gitlabci-bundle-update-mr 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a065986105c7fbd7f50eb145776cb26e84fc40d4e6880008f5be67f2200cdc57
4
- data.tar.gz: 652216fddd681c1d47098a4067a362fecda7238024967d56d4eae6abb3696621
3
+ metadata.gz: 328b0a88d5bbc5b521b604ee4d223ebe299b0b3eeb130680c18683ff8150bfc4
4
+ data.tar.gz: fff81a3041e33440121420c3adbace6229105eddce5ce3514e726313af5a8d1a
5
5
  SHA512:
6
- metadata.gz: c976b5cfa5ef0b0c45ebb585dd184f2ad783c67ae5a4635fba35071197c3e6e2459807a75fb7eeac2dfc2e15704419793684dfeba14c28bcd58a69fe60e618c3
7
- data.tar.gz: 8a105f20e246ce52d15779c0a5c69534c451a4c22387c65c554b058f1386f32bda2a0bf29ecd146838c8027fb0392e71d3070376075bc68a7b008a718969ca22
6
+ metadata.gz: e1b567cbe53d70bb6677221d500d07a417db35dfbbfc8c2061056926b1e6a2840f203cfab1ed8983c48591d74a28efbe08411bbebb122e27d08f7a2535c18ef0
7
+ data.tar.gz: 3bba3ccee80b94393b1294a0238b4bf0a21e8463a8b1e42ef99e4a5b4d8ed3574b50a70219efc8114d5dab82ced6abfaf9b9335f23b268f9cbca99e1baa0f5bc
@@ -13,6 +13,7 @@ continuous_bundle_update:
13
13
  GIT_EMAIL: "gitlabci@example.com"
14
14
  GIT_USER: "GitLab CI"
15
15
  OPTIONS: "--merge-when-pipeline-succeeds"
16
+ ASSIGNEES: "sue445"
16
17
 
17
18
  before_script:
18
19
  # Set timezone to Asia/Tokyo
@@ -10,6 +10,7 @@ inherit_gem:
10
10
 
11
11
  AllCops:
12
12
  TargetRubyVersion: 2.5
13
+ NewCops: enable
13
14
 
14
15
  Layout/HashAlignment:
15
16
  EnforcedHashRocketStyle: table
@@ -25,4 +26,4 @@ Layout/FirstHashElementIndentation:
25
26
  EnforcedStyle: consistent
26
27
 
27
28
  Metrics/MethodLength:
28
- Max: 21
29
+ Max: 22
@@ -1,5 +1,10 @@
1
1
  ## Unreleased
2
- [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v1.0.0...master)
2
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v1.1.0...master)
3
+
4
+ ## v1.1.0
5
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v1.0.0...v1.1.0)
6
+
7
+ * Support assignee [!113](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/113) *@sue445*
3
8
 
4
9
  ## v1.0.0
5
10
  [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.3.0...v1.0.0)
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- gitlabci-bundle-update-mr (1.0.0)
13
+ gitlabci-bundle-update-mr (1.1.0)
14
14
  bundler
15
15
  compare_linker (>= 1.4.3)
16
16
  gitlab (>= 4.14.1)
@@ -21,22 +21,21 @@ GEM
21
21
  specs:
22
22
  addressable (2.7.0)
23
23
  public_suffix (>= 2.0.2, < 5.0)
24
- ast (2.4.0)
25
- byebug (10.0.2)
26
- coderay (1.1.2)
27
- compare_linker (1.4.3)
24
+ ast (2.4.1)
25
+ byebug (11.1.3)
26
+ coderay (1.1.3)
27
+ compare_linker (1.4.4)
28
28
  httpclient
29
29
  octokit
30
- crack (0.4.3)
31
- safe_yaml (~> 1.0.0)
32
- diff-lcs (1.3)
30
+ crack (0.4.4)
31
+ diff-lcs (1.4.4)
33
32
  docile (1.3.2)
34
- dotenv (2.7.5)
35
- faraday (1.0.0)
33
+ dotenv (2.7.6)
34
+ faraday (1.0.1)
36
35
  multipart-post (>= 1.2, < 3)
37
- git (1.6.0)
36
+ git (1.7.0)
38
37
  rchardet (~> 1.8)
39
- gitlab (4.14.1)
38
+ gitlab (4.16.1)
40
39
  httparty (~> 0.14, >= 0.14.0)
41
40
  terminal-table (~> 1.5, >= 1.5.1)
42
41
  gitlab_awesome_release (1.0.2)
@@ -44,34 +43,33 @@ GEM
44
43
  gitlab (>= 4.0.0)
45
44
  thor
46
45
  hashdiff (1.0.1)
47
- httparty (0.18.0)
46
+ httparty (0.18.1)
48
47
  mime-types (~> 3.0)
49
48
  multi_xml (>= 0.5.2)
50
49
  httpclient (2.8.3)
51
- jaro_winkler (1.5.4)
52
- json (2.3.0)
53
- method_source (0.9.2)
50
+ method_source (1.0.0)
54
51
  mime-types (3.3.1)
55
52
  mime-types-data (~> 3.2015)
56
- mime-types-data (3.2019.1009)
53
+ mime-types-data (3.2020.0512)
57
54
  multi_xml (0.6.0)
58
55
  multipart-post (2.1.1)
59
- octokit (4.16.0)
56
+ octokit (4.18.0)
60
57
  faraday (>= 0.9)
61
58
  sawyer (~> 0.8.0, >= 0.5.3)
62
- parallel (1.19.1)
63
- parser (2.7.0.4)
64
- ast (~> 2.4.0)
65
- pry (0.12.2)
66
- coderay (~> 1.1.0)
67
- method_source (~> 0.9.0)
68
- pry-byebug (3.6.0)
69
- byebug (~> 10.0)
70
- pry (~> 0.10)
71
- public_suffix (4.0.3)
59
+ parallel (1.19.2)
60
+ parser (2.7.1.5)
61
+ ast (~> 2.4.1)
62
+ pry (0.13.1)
63
+ coderay (~> 1.1)
64
+ method_source (~> 1.0)
65
+ pry-byebug (3.9.0)
66
+ byebug (~> 11.0)
67
+ pry (~> 0.13.0)
68
+ public_suffix (4.0.6)
72
69
  rainbow (3.0.0)
73
70
  rake (13.0.1)
74
71
  rchardet (1.8.0)
72
+ regexp_parser (1.8.0)
75
73
  restore_bundled_with (1.0.0)
76
74
  git
77
75
  thor
@@ -80,50 +78,55 @@ GEM
80
78
  rspec-core (~> 3.9.0)
81
79
  rspec-expectations (~> 3.9.0)
82
80
  rspec-mocks (~> 3.9.0)
83
- rspec-core (3.9.1)
84
- rspec-support (~> 3.9.1)
85
- rspec-expectations (3.9.0)
81
+ rspec-core (3.9.2)
82
+ rspec-support (~> 3.9.3)
83
+ rspec-expectations (3.9.2)
86
84
  diff-lcs (>= 1.2.0, < 2.0)
87
85
  rspec-support (~> 3.9.0)
86
+ rspec-its (1.3.0)
87
+ rspec-core (>= 3.0.0)
88
+ rspec-expectations (>= 3.0.0)
88
89
  rspec-mocks (3.9.1)
89
90
  diff-lcs (>= 1.2.0, < 2.0)
90
91
  rspec-support (~> 3.9.0)
91
- rspec-support (3.9.2)
92
+ rspec-support (3.9.3)
92
93
  rspec-temp_dir (1.1.0)
93
94
  rspec (>= 3.0)
94
- rubocop (0.80.1)
95
- jaro_winkler (~> 1.5.1)
95
+ rubocop (0.92.0)
96
96
  parallel (~> 1.10)
97
- parser (>= 2.7.0.1)
97
+ parser (>= 2.7.1.5)
98
98
  rainbow (>= 2.2.2, < 4.0)
99
+ regexp_parser (>= 1.7)
99
100
  rexml
101
+ rubocop-ast (>= 0.5.0)
100
102
  ruby-progressbar (~> 1.7)
101
- unicode-display_width (>= 1.4.0, < 1.7)
102
- rubocop-performance (1.5.2)
103
- rubocop (>= 0.71.0)
104
- rubocop-rspec (1.38.1)
105
- rubocop (>= 0.68.1)
106
- rubocop_auto_corrector (0.3.0)
107
- rubocop (>= 0.72.0)
103
+ unicode-display_width (>= 1.4.0, < 2.0)
104
+ rubocop-ast (0.6.0)
105
+ parser (>= 2.7.1.5)
106
+ rubocop-performance (1.8.1)
107
+ rubocop (>= 0.87.0)
108
+ rubocop-ast (>= 0.4.0)
109
+ rubocop-rspec (1.43.2)
110
+ rubocop (~> 0.87)
111
+ rubocop_auto_corrector (0.4.1)
112
+ rubocop (>= 0.87.0)
108
113
  ruby-progressbar (1.10.1)
109
- safe_yaml (1.0.5)
110
114
  sawyer (0.8.2)
111
115
  addressable (>= 2.3.5)
112
116
  faraday (> 0.8, < 2.0)
113
- simplecov (0.17.1)
117
+ simplecov (0.19.0)
114
118
  docile (~> 1.1)
115
- json (>= 1.8, < 3)
116
- simplecov-html (~> 0.10.0)
117
- simplecov-html (0.10.2)
119
+ simplecov-html (~> 0.11)
120
+ simplecov-html (0.12.3)
118
121
  terminal-table (1.8.0)
119
122
  unicode-display_width (~> 1.1, >= 1.1.1)
120
123
  thor (1.0.1)
121
- unicode-display_width (1.6.1)
122
- webmock (3.8.2)
124
+ unicode-display_width (1.7.0)
125
+ webmock (3.9.1)
123
126
  addressable (>= 2.3.6)
124
127
  crack (>= 0.3.2)
125
128
  hashdiff (>= 0.4.0, < 2.0.0)
126
- yard (0.9.24)
129
+ yard (0.9.25)
127
130
 
128
131
  PLATFORMS
129
132
  ruby
@@ -138,6 +141,7 @@ DEPENDENCIES
138
141
  pry-byebug
139
142
  rake (>= 10.0)
140
143
  rspec (~> 3.0)
144
+ rspec-its
141
145
  rspec-temp_dir
142
146
  rubocop (>= 0.68.0)
143
147
  rubocop-performance
@@ -146,3 +150,6 @@ DEPENDENCIES
146
150
  simplecov
147
151
  webmock
148
152
  yard
153
+
154
+ BUNDLED WITH
155
+ 2.1.2
data/README.md CHANGED
@@ -101,6 +101,7 @@ continuous_bundle_update:
101
101
  GIT_EMAIL: "gitlabci@example.com"
102
102
  GIT_USER: "GitLab CI"
103
103
  LABELS: "bundle update"
104
+ ASSIGNEES: "foo, bar, baz"
104
105
  OPTIONS: ""
105
106
 
106
107
  before_script:
@@ -124,6 +125,32 @@ Usage: gitlabci-bundle-update-mr [options]
124
125
  --update-bundled-with Whether to update `BUNDLED WITH` section in Gemfie.lock (default. false)
125
126
  --merge-when-pipeline-succeeds
126
127
  Whether to set 'Merge when pipeline succeeds' (default. false)
128
+ --assignees 'foo, bar' Add assignees to the MR
129
+ ```
130
+
131
+ ## ProTip
132
+ ### Randomly assign 1 person to MergeRequest
133
+ ```yml
134
+ include:
135
+ - remote: "https://gitlab.com/sue445/gitlabci-bundle-update-mr/raw/master/gitlabci-templates/continuous_bundle_update.yml"
136
+
137
+ continuous_bundle_update:
138
+ stage: build
139
+
140
+ before_script:
141
+ - ASSIGNEES=$(ruby -e 'print %w[foo bar baz].sample')
142
+ ```
143
+
144
+ ### Assign one person to MR on a weekly basis
145
+ ```yml
146
+ include:
147
+ - remote: "https://gitlab.com/sue445/gitlabci-bundle-update-mr/raw/master/gitlabci-templates/continuous_bundle_update.yml"
148
+
149
+ continuous_bundle_update:
150
+ stage: build
151
+
152
+ before_script:
153
+ - ASSIGNEES=$(ruby -rtime -e 'a=%w[foo bar baz]; print a[Time.now.to_date.cweek% a.size]')
127
154
  ```
128
155
 
129
156
  ## Development
@@ -11,6 +11,7 @@ allow_dup_mr = false
11
11
  mr_labels = []
12
12
  update_bundled_with = false
13
13
  merge_when_pipeline_succeeds = false
14
+ assignees = []
14
15
 
15
16
  opt.on("--email EMAIL", "git email address (default. `git config user.email`)") {|v| author_email = v }
16
17
  opt.on("--user USER", "git username (default. `git config user.name`)") {|v| author_name = v }
@@ -18,6 +19,7 @@ opt.on("-d", "--duplicate", "Make MR even if it has already existed (default. fa
18
19
  opt.on("-l", "--labels 'In Review, Update'", Array, "Add labels to the MR") {|v| mr_labels = v.map(&:strip) }
19
20
  opt.on("--update-bundled-with", "Whether to update `BUNDLED WITH` section in Gemfie.lock (default. false)") {|v| update_bundled_with = v }
20
21
  opt.on("--merge-when-pipeline-succeeds", "Whether to set 'Merge when pipeline succeeds' (default. false)") {|v| merge_when_pipeline_succeeds = v }
22
+ opt.on("--assignees 'foo, bar'", Array, "Add assignees to the MR") {|v| assignees = v.map(&:strip) }
21
23
 
22
24
  opt.parse!(ARGV)
23
25
 
@@ -37,4 +39,5 @@ client.perform(
37
39
  mr_labels: mr_labels,
38
40
  update_bundled_with: update_bundled_with,
39
41
  merge_when_pipeline_succeeds: merge_when_pipeline_succeeds,
42
+ assignees: assignees,
40
43
  )
@@ -47,9 +47,10 @@ Gem::Specification.new do |spec|
47
47
  spec.add_development_dependency "pry-byebug"
48
48
  spec.add_development_dependency "rake", ">= 10.0"
49
49
  spec.add_development_dependency "rspec", "~> 3.0"
50
+ spec.add_development_dependency "rspec-its"
50
51
  spec.add_development_dependency "rspec-temp_dir"
51
- spec.add_development_dependency "rubocop-performance"
52
52
  spec.add_development_dependency "rubocop_auto_corrector"
53
+ spec.add_development_dependency "rubocop-performance"
53
54
  spec.add_development_dependency "simplecov"
54
55
  spec.add_development_dependency "webmock"
55
56
  spec.add_development_dependency "yard"
@@ -6,6 +6,7 @@ continuous_bundle_update:
6
6
  GIT_EMAIL: "gitlabci@example.com"
7
7
  GIT_USER: "GitLab CI"
8
8
  LABELS: "bundle update"
9
+ ASSIGNEES: ""
9
10
  OPTIONS: ""
10
11
 
11
12
  cache:
@@ -16,6 +17,10 @@ continuous_bundle_update:
16
17
  script:
17
18
  - bundle install --path vendor/bundle --clean
18
19
  - gem install --no-doc gitlabci-bundle-update-mr
20
+ - |
21
+ if [ -n "$ASSIGNEES" ]; then
22
+ OPTIONS="--assignees $ASSIGNEES $OPTIONS"
23
+ fi
19
24
  - gitlabci-bundle-update-mr --user="$GIT_USER" --email="$GIT_EMAIL" --labels="$LABELS" $OPTIONS
20
25
 
21
26
  only:
@@ -14,6 +14,8 @@ module Gitlabci
14
14
 
15
15
  class MissingKeyError < Error; end
16
16
 
17
+ class NotFoundUserError < Error; end
18
+
17
19
  def self.assert_env_keys
18
20
  %w[
19
21
  OCTOKIT_ACCESS_TOKEN
@@ -28,12 +28,14 @@ module Gitlabci
28
28
  # @param mr_labels [Array<String>]
29
29
  # @param update_bundled_with [Boolean]
30
30
  # @param merge_when_pipeline_succeeds [Boolean]
31
- def perform(allow_dup_mr:, mr_labels:, update_bundled_with:, merge_when_pipeline_succeeds:)
31
+ # @param assignees [Array<String>]
32
+ def perform(allow_dup_mr:, mr_labels:, update_bundled_with:, merge_when_pipeline_succeeds:, assignees:)
32
33
  if !allow_dup_mr && exists_bundle_update_mr?
33
34
  puts "Skip because it has already existed."
34
35
  return
35
36
  end
36
37
 
38
+ assignee_ids = get_assignee_ids(assignees)
37
39
  old_lockfile = File.read(lockfile_name)
38
40
 
39
41
  system!("bundle update")
@@ -51,7 +53,7 @@ module Gitlabci
51
53
  commit_gemfile_lock(new_lockfile)
52
54
  description = merge_request_description(old_lockfile, new_lockfile)
53
55
 
54
- mr = create_merge_request(description: description, mr_labels: mr_labels)
56
+ mr = create_merge_request(description: description, mr_labels: mr_labels, assignee_ids: assignee_ids)
55
57
  puts "MR is created: #{mr.web_url}"
56
58
 
57
59
  if merge_when_pipeline_succeeds
@@ -81,7 +83,10 @@ module Gitlabci
81
83
 
82
84
  # @param description [String]
83
85
  # @param mr_labels [Array<String>]
84
- def create_merge_request(description:, mr_labels:)
86
+ # @param assignee_ids [Array<Integer>]
87
+ #
88
+ # @see https://docs.gitlab.com/ee/api/merge_requests.html#create-mr
89
+ def create_merge_request(description:, mr_labels:, assignee_ids:)
85
90
  params = {
86
91
  source_branch: new_branch,
87
92
  target_branch: @branch,
@@ -93,6 +98,12 @@ module Gitlabci
93
98
  params[:labels] = mr_labels.join(",")
94
99
  end
95
100
 
101
+ if assignee_ids.length == 1
102
+ params[:assignee_id] = assignee_ids[0]
103
+ elsif assignee_ids.length >= 2
104
+ params[:assignee_ids] = assignee_ids
105
+ end
106
+
96
107
  @gitlab.create_merge_request(
97
108
  @project_name,
98
109
  "#{TITLE_PREFIX}#{current_time.strftime("%Y-%m-%d %H:%M:%S %Z")}",
@@ -120,6 +131,33 @@ module Gitlabci
120
131
  MARKDOWN
121
132
  end
122
133
 
134
+ # @param username [String]
135
+ #
136
+ # @return [Gitlab::ObjectifiedHash]
137
+ # @return [nil] User isn't found
138
+ #
139
+ # @see https://docs.gitlab.com/ee/api/users.html#for-normal-users
140
+ def find_by_username(username)
141
+ @gitlab.users(username: username).first
142
+ end
143
+
144
+ # @param username [String]
145
+ #
146
+ # @return [Gitlab::ObjectifiedHash]
147
+ #
148
+ # @raise [Gitlabci::Bundle::Update::Mr::NotFoundUserError]
149
+ #
150
+ # @see https://docs.gitlab.com/ee/api/users.html#for-normal-users
151
+ def find_by_username!(username)
152
+ user = find_by_username(username)
153
+
154
+ unless user
155
+ raise NotFoundUserError, "#{username} isn't found"
156
+ end
157
+
158
+ user
159
+ end
160
+
123
161
  private
124
162
 
125
163
  def system!(command)
@@ -170,6 +208,13 @@ module Gitlabci
170
208
  def accept_merge_request(mr_id)
171
209
  @gitlab.accept_merge_request(@project_name, mr_id, merge_when_pipeline_succeeds: true, should_remove_source_branch: true)
172
210
  end
211
+
212
+ def get_assignee_ids(assignees)
213
+ assignees.map do |username|
214
+ user = find_by_username!(username)
215
+ user.id
216
+ end
217
+ end
173
218
  end
174
219
  end
175
220
  end
@@ -2,7 +2,7 @@ module Gitlabci
2
2
  module Bundle
3
3
  module Update
4
4
  module Mr
5
- VERSION = "1.0.0".freeze
5
+ VERSION = "1.1.0".freeze
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlabci-bundle-update-mr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-16 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '3.0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: rspec-temp_dir
154
+ name: rspec-its
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,7 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: rubocop-performance
168
+ name: rspec-temp_dir
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-performance
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: simplecov
197
211
  requirement: !ruby/object:Gem::Requirement