Class: GithubIssuesCli::Command::Pull_request

Inherits:
GithubIssuesCli::Command show all
Defined in:
lib/github_issues_cli/command/pull_request.rb

Instance Attribute Summary

Attributes inherited from GithubIssuesCli::Command

#git_repo, #username

Instance Method Summary collapse

Methods inherited from GithubIssuesCli::Command

#authenticate, #get_git_repo, #get_github_repo, #get_issue_number, #get_source, #initialize, #run

Constructor Details

This class inherits a constructor from GithubIssuesCli::Command

Instance Method Details

#executeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/github_issues_cli/command/pull_request.rb', line 4

def execute
  github_repo = get_github_repo
  issue_number = get_issue_number
  source = @username + ':issue-' + issue_number
  begin
    request = {
        :user => github_repo[:user],
        :repo => github_repo[:name],
        :head => source,
        :base => 'master',
        :issue => issue_number
    }
    Github::PullRequests.new.create request
  rescue Exception => e
    unless get_source(issue_number).nil?
      raise 'Pull-request for issue #' + issue_number + ' already exists'
    end
    raise "Internal error: Cannot create pull-request.\n#{e.inspect}"
  end
  print 'Pull request for issue '
  print bold '#' + issue_number
  puts ' created'
end