lib/circleci/bundle/update/pr.rb in circleci-bundle-update-pr-1.10.0 vs lib/circleci/bundle/update/pr.rb in circleci-bundle-update-pr-1.11.0
- old
+ new
@@ -4,11 +4,12 @@
module Circleci
module Bundle
module Update
module Pr
- def self.create_if_needed(git_username: nil, git_email: nil, git_branches: ["master"], assignees: [])
+ def self.create_if_needed(git_username: nil, git_email: nil, git_branches: ["master"],
+ assignees: nil, reviewers: nil, labels: nil)
raise_if_env_unvalid!
return unless need?(git_branches)
repo_full_name = "#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}"
now = Time.now
branch = "bundle-update-#{now.strftime('%Y%m%d%H%M%S')}"
@@ -16,12 +17,14 @@
git_username ||= client.user.login
git_email ||= "#{git_username}@users.noreply.#{github_host}"
create_branch(git_username, git_email, branch, repo_full_name)
pull_request = create_pull_request(repo_full_name, branch, now)
- add_comment_of_compare_linker(repo_full_name, pull_request[:number])
- add_assignees(repo_full_name, pull_request[:number], assignees) unless assignees.empty?
+ update_pull_request_body(repo_full_name, pull_request[:number])
+ add_assignees(repo_full_name, pull_request[:number], assignees) if assignees
+ request_review(repo_full_name, pull_request[:number], reviewers) if reviewers
+ add_labels(repo_full_name, pull_request[:number], labels) if labels
end
def self.need?(git_branches)
return false unless git_branches.include?(ENV['CIRCLE_BRANCH'])
unless system("bundle update && bundle update --ruby")
@@ -44,34 +47,44 @@
private_class_method :create_branch
def self.create_pull_request(repo_full_name, branch, now)
title = "bundle update at #{now.strftime('%Y-%m-%d %H:%M:%S %Z')}"
build_url = URI.parse ENV['CIRCLE_BUILD_URL']
- body = "auto generated by [CircleCI of #{ENV['CIRCLE_PROJECT_REPONAME']}](https://#{build_url.host}/gh/#{repo_full_name})"
- client.create_pull_request(repo_full_name, ENV['CIRCLE_BRANCH'], branch, title, body)
+ client.create_pull_request(repo_full_name, ENV['CIRCLE_BRANCH'], branch, title)
end
private_class_method :create_pull_request
- def self.add_comment_of_compare_linker(repo_full_name, pr_number)
+ def self.update_pull_request_body(repo_full_name, pr_number)
ENV["OCTOKIT_ACCESS_TOKEN"] = ENV["GITHUB_ACCESS_TOKEN"]
compare_linker = CompareLinker.new(repo_full_name, pr_number)
compare_linker.formatter = CompareLinker::Formatter::Markdown.new
- comment = <<-EOC
+ body = <<-EOB
**Updated RubyGems:**
#{compare_linker.make_compare_links.to_a.join("\n")}
-Powered by [compare_linker](https://rubygems.org/gems/compare_linker)
- EOC
- compare_linker.add_comment(repo_full_name, pr_number, comment)
+Powered by [circleci-bundle-update-pr](https://rubygems.org/gems/circleci-bundle-update-pr)
+ EOB
+
+ client.update_pull_request(repo_full_name, pr_number, body: body)
end
- private_class_method :add_comment_of_compare_linker
+ private_class_method :update_pull_request_body
def self.add_assignees(repo_full_name, pr_number, assignees)
client.add_assignees(repo_full_name, pr_number, assignees)
end
private_class_method :add_assignees
+
+ def self.request_review(repo_full_name, pr_number, reviewers)
+ client.request_pull_request_review(repo_full_name, pr_number, reviewers)
+ end
+ private_class_method :request_review
+
+ def self.add_labels(repo_full_name, pr_number, labels)
+ client.add_labels_to_an_issue(repo_full_name, pr_number, labels)
+ end
+ private_class_method :add_labels
def self.client
if enterprise?
Octokit::Client.new(access_token: ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'],
api_endpoint: ENV['ENTERPRISE_OCTOKIT_API_ENDPOINT'])