circleci-bundle-update-pr 1.11.3 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +2 -2
- data/lib/circleci/bundle/update/pr.rb +82 -34
- data/lib/circleci/bundle/update/pr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e50dd78098b429691a6337242fdee4ab41974be18904d58b6f9a5eedbdf74e0
|
4
|
+
data.tar.gz: 36555ee2c44458ef2d456d2a5cf3c09b21e3b96908948aba0fa40819fb68f590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c01f59d3e28e132607892ca07d807478c01155032109a96689becdd18d17e758f09c884a0067fda08bc54a8a2cd8b3281cdbc30f84028dcd499f4139b762feba
|
7
|
+
data.tar.gz: d253a28b14648fc6d42165eb0c59bcea01d1370ee675efb36f1f225c1c5396340799abd89c83dcac3695d6fac057398aa31e7dec67e3aabc8b27e4c82cebc2ef
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
circleci-bundle-update-pr (1.
|
4
|
+
circleci-bundle-update-pr (1.12.0)
|
5
5
|
compare_linker (>= 1.4.0)
|
6
6
|
octokit
|
7
7
|
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
httpclient
|
15
15
|
octokit
|
16
16
|
diff-lcs (1.3)
|
17
|
-
faraday (0.15.
|
17
|
+
faraday (0.15.3)
|
18
18
|
multipart-post (>= 1.2, < 3)
|
19
19
|
httpclient (2.8.3)
|
20
20
|
multipart-post (2.0.0)
|
@@ -51,4 +51,4 @@ DEPENDENCIES
|
|
51
51
|
rspec (~> 3.7)
|
52
52
|
|
53
53
|
BUNDLED WITH
|
54
|
-
1.16.
|
54
|
+
1.16.5
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Circleci::Bundle::Update::Pr
|
2
2
|
|
3
|
-
[![Build Status](https://img.shields.io/circleci/project/masutaka/circleci-bundle-update-pr/master.svg?style=flat-square)][circleci]
|
3
|
+
[![Build Status](https://img.shields.io/circleci/project/github/masutaka/circleci-bundle-update-pr/master.svg?logo=circieci&style=flat-square)][circleci]
|
4
4
|
[![License](https://img.shields.io/github/license/masutaka/circleci-bundle-update-pr.svg?style=flat-square)][license]
|
5
|
-
[![Gem](https://img.shields.io/gem/v/circleci-bundle-update-pr.svg?style=flat-square)][gem-link]
|
5
|
+
[![Gem](https://img.shields.io/gem/v/circleci-bundle-update-pr.svg?logo=ruby&style=flat-square)][gem-link]
|
6
6
|
|
7
7
|
[circleci]: https://circleci.com/gh/masutaka/circleci-bundle-update-pr
|
8
8
|
[license]: https://github.com/masutaka/circleci-bundle-update-pr/blob/master/LICENSE.txt
|
@@ -9,32 +9,72 @@ module Circleci
|
|
9
9
|
def self.create_if_needed(git_username: nil, git_email: nil, git_branches: ["master"],
|
10
10
|
assignees: nil, reviewers: nil, labels: nil)
|
11
11
|
raise_if_env_unvalid!
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
|
13
|
+
if skip?
|
14
|
+
puts 'Skip because it has already existed.'
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
unless need_to_commit?(git_branches)
|
19
|
+
puts 'No changes due to bundle update'
|
20
|
+
return
|
21
|
+
end
|
16
22
|
|
17
23
|
git_username ||= client.user.login
|
18
24
|
git_email ||= "#{git_username}@users.noreply.#{github_host}"
|
19
25
|
|
20
|
-
create_branch(git_username, git_email
|
21
|
-
pull_request = create_pull_request(
|
22
|
-
add_labels(
|
23
|
-
update_pull_request_body(
|
24
|
-
add_assignees(
|
25
|
-
request_review(
|
26
|
+
branch = create_branch(git_username, git_email)
|
27
|
+
pull_request = create_pull_request(branch)
|
28
|
+
add_labels(pull_request[:number], labels) if labels
|
29
|
+
update_pull_request_body(pull_request[:number])
|
30
|
+
add_assignees(pull_request[:number], assignees) if assignees
|
31
|
+
request_review(pull_request[:number], reviewers) if reviewers
|
26
32
|
end
|
27
33
|
|
28
|
-
|
34
|
+
BRANCH_PREFIX = 'bundle-update-'.freeze
|
35
|
+
TITLE_PREFIX = 'bundle update at '.freeze
|
36
|
+
|
37
|
+
def self.raise_if_env_unvalid!
|
38
|
+
raise "$CIRCLE_PROJECT_USERNAME isn't set" unless ENV['CIRCLE_PROJECT_USERNAME']
|
39
|
+
raise "$CIRCLE_PROJECT_REPONAME isn't set" unless ENV['CIRCLE_PROJECT_REPONAME']
|
40
|
+
raise "$GITHUB_ACCESS_TOKEN isn't set" unless ENV['GITHUB_ACCESS_TOKEN']
|
41
|
+
if ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'] && !ENV['ENTERPRISE_OCTOKIT_API_ENDPOINT']
|
42
|
+
raise "$ENTERPRISE_OCTOKIT_API_ENDPOINT isn't set"
|
43
|
+
end
|
44
|
+
if !ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'] && ENV['ENTERPRISE_OCTOKIT_API_ENDPOINT']
|
45
|
+
raise "$ENTERPRISE_OCTOKIT_ACCESS_TOKEN isn't set"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
private_class_method :raise_if_env_unvalid!
|
49
|
+
|
50
|
+
# Has 'bundle update PR' already existed?
|
51
|
+
#
|
52
|
+
# @return [Boolean]
|
53
|
+
def self.skip?
|
54
|
+
client.pull_requests(repo_full_name).find do |pr|
|
55
|
+
pr.title =~ /\A#{TITLE_PREFIX}/ && pr.head.ref =~ /\A#{BRANCH_PREFIX}\d+/
|
56
|
+
end != nil
|
57
|
+
end
|
58
|
+
private_class_method :skip?
|
59
|
+
|
60
|
+
# Does it need to commit due to bundle update?
|
61
|
+
#
|
62
|
+
# @param git_branches [Array<String>]
|
63
|
+
# @return [Boolean]
|
64
|
+
def self.need_to_commit?(git_branches)
|
29
65
|
return false unless git_branches.include?(ENV['CIRCLE_BRANCH'])
|
30
66
|
unless system("bundle update && bundle update --ruby")
|
31
67
|
raise "Unable to execute `bundle update && bundle update --ruby`"
|
32
68
|
end
|
33
69
|
`git status -sb 2> /dev/null`.include?("Gemfile.lock")
|
34
70
|
end
|
35
|
-
private_class_method :
|
71
|
+
private_class_method :need_to_commit?
|
36
72
|
|
37
|
-
|
73
|
+
# Create remote branch for bundle update PR
|
74
|
+
#
|
75
|
+
# @return [String] remote branch name. e.g. bundle-update-20180929154455
|
76
|
+
def self.create_branch(git_username, git_email)
|
77
|
+
branch = "#{BRANCH_PREFIX}#{now.strftime('%Y%m%d%H%M%S')}"
|
38
78
|
remote = "https://#{github_access_token}@#{github_host}/#{repo_full_name}"
|
39
79
|
system("git remote add github-url-with-token #{remote}")
|
40
80
|
system("git config user.name #{git_username}")
|
@@ -43,16 +83,26 @@ module Circleci
|
|
43
83
|
system("git commit -m '$ bundle update && bundle update --ruby'")
|
44
84
|
system("git branch -M #{branch}")
|
45
85
|
system("git push -q github-url-with-token #{branch}")
|
86
|
+
branch
|
46
87
|
end
|
47
88
|
private_class_method :create_branch
|
48
89
|
|
49
|
-
|
50
|
-
|
90
|
+
# Create bundle update PR
|
91
|
+
#
|
92
|
+
# @param branch [String] branch name
|
93
|
+
# @return [Sawyer::Resource] The newly created pull request
|
94
|
+
def self.create_pull_request(branch)
|
95
|
+
title = "#{TITLE_PREFIX}#{now.strftime('%Y-%m-%d %H:%M:%S %Z')}"
|
51
96
|
client.create_pull_request(repo_full_name, ENV['CIRCLE_BRANCH'], branch, title)
|
52
97
|
end
|
53
98
|
private_class_method :create_pull_request
|
54
99
|
|
55
|
-
def self.
|
100
|
+
def self.add_labels(pr_number, labels)
|
101
|
+
client.add_labels_to_an_issue(repo_full_name, pr_number, labels)
|
102
|
+
end
|
103
|
+
private_class_method :add_labels
|
104
|
+
|
105
|
+
def self.update_pull_request_body(pr_number)
|
56
106
|
ENV["OCTOKIT_ACCESS_TOKEN"] = ENV["GITHUB_ACCESS_TOKEN"]
|
57
107
|
compare_linker = CompareLinker.new(repo_full_name, pr_number)
|
58
108
|
compare_linker.formatter = CompareLinker::Formatter::Markdown.new
|
@@ -69,21 +119,16 @@ Powered by [circleci-bundle-update-pr](https://rubygems.org/gems/circleci-bundle
|
|
69
119
|
end
|
70
120
|
private_class_method :update_pull_request_body
|
71
121
|
|
72
|
-
def self.add_assignees(
|
122
|
+
def self.add_assignees(pr_number, assignees)
|
73
123
|
client.add_assignees(repo_full_name, pr_number, assignees)
|
74
124
|
end
|
75
125
|
private_class_method :add_assignees
|
76
126
|
|
77
|
-
def self.request_review(
|
127
|
+
def self.request_review(pr_number, reviewers)
|
78
128
|
client.request_pull_request_review(repo_full_name, pr_number, reviewers)
|
79
129
|
end
|
80
130
|
private_class_method :request_review
|
81
131
|
|
82
|
-
def self.add_labels(repo_full_name, pr_number, labels)
|
83
|
-
client.add_labels_to_an_issue(repo_full_name, pr_number, labels)
|
84
|
-
end
|
85
|
-
private_class_method :add_labels
|
86
|
-
|
87
132
|
def self.client
|
88
133
|
if enterprise?
|
89
134
|
Octokit::Client.new(access_token: ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'],
|
@@ -104,6 +149,14 @@ Powered by [circleci-bundle-update-pr](https://rubygems.org/gems/circleci-bundle
|
|
104
149
|
end
|
105
150
|
private_class_method :github_access_token
|
106
151
|
|
152
|
+
# Get repository full name
|
153
|
+
#
|
154
|
+
# @return [String] e.g. 'masutaka/circleci-bundle-update-pr'
|
155
|
+
def self.repo_full_name
|
156
|
+
@repo_full_name ||= "#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}"
|
157
|
+
end
|
158
|
+
private_class_method :repo_full_name
|
159
|
+
|
107
160
|
def self.github_host
|
108
161
|
# A format like https://github.com/masutaka/circleci-bundle-update-pr.git
|
109
162
|
return $1 if ENV['CIRCLE_REPOSITORY_URL'] =~ %r{https://(.+?)/}
|
@@ -113,18 +166,13 @@ Powered by [circleci-bundle-update-pr](https://rubygems.org/gems/circleci-bundle
|
|
113
166
|
end
|
114
167
|
private_class_method :github_host
|
115
168
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
raise "$ENTERPRISE_OCTOKIT_API_ENDPOINT isn't set"
|
122
|
-
end
|
123
|
-
if !ENV['ENTERPRISE_OCTOKIT_ACCESS_TOKEN'] && ENV['ENTERPRISE_OCTOKIT_API_ENDPOINT']
|
124
|
-
raise "$ENTERPRISE_OCTOKIT_ACCESS_TOKEN isn't set"
|
125
|
-
end
|
169
|
+
# Get unified current time
|
170
|
+
#
|
171
|
+
# @return [Time]
|
172
|
+
def self.now
|
173
|
+
@now ||= Time.now
|
126
174
|
end
|
127
|
-
private_class_method :
|
175
|
+
private_class_method :now
|
128
176
|
end
|
129
177
|
end
|
130
178
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circleci-bundle-update-pr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Masuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|