Class: ModuleSync::PR::GitHub
- Inherits:
-
Object
- Object
- ModuleSync::PR::GitHub
- Defined in:
- lib/modulesync/pr/github.rb
Overview
GitHub creates and manages pull requests on github.com or GitHub Enterprise installations.
Instance Method Summary collapse
-
#initialize(token, endpoint) ⇒ GitHub
constructor
A new instance of GitHub.
- #manage(namespace, module_name, options) ⇒ Object
Constructor Details
#initialize(token, endpoint) ⇒ GitHub
Returns a new instance of GitHub.
9 10 11 12 13 14 |
# File 'lib/modulesync/pr/github.rb', line 9 def initialize(token, endpoint) Octokit.configure do |c| c.api_endpoint = endpoint end @api = Octokit::Client.new(:access_token => token) end |
Instance Method Details
#manage(namespace, module_name, options) ⇒ Object
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 51 52 53 54 |
# File 'lib/modulesync/pr/github.rb', line 16 def manage(namespace, module_name, ) repo_path = File.join(namespace, module_name) branch = [:remote_branch] || [:branch] head = "#{namespace}:#{branch}" target_branch = [:pr_target_branch] || 'master' if [:noop] $stdout.puts \ "Using no-op. Would submit PR '#{[:pr_title]}' to #{repo_path} " \ "- merges #{branch} into #{target_branch}" return end pull_requests = @api.pull_requests(repo_path, :state => 'open', :base => target_branch, :head => head) unless pull_requests.empty? # Skip creating the PR if it exists already. $stdout.puts "Skipped! #{pull_requests.length} PRs found for branch #{branch}" return end pr_labels = ModuleSync::Util.parse_list([:pr_labels]) pr = @api.create_pull_request(repo_path, target_branch, branch, [:pr_title], [:message]) $stdout.puts \ "Submitted PR '#{[:pr_title]}' to #{repo_path} " \ "- merges #{branch} into #{target_branch}" # We only assign labels to the PR if we've discovered a list > 1. The labels MUST # already exist. We DO NOT create missing labels. return if pr_labels.empty? $stdout.puts "Attaching the following labels to PR #{pr['number']}: #{pr_labels.join(', ')}" @api.add_labels_to_an_issue(repo_path, pr['number'], pr_labels) end |