lib/circleci/bundle/update/pr.rb in circleci-bundle-update-pr-1.2.2 vs lib/circleci/bundle/update/pr.rb in circleci-bundle-update-pr-1.3.0
- old
+ new
@@ -4,25 +4,29 @@
module Circleci
module Bundle
module Update
module Pr
- def self.create_if_needed(git_username: nil, git_email: nil)
+ def self.create_if_needed(git_username: nil, git_email: nil, git_branches: ["master"])
raise "$CIRCLE_PROJECT_USERNAME isn't set" unless ENV['CIRCLE_PROJECT_USERNAME']
raise "$CIRCLE_PROJECT_REPONAME isn't set" unless ENV['CIRCLE_PROJECT_REPONAME']
raise "$GITHUB_ACCESS_TOKEN isn't set" unless ENV['GITHUB_ACCESS_TOKEN']
- return unless need?
+ 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')}"
+
+ git_username ||= client.user.login
+ git_email ||= "#{git_username}@users.noreply.github.com"
+
create_branch(git_username, git_email, branch)
pull_request = create_pull_request(repo_full_name, branch, now)
add_comment_of_compare_linker(repo_full_name, pull_request[:number])
end
- def self.need?
- return false unless ENV['CIRCLE_BRANCH'] == "master"
+ def self.need?(git_branches)
+ return false unless git_branches.include?(ENV['CIRCLE_BRANCH'])
system("bundle update")
`git status -sb 2> /dev/null`.include?("Gemfile.lock")
end
private_class_method :need?
@@ -37,12 +41,11 @@
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')}"
body = "auto generated by [CircleCI of #{ENV['CIRCLE_PROJECT_REPONAME']}](https://circleci.com/gh/#{repo_full_name})"
- client = Octokit::Client.new(access_token: ENV["GITHUB_ACCESS_TOKEN"])
- client.create_pull_request(repo_full_name, "master", branch, title, body)
+ client.create_pull_request(repo_full_name, ENV['CIRCLE_BRANCH'], branch, title, body)
end
private_class_method :create_pull_request
def self.add_comment_of_compare_linker(repo_full_name, pr_number)
ENV["OCTOKIT_ACCESS_TOKEN"] = ENV["GITHUB_ACCESS_TOKEN"]
@@ -56,9 +59,14 @@
EOC
compare_linker.add_comment(repo_full_name, pr_number, comment)
end
private_class_method :add_comment_of_compare_linker
+
+ def self.client
+ Octokit::Client.new(access_token: ENV["GITHUB_ACCESS_TOKEN"])
+ end
+ private_class_method :client
end
end
end
end