gitlabci-bundle-update-mr 0.2.1 → 1.1.1.beta1

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: e79a247314e92818cfc085b4d48deb88d5db6b6a3da9a978ec8af66bcc0dad35
4
- data.tar.gz: bab306bb6c3c3d0969ec465e341668016c12b189e156c8906a4b52be1866521a
3
+ metadata.gz: 229a9fbae1ea6840f3f383b08cc83a15ff50d28739f06dfd5987564424ae7ab2
4
+ data.tar.gz: 677df6d813f5b0609e336323496c23c9a789c2fc5dfdcff31cb3095f57057c90
5
5
  SHA512:
6
- metadata.gz: 44b5d05f9c1a990299c59f5dbfc0ad631cf17487ef1f15d35321413bbd9b4780288c3d2eb6222786b69114a26d27f4d29b136de175e8b9be346e16bcbd39c4f2
7
- data.tar.gz: 0b5c0129e80a32e4c704260ff6c260d50efbc9ee35c8547274e18b686feb55c295f217eec1cfc5f761b7badc8f5a7976f30cc7e854045555d4db5b38971ec6e8
6
+ metadata.gz: 294bd4ec7d61cbf932e168386463eed2428f846e96e92959a44f4380e9f6640e98d75b8f17c0a8217a4be42401adebb57dd7bb623ceb81e4fd52e6cdb3aba329
7
+ data.tar.gz: 53be10193139b5fc00e3a4f228362b60ebf3a83c9565737307c442047855fd18faad20085a81a3a314313a64a985af3aafd6799842ccd160ed3f43d673315ce7
@@ -12,6 +12,8 @@ continuous_bundle_update:
12
12
  CACHE_VERSION: "v2"
13
13
  GIT_EMAIL: "gitlabci@example.com"
14
14
  GIT_USER: "GitLab CI"
15
+ OPTIONS: "--merge-when-pipeline-succeeds"
16
+ ASSIGNEES: "sue445"
15
17
 
16
18
  before_script:
17
19
  # Set timezone to Asia/Tokyo
@@ -21,14 +23,15 @@ continuous_bundle_update:
21
23
  - schedules
22
24
  - web # Test for topic branch
23
25
 
24
- .default: &default
26
+ .default:
25
27
  cache:
26
28
  key: "$CI_BUILD_NAME"
27
29
  paths:
28
30
  - vendor/bundle/
29
31
 
30
32
  before_script:
31
- - bundle install --path vendor/bundle
33
+ - bundle config --local path 'vendor/bundle'
34
+ - bundle install --retry=3 --jobs=$(nproc)
32
35
  - bundle clean
33
36
 
34
37
  except:
@@ -36,8 +39,8 @@ continuous_bundle_update:
36
39
  - web
37
40
  - tags
38
41
 
39
- .test: &test
40
- <<: *default
42
+ .test:
43
+ extends: .default
41
44
 
42
45
  stage: build
43
46
 
@@ -45,34 +48,44 @@ continuous_bundle_update:
45
48
  - bundle exec rspec
46
49
  - bundle exec ./exe/gitlabci-bundle-update-mr --help
47
50
 
48
- test:2.3:
49
- <<: *test
50
-
51
- image: ruby:2.3
52
-
53
- test:2.4:
54
- <<: *test
55
-
56
- image: ruby:2.4
57
-
58
51
  test:2.5:
59
- <<: *test
52
+ extends: .test
60
53
 
61
54
  image: ruby:2.5
62
55
 
63
56
  test:2.6:
64
- <<: *test
57
+ extends: .test
65
58
 
66
59
  image: ruby:2.6
67
60
 
61
+ test:2.7:
62
+ extends: .test
63
+
64
+ image: ruby:2.7
65
+
66
+ test:3.0:
67
+ extends: .test
68
+
69
+ image: ruby:3.0
70
+
68
71
  test:trunk:
69
- <<: *test
72
+ extends: .test
70
73
 
71
74
  image: rubylang/ruby:trunk-nightly-bionic
72
75
  allow_failure: true
73
76
 
77
+ rubocop:
78
+ extends: .default
79
+
80
+ stage: build
81
+
82
+ image: ruby
83
+
84
+ script:
85
+ - bundle exec rubocop -P
86
+
74
87
  pages:
75
- <<: *default
88
+ extends: .default
76
89
 
77
90
  stage: deploy
78
91
 
@@ -0,0 +1,29 @@
1
+ require: rubocop-performance
2
+
3
+ inherit_gem:
4
+ onkcop:
5
+ - "config/rubocop.yml"
6
+ # uncomment if use rails cops
7
+ # - "config/rails.yml"
8
+ # uncomment if use rspec cops
9
+ # - "config/rspec.yml"
10
+
11
+ AllCops:
12
+ TargetRubyVersion: 2.5
13
+ NewCops: enable
14
+
15
+ Layout/HashAlignment:
16
+ EnforcedHashRocketStyle: table
17
+ EnforcedColonStyle: table
18
+
19
+ Layout/IndentationConsistency:
20
+ EnforcedStyle: indented_internal_methods
21
+
22
+ Layout/FirstArrayElementIndentation:
23
+ EnforcedStyle: consistent
24
+
25
+ Layout/FirstHashElementIndentation:
26
+ EnforcedStyle: consistent
27
+
28
+ Metrics/MethodLength:
29
+ Max: 22
@@ -1,5 +1,27 @@
1
1
  ## Unreleased
2
- [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.2.1...HEAD)
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*
8
+
9
+ ## v1.0.0
10
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.3.0...v1.0.0)
11
+
12
+ ### Breaking changes :warning:
13
+ * Drop support ruby < 2.5 [!87](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/87) *@sue445*
14
+
15
+ ## v0.3.0
16
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.2.2...v0.3.0)
17
+
18
+ * Support "Merge when pipeline succeeds" [!41](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/41) *@sue445*
19
+
20
+ ## v0.2.2
21
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.2.1...v0.2.2)
22
+
23
+ ### Bugfix
24
+ * Bugfix. doesn't work `--update-bundled-with` option [!30](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/30) *@sue445*
3
25
 
4
26
  ## v0.2.1
5
27
  [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.2.0...v0.2.1)
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "https://rubygems.org"
2
+ git_source(:github) {|repo| "https://github.com/#{repo}.git" }
2
3
 
3
4
  # Specify your gem's dependencies in gitlabci-bundle-update-mr.gemspec
4
5
  gemspec
@@ -7,3 +8,11 @@ gemspec
7
8
  gem "faraday", ">= 0.15.4"
8
9
  gem "octokit", ">= 4.13.0"
9
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,95 +1,138 @@
1
+ GIT
2
+ remote: https://github.com/sue445/onkcop.git
3
+ revision: d09f75a5eeb1969800cca160f653325771590fae
4
+ branch: develop
5
+ specs:
6
+ onkcop (0.53.0.3)
7
+ rubocop (>= 0.53.0)
8
+ rubocop-rspec (>= 1.34.0)
9
+
1
10
  PATH
2
11
  remote: .
3
12
  specs:
4
- gitlabci-bundle-update-mr (0.2.1)
13
+ gitlabci-bundle-update-mr (1.1.1.beta1)
5
14
  bundler
6
15
  compare_linker (>= 1.4.3)
7
- gitlab (>= 4.0.0)
16
+ gitlab (>= 4.14.1)
8
17
  restore_bundled_with
9
18
 
10
19
  GEM
11
20
  remote: https://rubygems.org/
12
21
  specs:
13
- addressable (2.5.2)
14
- public_suffix (>= 2.0.2, < 4.0)
15
- byebug (11.0.0)
16
- coderay (1.1.2)
17
- compare_linker (1.4.3)
22
+ addressable (2.7.0)
23
+ public_suffix (>= 2.0.2, < 5.0)
24
+ ast (2.4.1)
25
+ byebug (11.1.3)
26
+ coderay (1.1.3)
27
+ compare_linker (1.4.4)
18
28
  httpclient
19
29
  octokit
20
- crack (0.4.3)
21
- safe_yaml (~> 1.0.0)
22
- diff-lcs (1.3)
23
- docile (1.3.1)
24
- dotenv (2.7.1)
25
- faraday (0.15.4)
30
+ crack (0.4.5)
31
+ rexml
32
+ diff-lcs (1.4.4)
33
+ docile (1.3.4)
34
+ dotenv (2.7.6)
35
+ faraday (1.2.0)
26
36
  multipart-post (>= 1.2, < 3)
27
- git (1.5.0)
28
- gitlab (4.10.0)
29
- httparty (~> 0.14, >= 0.14.0)
37
+ ruby2_keywords
38
+ git (1.7.0)
39
+ rchardet (~> 1.8)
40
+ gitlab (4.17.0)
41
+ httparty (~> 0.18)
30
42
  terminal-table (~> 1.5, >= 1.5.1)
31
43
  gitlab_awesome_release (1.0.2)
32
44
  dotenv
33
45
  gitlab (>= 4.0.0)
34
46
  thor
35
- hashdiff (0.3.8)
36
- httparty (0.16.4)
47
+ hashdiff (1.0.1)
48
+ httparty (0.18.1)
37
49
  mime-types (~> 3.0)
38
50
  multi_xml (>= 0.5.2)
39
51
  httpclient (2.8.3)
40
- json (2.2.0)
41
- method_source (0.9.2)
42
- mime-types (3.2.2)
52
+ method_source (1.0.0)
53
+ mime-types (3.3.1)
43
54
  mime-types-data (~> 3.2015)
44
- mime-types-data (3.2018.0812)
55
+ mime-types-data (3.2020.1104)
45
56
  multi_xml (0.6.0)
46
- multipart-post (2.0.0)
47
- octokit (4.13.0)
57
+ multipart-post (2.1.1)
58
+ octokit (4.19.0)
59
+ faraday (>= 0.9)
48
60
  sawyer (~> 0.8.0, >= 0.5.3)
49
- pry (0.12.2)
50
- coderay (~> 1.1.0)
51
- method_source (~> 0.9.0)
52
- pry-byebug (3.7.0)
61
+ parallel (1.20.1)
62
+ parser (3.0.0.0)
63
+ ast (~> 2.4.1)
64
+ pry (0.13.1)
65
+ coderay (~> 1.1)
66
+ method_source (~> 1.0)
67
+ pry-byebug (3.9.0)
53
68
  byebug (~> 11.0)
54
- pry (~> 0.10)
55
- public_suffix (3.0.3)
56
- rake (10.5.0)
69
+ pry (~> 0.13.0)
70
+ public_suffix (4.0.6)
71
+ rainbow (3.0.0)
72
+ rake (13.0.3)
73
+ rchardet (1.8.0)
74
+ regexp_parser (2.0.2)
57
75
  restore_bundled_with (1.0.0)
58
76
  git
59
77
  thor
60
- rspec (3.8.0)
61
- rspec-core (~> 3.8.0)
62
- rspec-expectations (~> 3.8.0)
63
- rspec-mocks (~> 3.8.0)
64
- rspec-core (3.8.0)
65
- rspec-support (~> 3.8.0)
66
- rspec-expectations (3.8.2)
78
+ rexml (3.2.4)
79
+ rspec (3.10.0)
80
+ rspec-core (~> 3.10.0)
81
+ rspec-expectations (~> 3.10.0)
82
+ rspec-mocks (~> 3.10.0)
83
+ rspec-core (3.10.1)
84
+ rspec-support (~> 3.10.0)
85
+ rspec-expectations (3.10.1)
67
86
  diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.8.0)
69
- rspec-mocks (3.8.0)
87
+ rspec-support (~> 3.10.0)
88
+ rspec-its (1.3.0)
89
+ rspec-core (>= 3.0.0)
90
+ rspec-expectations (>= 3.0.0)
91
+ rspec-mocks (3.10.0)
70
92
  diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.8.0)
72
- rspec-support (3.8.0)
93
+ rspec-support (~> 3.10.0)
94
+ rspec-support (3.10.1)
73
95
  rspec-temp_dir (1.1.0)
74
96
  rspec (>= 3.0)
75
- safe_yaml (1.0.5)
76
- sawyer (0.8.1)
77
- addressable (>= 2.3.5, < 2.6)
78
- faraday (~> 0.8, < 1.0)
79
- simplecov (0.16.1)
97
+ rubocop (1.7.0)
98
+ parallel (~> 1.10)
99
+ parser (>= 2.7.1.5)
100
+ rainbow (>= 2.2.2, < 4.0)
101
+ regexp_parser (>= 1.8, < 3.0)
102
+ rexml
103
+ rubocop-ast (>= 1.2.0, < 2.0)
104
+ ruby-progressbar (~> 1.7)
105
+ unicode-display_width (>= 1.4.0, < 2.0)
106
+ rubocop-ast (1.3.0)
107
+ parser (>= 2.7.1.5)
108
+ rubocop-performance (1.9.1)
109
+ rubocop (>= 0.90.0, < 2.0)
110
+ rubocop-ast (>= 0.4.0)
111
+ rubocop-rspec (2.1.0)
112
+ rubocop (~> 1.0)
113
+ rubocop-ast (>= 1.1.0)
114
+ rubocop_auto_corrector (0.4.1)
115
+ rubocop (>= 0.87.0)
116
+ ruby-progressbar (1.10.1)
117
+ ruby2_keywords (0.0.2)
118
+ sawyer (0.8.2)
119
+ addressable (>= 2.3.5)
120
+ faraday (> 0.8, < 2.0)
121
+ simplecov (0.20.0)
80
122
  docile (~> 1.1)
81
- json (>= 1.8, < 3)
82
- simplecov-html (~> 0.10.0)
83
- simplecov-html (0.10.2)
123
+ simplecov-html (~> 0.11)
124
+ simplecov_json_formatter (~> 0.1)
125
+ simplecov-html (0.12.3)
126
+ simplecov_json_formatter (0.1.2)
84
127
  terminal-table (1.8.0)
85
128
  unicode-display_width (~> 1.1, >= 1.1.1)
86
- thor (0.20.3)
87
- unicode-display_width (1.5.0)
88
- webmock (3.5.1)
129
+ thor (1.0.1)
130
+ unicode-display_width (1.7.0)
131
+ webmock (3.11.0)
89
132
  addressable (>= 2.3.6)
90
133
  crack (>= 0.3.2)
91
- hashdiff
92
- yard (0.9.18)
134
+ hashdiff (>= 0.4.0, < 2.0.0)
135
+ yard (0.9.26)
93
136
 
94
137
  PLATFORMS
95
138
  ruby
@@ -100,10 +143,15 @@ DEPENDENCIES
100
143
  gitlab_awesome_release
101
144
  gitlabci-bundle-update-mr!
102
145
  octokit (>= 4.13.0)
146
+ onkcop!
103
147
  pry-byebug
104
- rake (~> 10.0)
148
+ rake (>= 10.0)
105
149
  rspec (~> 3.0)
150
+ rspec-its
106
151
  rspec-temp_dir
152
+ rubocop (>= 0.68.0)
153
+ rubocop-performance
154
+ rubocop_auto_corrector
107
155
  sawyer (>= 0.8.1)
108
156
  simplecov
109
157
  webmock
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Gitlabci::Bundle::Update::Mr
2
2
  [![Gem Version](https://badge.fury.io/rb/gitlabci-bundle-update-mr.svg)](https://badge.fury.io/rb/gitlabci-bundle-update-mr)
3
+ [![pipeline status](https://gitlab.com/sue445/gitlabci-bundle-update-mr/badges/master/pipeline.svg)](https://gitlab.com/sue445/gitlabci-bundle-update-mr/commits/master)
4
+ [![coverage report](https://gitlab.com/sue445/gitlabci-bundle-update-mr/badges/master/coverage.svg)](https://gitlab.com/sue445/gitlabci-bundle-update-mr/commits/master)
3
5
 
4
6
  Create MergeRequest of bundle update in GitLab CI
5
7
 
@@ -80,7 +82,7 @@ continuous_bundle_update:
80
82
 
81
83
  * GitLab Core 11.4+
82
84
  * GitLab Premium 10.5+
83
- * Starter, Premium and Ultimate 10.6+)
85
+ * Starter, Premium and Ultimate 10.6+
84
86
 
85
87
  c.f. https://docs.gitlab.com/ce/ci/yaml/README.html#include
86
88
 
@@ -88,17 +90,18 @@ example
88
90
 
89
91
  ```yml
90
92
  include:
91
- - remote: "https://gitlab.com/sue445/gitlabci-bundle-update-mr/blob/master/gitlabci-templates/continuous_bundle_update.yml"
93
+ - remote: "https://gitlab.com/sue445/gitlabci-bundle-update-mr/raw/master/gitlabci-templates/continuous_bundle_update.yml"
92
94
 
93
95
  continuous_bundle_update:
94
96
  stage: build
95
97
 
96
98
  variables:
97
- # override variables (followings are defailts)
99
+ # override variables (followings are defaults)
98
100
  CACHE_VERSION: "v1"
99
101
  GIT_EMAIL: "gitlabci@example.com"
100
102
  GIT_USER: "GitLab CI"
101
103
  LABELS: "bundle update"
104
+ ASSIGNEES: "foo, bar, baz"
102
105
  OPTIONS: ""
103
106
 
104
107
  before_script:
@@ -120,8 +123,40 @@ Usage: gitlabci-bundle-update-mr [options]
120
123
  -d, --duplicate Make MR even if it has already existed (default. false)
121
124
  -l, --labels 'In Review, Update' Add labels to the MR
122
125
  --update-bundled-with Whether to update `BUNDLED WITH` section in Gemfie.lock (default. false)
126
+ --merge-when-pipeline-succeeds
127
+ Whether to set 'Merge when pipeline succeeds' (default. false)
128
+ --assignees 'foo, bar' Add assignees to the MR
123
129
  ```
124
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
+
125
160
  ## Development
126
161
 
127
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.
@@ -10,12 +10,16 @@ author_name = `git config user.name`.strip
10
10
  allow_dup_mr = false
11
11
  mr_labels = []
12
12
  update_bundled_with = false
13
+ merge_when_pipeline_succeeds = false
14
+ assignees = []
13
15
 
14
- opt.on("--email EMAIL", "git email address (default. `git config user.email`)") { |v| author_email = v }
15
- opt.on("--user USER", "git username (default. `git config user.name`)") { |v| author_name = v }
16
- opt.on("-d", "--duplicate", "Make MR even if it has already existed (default. false)") { |v| allow_dup_mr = v }
17
- opt.on("-l", "--labels 'In Review, Update'", Array, "Add labels to the MR") { |v| mr_labels = v.map(&:strip) }
18
- opt.on("--update-bundled-with", "Whether to update `BUNDLED WITH` section in Gemfie.lock (default. false)") { |v| p v }
16
+ opt.on("--email EMAIL", "git email address (default. `git config user.email`)") {|v| author_email = v }
17
+ opt.on("--user USER", "git username (default. `git config user.name`)") {|v| author_name = v }
18
+ opt.on("-d", "--duplicate", "Make MR even if it has already existed (default. false)") {|v| allow_dup_mr = v }
19
+ opt.on("-l", "--labels 'In Review, Update'", Array, "Add labels to the MR") {|v| mr_labels = v.map(&:strip) }
20
+ opt.on("--update-bundled-with", "Whether to update `BUNDLED WITH` section in Gemfie.lock (default. false)") {|v| update_bundled_with = v }
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) }
19
23
 
20
24
  opt.parse!(ARGV)
21
25
 
@@ -30,4 +34,10 @@ client = Gitlabci::Bundle::Update::Mr::Client.new(
30
34
  author_name: author_name,
31
35
  )
32
36
 
33
- client.perform(allow_dup_mr: allow_dup_mr, mr_labels: mr_labels, update_bundled_with: update_bundled_with)
37
+ client.perform(
38
+ allow_dup_mr: allow_dup_mr,
39
+ mr_labels: mr_labels,
40
+ update_bundled_with: update_bundled_with,
41
+ merge_when_pipeline_succeeds: merge_when_pipeline_succeeds,
42
+ assignees: assignees,
43
+ )
@@ -1,5 +1,4 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "gitlabci/bundle/update/mr/version"
5
4
 
@@ -9,8 +8,8 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ["sue445"]
10
9
  spec.email = ["sue445@sue445.net"]
11
10
 
12
- spec.summary = %q{Create MergeRequest of bundle update in GitLab CI}
13
- spec.description = %q{Create MergeRequest of bundle update in GitLab CI}
11
+ spec.summary = "Create MergeRequest of bundle update in GitLab CI"
12
+ spec.description = "Create MergeRequest of bundle update in GitLab CI"
14
13
  spec.homepage = "https://gitlab.com/sue445/gitlabci-bundle-update-mr"
15
14
  spec.license = "MIT"
16
15
 
@@ -27,27 +26,31 @@ Gem::Specification.new do |spec|
27
26
 
28
27
  # Specify which files should be added to the gem when it is released.
29
28
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|img)/}) }
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features|img)/}) }
32
31
  end
33
32
 
34
33
  spec.bindir = "exe"
35
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
36
35
  spec.require_paths = ["lib"]
37
36
 
38
- spec.required_ruby_version = ">= 2.3.0"
37
+ spec.required_ruby_version = ">= 2.5.0"
39
38
 
40
39
  spec.add_dependency "bundler"
41
40
  spec.add_dependency "compare_linker", ">= 1.4.3"
42
- spec.add_dependency "gitlab", ">= 4.0.0"
41
+ spec.add_dependency "gitlab", ">= 4.14.1"
43
42
  spec.add_dependency "restore_bundled_with"
44
43
 
45
44
  spec.add_development_dependency "dotenv"
46
45
  spec.add_development_dependency "gitlab_awesome_release"
46
+ spec.add_development_dependency "onkcop"
47
47
  spec.add_development_dependency "pry-byebug"
48
- spec.add_development_dependency "rake", "~> 10.0"
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"
52
+ spec.add_development_dependency "rubocop_auto_corrector"
53
+ spec.add_development_dependency "rubocop-performance"
51
54
  spec.add_development_dependency "simplecov"
52
55
  spec.add_development_dependency "webmock"
53
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,14 +14,16 @@ 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
- %w(
19
- OCTOKIT_ACCESS_TOKEN
20
- GITLAB_API_ENDPOINT
21
- GITLAB_API_PRIVATE_TOKEN
22
- CI_PROJECT_PATH
23
- CI_COMMIT_REF_NAME
24
- ).each do |key|
20
+ %w[
21
+ OCTOKIT_ACCESS_TOKEN
22
+ GITLAB_API_ENDPOINT
23
+ GITLAB_API_PRIVATE_TOKEN
24
+ CI_PROJECT_PATH
25
+ CI_COMMIT_REF_NAME
26
+ ].each do |key|
25
27
  assert_env_key(key)
26
28
  end
27
29
  end
@@ -2,9 +2,12 @@ module Gitlabci
2
2
  module Bundle
3
3
  module Update
4
4
  module Mr
5
- class Client
6
- BRANCH_PREFIX = "bundle-update-"
7
- TITLE_PREFIX = "bundle update at "
5
+ class Client # rubocop:disable Metrics/ClassLength
6
+ BRANCH_PREFIX = "bundle-update-".freeze
7
+ TITLE_PREFIX = "bundle update at ".freeze
8
+ MAX_RETRY_COUNT = 3
9
+
10
+ # rubocop:disable Metrics/ParameterLists
8
11
 
9
12
  # @param gitlab_api_endpoint [String]
10
13
  # @param gitlab_api_private_token [String]
@@ -20,16 +23,20 @@ module Gitlabci
20
23
  @author_email = author_email
21
24
  @author_name = author_name
22
25
  end
26
+ # rubocop:enable Metrics/ParameterLists
23
27
 
24
28
  # @param allow_dup_mr [Boolean]
25
29
  # @param mr_labels [Array<String>]
26
30
  # @param update_bundled_with [Boolean]
27
- def perform(allow_dup_mr:, mr_labels:, update_bundled_with:)
31
+ # @param merge_when_pipeline_succeeds [Boolean]
32
+ # @param assignees [Array<String>]
33
+ def perform(allow_dup_mr:, mr_labels:, update_bundled_with:, merge_when_pipeline_succeeds:, assignees:)
28
34
  if !allow_dup_mr && exists_bundle_update_mr?
29
35
  puts "Skip because it has already existed."
30
36
  return
31
37
  end
32
38
 
39
+ assignee_ids = get_assignee_ids(assignees)
33
40
  old_lockfile = File.read(lockfile_name)
34
41
 
35
42
  system!("bundle update")
@@ -47,8 +54,13 @@ module Gitlabci
47
54
  commit_gemfile_lock(new_lockfile)
48
55
  description = merge_request_description(old_lockfile, new_lockfile)
49
56
 
50
- 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)
51
58
  puts "MR is created: #{mr.web_url}"
59
+
60
+ if merge_when_pipeline_succeeds
61
+ accept_merge_request(mr.iid)
62
+ puts "Set merge_when_pipeline_succeeds to #{mr.web_url}"
63
+ end
52
64
  end
53
65
 
54
66
  # @param lockfile [String]
@@ -59,31 +71,40 @@ module Gitlabci
59
71
  "$ bundle update && bundle update --ruby",
60
72
  [
61
73
  {
62
- action: "update",
74
+ action: "update",
63
75
  file_path: lockfile_name,
64
- content: lockfile,
65
- }
76
+ content: lockfile,
77
+ },
66
78
  ],
67
79
  start_branch: @branch,
68
80
  author_email: @author_email,
69
- author_name: @author_name,
81
+ author_name: @author_name,
70
82
  )
71
83
  end
72
84
 
73
85
  # @param description [String]
74
86
  # @param mr_labels [Array<String>]
75
- 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:)
76
91
  params = {
77
- source_branch: new_branch,
78
- target_branch: @branch,
92
+ source_branch: new_branch,
93
+ target_branch: @branch,
79
94
  remove_source_branch: true,
80
- description: description
95
+ description: description,
81
96
  }
82
97
 
83
98
  unless mr_labels.empty?
84
99
  params[:labels] = mr_labels.join(",")
85
100
  end
86
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
+
87
108
  @gitlab.create_merge_request(
88
109
  @project_name,
89
110
  "#{TITLE_PREFIX}#{current_time.strftime("%Y-%m-%d %H:%M:%S %Z")}",
@@ -99,8 +120,8 @@ module Gitlabci
99
120
  compare_linker = CompareLinker.new("dummy", "dummy")
100
121
  compare_linker.formatter = CompareLinker::Formatter::Markdown.new
101
122
  compare_links = compare_linker.
102
- make_compare_links_from_lockfiles(Bundler::LockfileParser.new(old_lockfile), Bundler::LockfileParser.new(new_lockfile)).
103
- to_a.join("\n")
123
+ make_compare_links_from_lockfiles(Bundler::LockfileParser.new(old_lockfile), Bundler::LockfileParser.new(new_lockfile)).
124
+ to_a.join("\n")
104
125
 
105
126
  <<~MARKDOWN
106
127
  **Updated RubyGems:**
@@ -111,52 +132,106 @@ module Gitlabci
111
132
  MARKDOWN
112
133
  end
113
134
 
114
- private
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
115
144
 
116
- def system!(command)
117
- # NOTE: system(exception: true) requires Ruby 2.6+
118
- ret = system(command)
119
- raise "`#{command}` is failed" unless ret
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
120
160
  end
121
161
 
122
- def restore_bundled_with
123
- RestoreBundledWith::CLI.new.invoke(
124
- :restore,
125
- [],
126
- {
127
- lockfile: lockfile_name,
128
- },
162
+ private
163
+
164
+ def system!(command)
165
+ # NOTE: system(exception: true) requires Ruby 2.6+
166
+ ret = system(command)
167
+ raise "`#{command}` is failed" unless ret
168
+ end
169
+
170
+ def restore_bundled_with
171
+ RestoreBundledWith::CLI.new.invoke(
172
+ :restore,
173
+ [],
174
+ {
175
+ lockfile: lockfile_name,
176
+ },
129
177
  )
130
- end
178
+ end
179
+
180
+ def gemfile_name
181
+ return @gemfile_name if @gemfile_name
131
182
 
132
- def gemfile_name
133
- return @gemfile_name if @gemfile_name
183
+ @gemfile_name = ENV["BUNDLE_GEMFILE"] || "Gemfile"
134
184
 
135
- @gemfile_name = ENV["BUNDLE_GEMFILE"] || "Gemfile"
185
+ if @gemfile_name.start_with?("#{Dir.pwd}/")
186
+ @gemfile_name = @gemfile_name.gsub("#{Dir.pwd}/", "")
187
+ end
136
188
 
137
- if @gemfile_name.start_with?("#{Dir.pwd}/")
138
- @gemfile_name = @gemfile_name.gsub("#{Dir.pwd}/", "")
189
+ @gemfile_name
139
190
  end
140
191
 
141
- @gemfile_name
142
- end
192
+ def lockfile_name
193
+ "#{gemfile_name}.lock"
194
+ end
143
195
 
144
- def lockfile_name
145
- "#{gemfile_name}.lock"
146
- end
196
+ def current_time
197
+ @current_time ||= Time.now
198
+ end
147
199
 
148
- def current_time
149
- @current_time ||= Time.now
150
- end
200
+ def new_branch
201
+ "#{BRANCH_PREFIX}#{current_time.strftime("%Y%m%d%H%M%S")}"
202
+ end
151
203
 
152
- def new_branch
153
- "#{BRANCH_PREFIX}#{current_time.strftime("%Y%m%d%H%M%S")}"
154
- end
204
+ def exists_bundle_update_mr?
205
+ merge_requests = @gitlab.merge_requests(@project_name, state: "opened", target_branch: @branch, search: TITLE_PREFIX.strip)
206
+ merge_requests.any? {|mr| mr.title.start_with?(TITLE_PREFIX) && mr.source_branch.start_with?(BRANCH_PREFIX) }
207
+ end
155
208
 
156
- def exists_bundle_update_mr?
157
- merge_requests = @gitlab.merge_requests(@project_name, state: "opened", target_branch: @branch, search: TITLE_PREFIX.strip)
158
- merge_requests.any? { |mr| mr.title.start_with?(TITLE_PREFIX) && mr.source_branch.start_with?(BRANCH_PREFIX) }
159
- end
209
+ def accept_merge_request(mr_id)
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 => e
220
+ retry_count += 1
221
+
222
+ if retry_count > MAX_RETRY_COUNT
223
+ raise e
224
+ end
225
+
226
+ retry
227
+ end
228
+
229
+ def get_assignee_ids(assignees)
230
+ assignees.map do |username|
231
+ user = find_by_username!(username)
232
+ user.id
233
+ end
234
+ end
160
235
  end
161
236
  end
162
237
  end
@@ -2,7 +2,7 @@ module Gitlabci
2
2
  module Bundle
3
3
  module Update
4
4
  module Mr
5
- VERSION = "0.2.1"
5
+ VERSION = "1.1.1.beta1".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: 0.2.1
4
+ version: 1.1.1.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-07 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.0
47
+ version: 4.14.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 4.0.0
54
+ version: 4.14.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: restore_bundled_with
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: onkcop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: pry-byebug
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +126,14 @@ dependencies:
112
126
  name: rake
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - "~>"
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
131
  version: '10.0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - "~>"
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '10.0'
125
139
  - !ruby/object:Gem::Dependency
@@ -136,6 +150,20 @@ dependencies:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '3.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-its
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: rspec-temp_dir
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +178,34 @@ dependencies:
150
178
  - - ">="
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop_auto_corrector
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
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'
153
209
  - !ruby/object:Gem::Dependency
154
210
  name: simplecov
155
211
  requirement: !ruby/object:Gem::Requirement
@@ -205,6 +261,7 @@ files:
205
261
  - ".gitignore"
206
262
  - ".gitlab-ci.yml"
207
263
  - ".rspec"
264
+ - ".rubocop.yml"
208
265
  - ".yardopts"
209
266
  - CHANGELOG.md
210
267
  - Gemfile
@@ -227,7 +284,7 @@ metadata:
227
284
  homepage_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr
228
285
  source_code_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr
229
286
  changelog_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr/blob/master/CHANGELOG.md
230
- post_install_message:
287
+ post_install_message:
231
288
  rdoc_options: []
232
289
  require_paths:
233
290
  - lib
@@ -235,15 +292,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
292
  requirements:
236
293
  - - ">="
237
294
  - !ruby/object:Gem::Version
238
- version: 2.3.0
295
+ version: 2.5.0
239
296
  required_rubygems_version: !ruby/object:Gem::Requirement
240
297
  requirements:
241
- - - ">="
298
+ - - ">"
242
299
  - !ruby/object:Gem::Version
243
- version: '0'
300
+ version: 1.3.1
244
301
  requirements: []
245
- rubygems_version: 3.0.1
246
- signing_key:
302
+ rubygems_version: 3.1.4
303
+ signing_key:
247
304
  specification_version: 4
248
305
  summary: Create MergeRequest of bundle update in GitLab CI
249
306
  test_files: []