Module: GitHubPr::CLI

Defined in:
lib/github-pr/cli.rb

Class Method Summary collapse

Class Method Details

.current_branchObject



52
53
54
# File 'lib/github-pr/cli.rb', line 52

def self.current_branch
  `git branch | grep "^*"`.chomp[2..-1]
end

.parse(argv) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/github-pr/cli.rb', line 5

def self.parse(argv)
options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: github-pr -b master -f shop-redesign -a hovox"
  opts.separator ""
  opts.separator "Your current directory must be your git directory"
  opts.separator "github-pr -b master -a hovox"
  opts.separator "Will use current branch as feature branch"
  opts.separator ""
  opts.separator "github-pr -a hovox"
  opts.separator "Will use master branch as base branch and current branch as feature branch"
  opts.separator ""
  opts.separator "Command should be run from project's directory"


  opts.on("-b", "--base BASE", "Base branch") do |b|
    options[:base] = b
  end
  opts.on("-f", "--feature FEATURE", "Feature branch") do |f|
    options[:feature] = f
  end
  opts.on("-a", "--assign USERNAME", "GitHub user name whom to assign") do |a|
    options[:assign] = a
  end
  opts.on("-t", "--title PULLREQUESTTITLE", "Title of the pull request") do |t|
    options[:title] = t
  end
  opts.on("-g", "--github-token GITHUBTOKEN", "Generated user token from GitHub") do |t|
    options[:token] = t
  end
  opts.on("-u", "--url GITHUBURL", "GitHub repo url, optional. We will try to get url from git.") do |t|
    options[:url] = t
  end
end.parse!(argv)

raise 'You must assign to someone' if options[:assign].nil?

options[:base] = 'master' if options[:base].nil?
  # e.g. * master cutting '* ' from begining
  options[:feature] = self.current_branch if options[:feature].nil?
  options[:title] = options[:feature] if options[:title].nil?
options[:token] = options[:token] if options[:token].nil?
options[:url] = options[:url] if options[:url].nil?

  return options
end