gitlabci-bundle-update-mr 1.0.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a065986105c7fbd7f50eb145776cb26e84fc40d4e6880008f5be67f2200cdc57
4
- data.tar.gz: 652216fddd681c1d47098a4067a362fecda7238024967d56d4eae6abb3696621
3
+ metadata.gz: b573b689c6bf38bb800c26ffcbe5e34815bc4ad8f6ae5c92ae5ba7d83ec930e2
4
+ data.tar.gz: ffba9360127be72feea30613f07ce99c8c3d55a2261ffe6acbfa55e2985db796
5
5
  SHA512:
6
- metadata.gz: c976b5cfa5ef0b0c45ebb585dd184f2ad783c67ae5a4635fba35071197c3e6e2459807a75fb7eeac2dfc2e15704419793684dfeba14c28bcd58a69fe60e618c3
7
- data.tar.gz: 8a105f20e246ce52d15779c0a5c69534c451a4c22387c65c554b058f1386f32bda2a0bf29ecd146838c8027fb0392e71d3070376075bc68a7b008a718969ca22
6
+ metadata.gz: 3242994d13cd7c4959d5399bee444e6d13d59ad54ae2d141c5952f669b0d53f3939c47f6e5fb9e943893e779022762494a16db40039a8c0c00f1da108479a464
7
+ data.tar.gz: e9083b867e926800dc01b450b92da8c77eaeb5eb22f75f1b86627e8c209b09c5f7c9e206cd8e79581ab59ec29454dc8565cfbc65b8102cada9a9d4a94c53360b
@@ -13,15 +13,12 @@ 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
19
20
  - cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
20
21
 
21
- only:
22
- - schedules
23
- - web # Test for topic branch
24
-
25
22
  .default:
26
23
  cache:
27
24
  key: "$CI_BUILD_NAME"
@@ -29,7 +26,8 @@ continuous_bundle_update:
29
26
  - vendor/bundle/
30
27
 
31
28
  before_script:
32
- - bundle install --path vendor/bundle
29
+ - bundle config --local path 'vendor/bundle'
30
+ - bundle install --retry=3 --jobs=$(nproc)
33
31
  - bundle clean
34
32
 
35
33
  except:
@@ -61,6 +59,11 @@ test:2.7:
61
59
 
62
60
  image: ruby:2.7
63
61
 
62
+ test:3.0:
63
+ extends: .test
64
+
65
+ image: ruby:3.0
66
+
64
67
  test:trunk:
65
68
  extends: .test
66
69
 
@@ -91,3 +94,20 @@ pages:
91
94
  - public
92
95
  only:
93
96
  - master
97
+
98
+ gitlab_awesome_release:
99
+ stage: build
100
+
101
+ image: ruby:alpine
102
+
103
+ script:
104
+ - gem install gitlab_awesome_release --no-doc
105
+ - gitlab_awesome_release create_latest_note
106
+
107
+ variables:
108
+ GITLAB_API_ENDPOINT: $CI_API_V4_URL
109
+ GITLAB_PROJECT_NAME: $CI_PROJECT_PATH
110
+ GITLAB_API_PRIVATE_TOKEN: $GITLAB_API_PRIVATE_TOKEN
111
+
112
+ only:
113
+ - web
@@ -10,19 +10,12 @@ inherit_gem:
10
10
 
11
11
  AllCops:
12
12
  TargetRubyVersion: 2.5
13
+ NewCops: enable
14
+ SuggestExtensions: false
13
15
 
14
16
  Layout/HashAlignment:
15
17
  EnforcedHashRocketStyle: table
16
18
  EnforcedColonStyle: table
17
19
 
18
- Layout/IndentationConsistency:
19
- EnforcedStyle: indented_internal_methods
20
-
21
- Layout/FirstArrayElementIndentation:
22
- EnforcedStyle: consistent
23
-
24
- Layout/FirstHashElementIndentation:
25
- EnforcedStyle: consistent
26
-
27
20
  Metrics/MethodLength:
28
- Max: 21
21
+ Max: 22
@@ -1,5 +1,21 @@
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.2...master)
3
+
4
+ ## v1.1.2
5
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v1.1.1...v1.1.2)
6
+
7
+ * Allow auto retry with `Gitlab::Error::NotAcceptable` [!134](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/134) *@sue445*
8
+
9
+ ## v1.1.1
10
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v1.1.0...v1.1.1)
11
+
12
+ * Add auto retry when `merge when pipeline succeeds` is failed [!128](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/128) *@sue445*
13
+ * [Resolved] `open': can't modify frozen Hash: {} (FrozenError) [!131](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/131) *@sue445*
14
+
15
+ ## v1.1.0
16
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v1.0.0...v1.1.0)
17
+
18
+ * Support assignee [!113](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/113) *@sue445*
3
19
 
4
20
  ## v1.0.0
5
21
  [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.3.0...v1.0.0)
data/Gemfile CHANGED
@@ -8,11 +8,3 @@ gemspec
8
8
  gem "faraday", ">= 0.15.4"
9
9
  gem "octokit", ">= 4.13.0"
10
10
  gem "sawyer", ">= 0.8.1"
11
-
12
- # TODO: Remove after following PR are merged
13
- # * https://github.com/onk/onkcop/pull/62
14
- # * https://github.com/onk/onkcop/pull/63
15
- # * https://github.com/onk/onkcop/pull/65
16
- # gem "onkcop", ">= 0.53.0.3", require: false
17
- gem "onkcop", require: false, github: "sue445/onkcop", branch: "develop"
18
- gem "rubocop", ">= 0.68.0"
@@ -1,18 +1,10 @@
1
- GIT
2
- remote: https://github.com/sue445/onkcop.git
3
- revision: 4f7e76b93efff0b7d4d7d9058a487d435479b129
4
- branch: develop
5
- specs:
6
- onkcop (0.53.0.3)
7
- rubocop (>= 0.53.0)
8
- rubocop-rspec (>= 1.24.0)
9
-
10
1
  PATH
11
2
  remote: .
12
3
  specs:
13
- gitlabci-bundle-update-mr (1.0.0)
4
+ gitlabci-bundle-update-mr (1.1.2)
14
5
  bundler
15
6
  compare_linker (>= 1.4.3)
7
+ git (= 1.7.0)
16
8
  gitlab (>= 4.14.1)
17
9
  restore_bundled_with
18
10
 
@@ -21,109 +13,123 @@ GEM
21
13
  specs:
22
14
  addressable (2.7.0)
23
15
  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)
16
+ ast (2.4.1)
17
+ byebug (11.1.3)
18
+ coderay (1.1.3)
19
+ compare_linker (1.4.4)
28
20
  httpclient
29
21
  octokit
30
- crack (0.4.3)
31
- safe_yaml (~> 1.0.0)
32
- diff-lcs (1.3)
33
- docile (1.3.2)
34
- dotenv (2.7.5)
35
- faraday (1.0.0)
22
+ crack (0.4.5)
23
+ rexml
24
+ diff-lcs (1.4.4)
25
+ docile (1.3.4)
26
+ dotenv (2.7.6)
27
+ faraday (1.3.0)
28
+ faraday-net_http (~> 1.0)
36
29
  multipart-post (>= 1.2, < 3)
37
- git (1.6.0)
30
+ ruby2_keywords
31
+ faraday-net_http (1.0.0)
32
+ git (1.7.0)
38
33
  rchardet (~> 1.8)
39
- gitlab (4.14.1)
40
- httparty (~> 0.14, >= 0.14.0)
34
+ gitlab (4.17.0)
35
+ httparty (~> 0.18)
41
36
  terminal-table (~> 1.5, >= 1.5.1)
42
37
  gitlab_awesome_release (1.0.2)
43
38
  dotenv
44
39
  gitlab (>= 4.0.0)
45
40
  thor
46
41
  hashdiff (1.0.1)
47
- httparty (0.18.0)
42
+ httparty (0.18.1)
48
43
  mime-types (~> 3.0)
49
44
  multi_xml (>= 0.5.2)
50
45
  httpclient (2.8.3)
51
- jaro_winkler (1.5.4)
52
- json (2.3.0)
53
- method_source (0.9.2)
46
+ method_source (1.0.0)
54
47
  mime-types (3.3.1)
55
48
  mime-types-data (~> 3.2015)
56
- mime-types-data (3.2019.1009)
49
+ mime-types-data (3.2020.1104)
57
50
  multi_xml (0.6.0)
58
51
  multipart-post (2.1.1)
59
- octokit (4.16.0)
52
+ octokit (4.20.0)
60
53
  faraday (>= 0.9)
61
54
  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)
55
+ onkcop (1.0.0.0)
56
+ rubocop (>= 0.80.0)
57
+ rubocop-rspec (>= 1.34.0)
58
+ parallel (1.20.1)
59
+ parser (3.0.0.0)
60
+ ast (~> 2.4.1)
61
+ pry (0.13.1)
62
+ coderay (~> 1.1)
63
+ method_source (~> 1.0)
64
+ pry-byebug (3.9.0)
65
+ byebug (~> 11.0)
66
+ pry (~> 0.13.0)
67
+ public_suffix (4.0.6)
72
68
  rainbow (3.0.0)
73
- rake (13.0.1)
69
+ rake (13.0.3)
74
70
  rchardet (1.8.0)
71
+ regexp_parser (2.0.3)
75
72
  restore_bundled_with (1.0.0)
76
73
  git
77
74
  thor
78
75
  rexml (3.2.4)
79
- rspec (3.9.0)
80
- rspec-core (~> 3.9.0)
81
- rspec-expectations (~> 3.9.0)
82
- rspec-mocks (~> 3.9.0)
83
- rspec-core (3.9.1)
84
- rspec-support (~> 3.9.1)
85
- rspec-expectations (3.9.0)
76
+ rspec (3.10.0)
77
+ rspec-core (~> 3.10.0)
78
+ rspec-expectations (~> 3.10.0)
79
+ rspec-mocks (~> 3.10.0)
80
+ rspec-core (3.10.1)
81
+ rspec-support (~> 3.10.0)
82
+ rspec-expectations (3.10.1)
86
83
  diff-lcs (>= 1.2.0, < 2.0)
87
- rspec-support (~> 3.9.0)
88
- rspec-mocks (3.9.1)
84
+ rspec-support (~> 3.10.0)
85
+ rspec-its (1.3.0)
86
+ rspec-core (>= 3.0.0)
87
+ rspec-expectations (>= 3.0.0)
88
+ rspec-mocks (3.10.1)
89
89
  diff-lcs (>= 1.2.0, < 2.0)
90
- rspec-support (~> 3.9.0)
91
- rspec-support (3.9.2)
90
+ rspec-support (~> 3.10.0)
91
+ rspec-support (3.10.1)
92
92
  rspec-temp_dir (1.1.0)
93
93
  rspec (>= 3.0)
94
- rubocop (0.80.1)
95
- jaro_winkler (~> 1.5.1)
94
+ rubocop (1.7.0)
96
95
  parallel (~> 1.10)
97
- parser (>= 2.7.0.1)
96
+ parser (>= 2.7.1.5)
98
97
  rainbow (>= 2.2.2, < 4.0)
98
+ regexp_parser (>= 1.8, < 3.0)
99
99
  rexml
100
+ rubocop-ast (>= 1.2.0, < 2.0)
100
101
  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)
108
- ruby-progressbar (1.10.1)
109
- safe_yaml (1.0.5)
102
+ unicode-display_width (>= 1.4.0, < 2.0)
103
+ rubocop-ast (1.4.0)
104
+ parser (>= 2.7.1.5)
105
+ rubocop-performance (1.9.2)
106
+ rubocop (>= 0.90.0, < 2.0)
107
+ rubocop-ast (>= 0.4.0)
108
+ rubocop-rspec (2.1.0)
109
+ rubocop (~> 1.0)
110
+ rubocop-ast (>= 1.1.0)
111
+ rubocop_auto_corrector (0.4.1)
112
+ rubocop (>= 0.87.0)
113
+ ruby-progressbar (1.11.0)
114
+ ruby2_keywords (0.0.2)
110
115
  sawyer (0.8.2)
111
116
  addressable (>= 2.3.5)
112
117
  faraday (> 0.8, < 2.0)
113
- simplecov (0.17.1)
118
+ simplecov (0.21.0)
114
119
  docile (~> 1.1)
115
- json (>= 1.8, < 3)
116
- simplecov-html (~> 0.10.0)
117
- simplecov-html (0.10.2)
120
+ simplecov-html (~> 0.11)
121
+ simplecov_json_formatter (~> 0.1)
122
+ simplecov-html (0.12.3)
123
+ simplecov_json_formatter (0.1.2)
118
124
  terminal-table (1.8.0)
119
125
  unicode-display_width (~> 1.1, >= 1.1.1)
120
126
  thor (1.0.1)
121
- unicode-display_width (1.6.1)
122
- webmock (3.8.2)
127
+ unicode-display_width (1.7.0)
128
+ webmock (3.11.0)
123
129
  addressable (>= 2.3.6)
124
130
  crack (>= 0.3.2)
125
131
  hashdiff (>= 0.4.0, < 2.0.0)
126
- yard (0.9.24)
132
+ yard (0.9.26)
127
133
 
128
134
  PLATFORMS
129
135
  ruby
@@ -134,12 +140,12 @@ DEPENDENCIES
134
140
  gitlab_awesome_release
135
141
  gitlabci-bundle-update-mr!
136
142
  octokit (>= 4.13.0)
137
- onkcop!
143
+ onkcop (>= 1.0.0.0)
138
144
  pry-byebug
139
145
  rake (>= 10.0)
140
146
  rspec (~> 3.0)
147
+ rspec-its
141
148
  rspec-temp_dir
142
- rubocop (>= 0.68.0)
143
149
  rubocop-performance
144
150
  rubocop_auto_corrector
145
151
  sawyer (>= 0.8.1)
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,8 +125,38 @@ 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
127
129
  ```
128
130
 
131
+ ## ProTip
132
+ ### Randomly assign one 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]')
154
+ ```
155
+
156
+ It will be assigned weekly in the following order.
157
+
158
+ `foo` -> `bar` -> `baz` -> `foo` -> `bar` -> `baz` -> ...
159
+
129
160
  ## Development
130
161
 
131
162
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -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
  )
@@ -38,18 +38,20 @@ Gem::Specification.new do |spec|
38
38
 
39
39
  spec.add_dependency "bundler"
40
40
  spec.add_dependency "compare_linker", ">= 1.4.3"
41
+ spec.add_dependency "git", "1.7.0"
41
42
  spec.add_dependency "gitlab", ">= 4.14.1"
42
43
  spec.add_dependency "restore_bundled_with"
43
44
 
44
45
  spec.add_development_dependency "dotenv"
45
46
  spec.add_development_dependency "gitlab_awesome_release"
46
- spec.add_development_dependency "onkcop"
47
+ spec.add_development_dependency "onkcop", ">= 1.0.0.0"
47
48
  spec.add_development_dependency "pry-byebug"
48
49
  spec.add_development_dependency "rake", ">= 10.0"
49
50
  spec.add_development_dependency "rspec", "~> 3.0"
51
+ spec.add_development_dependency "rspec-its"
50
52
  spec.add_development_dependency "rspec-temp_dir"
51
- spec.add_development_dependency "rubocop-performance"
52
53
  spec.add_development_dependency "rubocop_auto_corrector"
54
+ spec.add_development_dependency "rubocop-performance"
53
55
  spec.add_development_dependency "simplecov"
54
56
  spec.add_development_dependency "webmock"
55
57
  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
@@ -5,6 +5,7 @@ module Gitlabci
5
5
  class Client # rubocop:disable Metrics/ClassLength
6
6
  BRANCH_PREFIX = "bundle-update-".freeze
7
7
  TITLE_PREFIX = "bundle update at ".freeze
8
+ MAX_RETRY_COUNT = 3
8
9
 
9
10
  # rubocop:disable Metrics/ParameterLists
10
11
 
@@ -28,12 +29,14 @@ module Gitlabci
28
29
  # @param mr_labels [Array<String>]
29
30
  # @param update_bundled_with [Boolean]
30
31
  # @param merge_when_pipeline_succeeds [Boolean]
31
- def perform(allow_dup_mr:, mr_labels:, update_bundled_with:, merge_when_pipeline_succeeds:)
32
+ # @param assignees [Array<String>]
33
+ def perform(allow_dup_mr:, mr_labels:, update_bundled_with:, merge_when_pipeline_succeeds:, assignees:)
32
34
  if !allow_dup_mr && exists_bundle_update_mr?
33
35
  puts "Skip because it has already existed."
34
36
  return
35
37
  end
36
38
 
39
+ assignee_ids = get_assignee_ids(assignees)
37
40
  old_lockfile = File.read(lockfile_name)
38
41
 
39
42
  system!("bundle update")
@@ -51,7 +54,7 @@ module Gitlabci
51
54
  commit_gemfile_lock(new_lockfile)
52
55
  description = merge_request_description(old_lockfile, new_lockfile)
53
56
 
54
- mr = create_merge_request(description: description, mr_labels: mr_labels)
57
+ mr = create_merge_request(description: description, mr_labels: mr_labels, assignee_ids: assignee_ids)
55
58
  puts "MR is created: #{mr.web_url}"
56
59
 
57
60
  if merge_when_pipeline_succeeds
@@ -81,7 +84,10 @@ module Gitlabci
81
84
 
82
85
  # @param description [String]
83
86
  # @param mr_labels [Array<String>]
84
- def create_merge_request(description:, mr_labels:)
87
+ # @param assignee_ids [Array<Integer>]
88
+ #
89
+ # @see https://docs.gitlab.com/ee/api/merge_requests.html#create-mr
90
+ def create_merge_request(description:, mr_labels:, assignee_ids:)
85
91
  params = {
86
92
  source_branch: new_branch,
87
93
  target_branch: @branch,
@@ -93,6 +99,12 @@ module Gitlabci
93
99
  params[:labels] = mr_labels.join(",")
94
100
  end
95
101
 
102
+ if assignee_ids.length == 1
103
+ params[:assignee_id] = assignee_ids[0]
104
+ elsif assignee_ids.length >= 2
105
+ params[:assignee_ids] = assignee_ids
106
+ end
107
+
96
108
  @gitlab.create_merge_request(
97
109
  @project_name,
98
110
  "#{TITLE_PREFIX}#{current_time.strftime("%Y-%m-%d %H:%M:%S %Z")}",
@@ -120,6 +132,33 @@ module Gitlabci
120
132
  MARKDOWN
121
133
  end
122
134
 
135
+ # @param username [String]
136
+ #
137
+ # @return [Gitlab::ObjectifiedHash]
138
+ # @return [nil] User isn't found
139
+ #
140
+ # @see https://docs.gitlab.com/ee/api/users.html#for-normal-users
141
+ def find_by_username(username)
142
+ @gitlab.users(username: username).first
143
+ end
144
+
145
+ # @param username [String]
146
+ #
147
+ # @return [Gitlab::ObjectifiedHash]
148
+ #
149
+ # @raise [Gitlabci::Bundle::Update::Mr::NotFoundUserError]
150
+ #
151
+ # @see https://docs.gitlab.com/ee/api/users.html#for-normal-users
152
+ def find_by_username!(username)
153
+ user = find_by_username(username)
154
+
155
+ unless user
156
+ raise NotFoundUserError, "#{username} isn't found"
157
+ end
158
+
159
+ user
160
+ end
161
+
123
162
  private
124
163
 
125
164
  def system!(command)
@@ -168,7 +207,33 @@ module Gitlabci
168
207
  end
169
208
 
170
209
  def accept_merge_request(mr_id)
171
- @gitlab.accept_merge_request(@project_name, mr_id, merge_when_pipeline_succeeds: true, should_remove_source_branch: true)
210
+ with_retry do
211
+ @gitlab.accept_merge_request(@project_name, mr_id, merge_when_pipeline_succeeds: true, should_remove_source_branch: true)
212
+ end
213
+ end
214
+
215
+ def with_retry
216
+ retry_count ||= 0
217
+
218
+ yield
219
+ rescue Gitlab::Error::MethodNotAllowed, Gitlab::Error::NotAcceptable => e
220
+ retry_count += 1
221
+
222
+ if retry_count > MAX_RETRY_COUNT
223
+ raise e
224
+ end
225
+
226
+ puts "Error is occurred and auto retry (#{retry_count}/#{MAX_RETRY_COUNT}): #{e}"
227
+ sleep 1
228
+
229
+ retry
230
+ end
231
+
232
+ def get_assignee_ids(assignees)
233
+ assignees.map do |username|
234
+ user = find_by_username!(username)
235
+ user.id
236
+ end
172
237
  end
173
238
  end
174
239
  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.2".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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-16 00:00:00.000000000 Z
11
+ date: 2021-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.4.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: git
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: gitlab
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - ">="
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: 1.0.0.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: 1.0.0.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pry-byebug
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +165,7 @@ dependencies:
151
165
  - !ruby/object:Gem::Version
152
166
  version: '3.0'
153
167
  - !ruby/object:Gem::Dependency
154
- name: rspec-temp_dir
168
+ name: rspec-its
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - ">="
@@ -165,7 +179,7 @@ dependencies:
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
- name: rubocop-performance
182
+ name: rspec-temp_dir
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - ">="
@@ -192,6 +206,20 @@ dependencies:
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop-performance
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
195
223
  - !ruby/object:Gem::Dependency
196
224
  name: simplecov
197
225
  requirement: !ruby/object:Gem::Requirement
@@ -270,7 +298,7 @@ metadata:
270
298
  homepage_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr
271
299
  source_code_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr
272
300
  changelog_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr/blob/master/CHANGELOG.md
273
- post_install_message:
301
+ post_install_message:
274
302
  rdoc_options: []
275
303
  require_paths:
276
304
  - lib
@@ -285,8 +313,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
313
  - !ruby/object:Gem::Version
286
314
  version: '0'
287
315
  requirements: []
288
- rubygems_version: 3.1.2
289
- signing_key:
316
+ rubygems_version: 3.1.4
317
+ signing_key:
290
318
  specification_version: 4
291
319
  summary: Create MergeRequest of bundle update in GitLab CI
292
320
  test_files: []