gitlabci-bundle-update-mr 0.2.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: d607680fe4d0fa78918da62e4777d8be1db5421949306682d83602bc538b3516
4
- data.tar.gz: 692a716488d0553385164b0b8ad8a3ba78094764e72aad2608d6153aa073c242
3
+ metadata.gz: 328b0a88d5bbc5b521b604ee4d223ebe299b0b3eeb130680c18683ff8150bfc4
4
+ data.tar.gz: fff81a3041e33440121420c3adbace6229105eddce5ce3514e726313af5a8d1a
5
5
  SHA512:
6
- metadata.gz: 7fea1ef7556ef71806db573a3205c84689723641c0c9feb9279f0915601d2e0ab76ac8d38367e97335e6de27915bbdcbfbaecf77dd5dfe1a8bb88731d40d95b7
7
- data.tar.gz: 735ea90e2f2cb29bf35a17490bbc8a074d13bee45f0de44f5df825a3371070b220569f029b2c140e89ba5902775ae56ffcc599cc7e4397f014d9ceb52263b2e2
6
+ metadata.gz: e1b567cbe53d70bb6677221d500d07a417db35dfbbfc8c2061056926b1e6a2840f203cfab1ed8983c48591d74a28efbe08411bbebb122e27d08f7a2535c18ef0
7
+ data.tar.gz: 3bba3ccee80b94393b1294a0238b4bf0a21e8463a8b1e42ef99e4a5b4d8ed3574b50a70219efc8114d5dab82ced6abfaf9b9335f23b268f9cbca99e1baa0f5bc
@@ -2,7 +2,28 @@ stages:
2
2
  - build
3
3
  - deploy
4
4
 
5
- .default: &default
5
+ include:
6
+ - local: "/gitlabci-templates/continuous_bundle_update.yml"
7
+
8
+ continuous_bundle_update:
9
+ stage: build
10
+
11
+ variables:
12
+ CACHE_VERSION: "v2"
13
+ GIT_EMAIL: "gitlabci@example.com"
14
+ GIT_USER: "GitLab CI"
15
+ OPTIONS: "--merge-when-pipeline-succeeds"
16
+ ASSIGNEES: "sue445"
17
+
18
+ before_script:
19
+ # Set timezone to Asia/Tokyo
20
+ - cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
21
+
22
+ only:
23
+ - schedules
24
+ - web # Test for topic branch
25
+
26
+ .default:
6
27
  cache:
7
28
  key: "$CI_BUILD_NAME"
8
29
  paths:
@@ -17,8 +38,8 @@ stages:
17
38
  - web
18
39
  - tags
19
40
 
20
- .test: &test
21
- <<: *default
41
+ .test:
42
+ extends: .default
22
43
 
23
44
  stage: build
24
45
 
@@ -26,59 +47,39 @@ stages:
26
47
  - bundle exec rspec
27
48
  - bundle exec ./exe/gitlabci-bundle-update-mr --help
28
49
 
29
- test:2.3:
30
- <<: *test
31
-
32
- image: ruby:2.3
33
-
34
- test:2.4:
35
- <<: *test
36
-
37
- image: ruby:2.4
38
-
39
50
  test:2.5:
40
- <<: *test
51
+ extends: .test
41
52
 
42
53
  image: ruby:2.5
43
54
 
44
55
  test:2.6:
45
- <<: *test
56
+ extends: .test
46
57
 
47
58
  image: ruby:2.6
48
59
 
60
+ test:2.7:
61
+ extends: .test
62
+
63
+ image: ruby:2.7
64
+
49
65
  test:trunk:
50
- <<: *test
66
+ extends: .test
51
67
 
52
68
  image: rubylang/ruby:trunk-nightly-bionic
53
69
  allow_failure: true
54
70
 
55
- continuous_bundle_update:
71
+ rubocop:
72
+ extends: .default
73
+
56
74
  stage: build
57
75
 
58
76
  image: ruby
59
77
 
60
- cache:
61
- key: "$CI_BUILD_NAME"
62
- paths:
63
- - vendor/bundle/
64
-
65
- before_script:
66
- - bundle install --path vendor/bundle
67
- - bundle clean
68
-
69
- # Set timezone to Asia/Tokyo
70
- - cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
71
-
72
78
  script:
73
- - gem install --no-doc gitlabci-bundle-update-mr
74
- - gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com" --labels="bundle update"
75
-
76
- only:
77
- - schedules
78
- - web # Test for topic branch
79
+ - bundle exec rubocop -P
79
80
 
80
81
  pages:
81
- <<: *default
82
+ extends: .default
82
83
 
83
84
  stage: deploy
84
85
 
@@ -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,34 @@
1
1
  ## Unreleased
2
- [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.2.0...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*
25
+
26
+ ## v0.2.1
27
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.2.0...v0.2.1)
28
+
29
+ ### Others
30
+ * Add gitlabci-templates/continuous_bundle_update.yml [!27](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/27) *@sue445*
31
+ * bundle update at 2019-03-07 00:56:00 JST [!26](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/26) *@sue445*
3
32
 
4
33
  ## v0.2.0
5
34
  [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.1.1...v0.2.0)
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,132 @@
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
+
1
10
  PATH
2
11
  remote: .
3
12
  specs:
4
- gitlabci-bundle-update-mr (0.2.0)
13
+ gitlabci-bundle-update-mr (1.1.0)
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.4)
31
+ diff-lcs (1.4.4)
32
+ docile (1.3.2)
33
+ dotenv (2.7.6)
34
+ faraday (1.0.1)
26
35
  multipart-post (>= 1.2, < 3)
27
- git (1.5.0)
28
- gitlab (4.10.0)
36
+ git (1.7.0)
37
+ rchardet (~> 1.8)
38
+ gitlab (4.16.1)
29
39
  httparty (~> 0.14, >= 0.14.0)
30
40
  terminal-table (~> 1.5, >= 1.5.1)
31
41
  gitlab_awesome_release (1.0.2)
32
42
  dotenv
33
43
  gitlab (>= 4.0.0)
34
44
  thor
35
- hashdiff (0.3.8)
36
- httparty (0.16.4)
45
+ hashdiff (1.0.1)
46
+ httparty (0.18.1)
37
47
  mime-types (~> 3.0)
38
48
  multi_xml (>= 0.5.2)
39
49
  httpclient (2.8.3)
40
- json (2.2.0)
41
- method_source (0.9.2)
42
- mime-types (3.2.2)
50
+ method_source (1.0.0)
51
+ mime-types (3.3.1)
43
52
  mime-types-data (~> 3.2015)
44
- mime-types-data (3.2018.0812)
53
+ mime-types-data (3.2020.0512)
45
54
  multi_xml (0.6.0)
46
- multipart-post (2.0.0)
47
- octokit (4.13.0)
55
+ multipart-post (2.1.1)
56
+ octokit (4.18.0)
57
+ faraday (>= 0.9)
48
58
  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)
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)
53
66
  byebug (~> 11.0)
54
- pry (~> 0.10)
55
- public_suffix (3.0.3)
56
- rake (10.5.0)
67
+ pry (~> 0.13.0)
68
+ public_suffix (4.0.6)
69
+ rainbow (3.0.0)
70
+ rake (13.0.1)
71
+ rchardet (1.8.0)
72
+ regexp_parser (1.8.0)
57
73
  restore_bundled_with (1.0.0)
58
74
  git
59
75
  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)
76
+ rexml (3.2.4)
77
+ rspec (3.9.0)
78
+ rspec-core (~> 3.9.0)
79
+ rspec-expectations (~> 3.9.0)
80
+ rspec-mocks (~> 3.9.0)
81
+ rspec-core (3.9.2)
82
+ rspec-support (~> 3.9.3)
83
+ rspec-expectations (3.9.2)
67
84
  diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.8.0)
69
- rspec-mocks (3.8.0)
85
+ rspec-support (~> 3.9.0)
86
+ rspec-its (1.3.0)
87
+ rspec-core (>= 3.0.0)
88
+ rspec-expectations (>= 3.0.0)
89
+ rspec-mocks (3.9.1)
70
90
  diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.8.0)
72
- rspec-support (3.8.0)
91
+ rspec-support (~> 3.9.0)
92
+ rspec-support (3.9.3)
73
93
  rspec-temp_dir (1.1.0)
74
94
  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)
95
+ rubocop (0.92.0)
96
+ parallel (~> 1.10)
97
+ parser (>= 2.7.1.5)
98
+ rainbow (>= 2.2.2, < 4.0)
99
+ regexp_parser (>= 1.7)
100
+ rexml
101
+ rubocop-ast (>= 0.5.0)
102
+ ruby-progressbar (~> 1.7)
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)
113
+ ruby-progressbar (1.10.1)
114
+ sawyer (0.8.2)
115
+ addressable (>= 2.3.5)
116
+ faraday (> 0.8, < 2.0)
117
+ simplecov (0.19.0)
80
118
  docile (~> 1.1)
81
- json (>= 1.8, < 3)
82
- simplecov-html (~> 0.10.0)
83
- simplecov-html (0.10.2)
119
+ simplecov-html (~> 0.11)
120
+ simplecov-html (0.12.3)
84
121
  terminal-table (1.8.0)
85
122
  unicode-display_width (~> 1.1, >= 1.1.1)
86
- thor (0.20.3)
87
- unicode-display_width (1.4.1)
88
- webmock (3.5.1)
123
+ thor (1.0.1)
124
+ unicode-display_width (1.7.0)
125
+ webmock (3.9.1)
89
126
  addressable (>= 2.3.6)
90
127
  crack (>= 0.3.2)
91
- hashdiff
92
- yard (0.9.18)
128
+ hashdiff (>= 0.4.0, < 2.0.0)
129
+ yard (0.9.25)
93
130
 
94
131
  PLATFORMS
95
132
  ruby
@@ -100,11 +137,19 @@ DEPENDENCIES
100
137
  gitlab_awesome_release
101
138
  gitlabci-bundle-update-mr!
102
139
  octokit (>= 4.13.0)
140
+ onkcop!
103
141
  pry-byebug
104
- rake (~> 10.0)
142
+ rake (>= 10.0)
105
143
  rspec (~> 3.0)
144
+ rspec-its
106
145
  rspec-temp_dir
146
+ rubocop (>= 0.68.0)
147
+ rubocop-performance
148
+ rubocop_auto_corrector
107
149
  sawyer (>= 0.8.1)
108
150
  simplecov
109
151
  webmock
110
152
  yard
153
+
154
+ BUNDLED WITH
155
+ 2.1.2
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
 
@@ -44,6 +46,7 @@ The application on which you want to run continuous bundle update must be config
44
46
  ![gitlab_environment_variables](img/gitlab_environment_variables.png)
45
47
 
46
48
  ## Usage
49
+ ### Step 1-A. Plain
47
50
  Configure your `.gitlab-ci.yml` to run `gitlabci-bundle-update-mr`, for example:
48
51
 
49
52
  ```yml
@@ -61,13 +64,12 @@ continuous_bundle_update:
61
64
  - vendor/bundle/
62
65
 
63
66
  before_script:
64
- - bundle install --path vendor/bundle
65
- - bundle clean
66
-
67
67
  # Set timezone to Asia/Tokyo
68
68
  - cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
69
69
 
70
70
  script:
71
+ - bundle install --path vendor/bundle
72
+ - bundle clean
71
73
  - gem install --no-doc gitlabci-bundle-update-mr
72
74
  - gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com" --labels="bundle update"
73
75
 
@@ -75,6 +77,39 @@ continuous_bundle_update:
75
77
  - schedules
76
78
  ```
77
79
 
80
+ ### Step 1-B. Using `include`
81
+ `include` is available in one of the following versions.
82
+
83
+ * GitLab Core 11.4+
84
+ * GitLab Premium 10.5+
85
+ * Starter, Premium and Ultimate 10.6+
86
+
87
+ c.f. https://docs.gitlab.com/ce/ci/yaml/README.html#include
88
+
89
+ example
90
+
91
+ ```yml
92
+ include:
93
+ - remote: "https://gitlab.com/sue445/gitlabci-bundle-update-mr/raw/master/gitlabci-templates/continuous_bundle_update.yml"
94
+
95
+ continuous_bundle_update:
96
+ stage: build
97
+
98
+ variables:
99
+ # override variables (followings are defaults)
100
+ CACHE_VERSION: "v1"
101
+ GIT_EMAIL: "gitlabci@example.com"
102
+ GIT_USER: "GitLab CI"
103
+ LABELS: "bundle update"
104
+ ASSIGNEES: "foo, bar, baz"
105
+ OPTIONS: ""
106
+
107
+ before_script:
108
+ # Set timezone to Asia/Tokyo
109
+ - cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
110
+ ```
111
+
112
+ ### Step 2. Register scheduler
78
113
  And register scheduler to `https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/pipeline_schedules`
79
114
 
80
115
  ![gitlab_scheduler](img/gitlab_scheduler.png)
@@ -88,6 +123,34 @@ Usage: gitlabci-bundle-update-mr [options]
88
123
  -d, --duplicate Make MR even if it has already existed (default. false)
89
124
  -l, --labels 'In Review, Update' Add labels to the MR
90
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
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]')
91
154
  ```
92
155
 
93
156
  ## Development
@@ -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,28 +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)/}) }
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
- spec.files.reject! { |file| file =~ %r{img/} }
34
32
 
35
33
  spec.bindir = "exe"
36
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
37
35
  spec.require_paths = ["lib"]
38
36
 
39
- spec.required_ruby_version = ">= 2.3.0"
37
+ spec.required_ruby_version = ">= 2.5.0"
40
38
 
41
39
  spec.add_dependency "bundler"
42
40
  spec.add_dependency "compare_linker", ">= 1.4.3"
43
- spec.add_dependency "gitlab", ">= 4.0.0"
41
+ spec.add_dependency "gitlab", ">= 4.14.1"
44
42
  spec.add_dependency "restore_bundled_with"
45
43
 
46
44
  spec.add_development_dependency "dotenv"
47
45
  spec.add_development_dependency "gitlab_awesome_release"
46
+ spec.add_development_dependency "onkcop"
48
47
  spec.add_development_dependency "pry-byebug"
49
- spec.add_development_dependency "rake", "~> 10.0"
48
+ spec.add_development_dependency "rake", ">= 10.0"
50
49
  spec.add_development_dependency "rspec", "~> 3.0"
50
+ spec.add_development_dependency "rspec-its"
51
51
  spec.add_development_dependency "rspec-temp_dir"
52
+ spec.add_development_dependency "rubocop_auto_corrector"
53
+ spec.add_development_dependency "rubocop-performance"
52
54
  spec.add_development_dependency "simplecov"
53
55
  spec.add_development_dependency "webmock"
54
56
  spec.add_development_dependency "yard"
@@ -0,0 +1,27 @@
1
+ continuous_bundle_update:
2
+ image: ruby
3
+
4
+ variables:
5
+ CACHE_VERSION: "v1"
6
+ GIT_EMAIL: "gitlabci@example.com"
7
+ GIT_USER: "GitLab CI"
8
+ LABELS: "bundle update"
9
+ ASSIGNEES: ""
10
+ OPTIONS: ""
11
+
12
+ cache:
13
+ key: "$CACHE_VERSION-$CI_BUILD_NAME"
14
+ paths:
15
+ - vendor/bundle/
16
+
17
+ script:
18
+ - bundle install --path vendor/bundle --clean
19
+ - gem install --no-doc gitlabci-bundle-update-mr
20
+ - |
21
+ if [ -n "$ASSIGNEES" ]; then
22
+ OPTIONS="--assignees $ASSIGNEES $OPTIONS"
23
+ fi
24
+ - gitlabci-bundle-update-mr --user="$GIT_USER" --email="$GIT_EMAIL" --labels="$LABELS" $OPTIONS
25
+
26
+ only:
27
+ - schedules
@@ -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,11 @@ 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
+
9
+ # rubocop:disable Metrics/ParameterLists
8
10
 
9
11
  # @param gitlab_api_endpoint [String]
10
12
  # @param gitlab_api_private_token [String]
@@ -20,16 +22,20 @@ module Gitlabci
20
22
  @author_email = author_email
21
23
  @author_name = author_name
22
24
  end
25
+ # rubocop:enable Metrics/ParameterLists
23
26
 
24
27
  # @param allow_dup_mr [Boolean]
25
28
  # @param mr_labels [Array<String>]
26
29
  # @param update_bundled_with [Boolean]
27
- def perform(allow_dup_mr:, mr_labels:, update_bundled_with:)
30
+ # @param merge_when_pipeline_succeeds [Boolean]
31
+ # @param assignees [Array<String>]
32
+ def perform(allow_dup_mr:, mr_labels:, update_bundled_with:, merge_when_pipeline_succeeds:, assignees:)
28
33
  if !allow_dup_mr && exists_bundle_update_mr?
29
34
  puts "Skip because it has already existed."
30
35
  return
31
36
  end
32
37
 
38
+ assignee_ids = get_assignee_ids(assignees)
33
39
  old_lockfile = File.read(lockfile_name)
34
40
 
35
41
  system!("bundle update")
@@ -47,8 +53,13 @@ module Gitlabci
47
53
  commit_gemfile_lock(new_lockfile)
48
54
  description = merge_request_description(old_lockfile, new_lockfile)
49
55
 
50
- 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)
51
57
  puts "MR is created: #{mr.web_url}"
58
+
59
+ if merge_when_pipeline_succeeds
60
+ accept_merge_request(mr.iid)
61
+ puts "Set merge_when_pipeline_succeeds to #{mr.web_url}"
62
+ end
52
63
  end
53
64
 
54
65
  # @param lockfile [String]
@@ -59,31 +70,40 @@ module Gitlabci
59
70
  "$ bundle update && bundle update --ruby",
60
71
  [
61
72
  {
62
- action: "update",
73
+ action: "update",
63
74
  file_path: lockfile_name,
64
- content: lockfile,
65
- }
75
+ content: lockfile,
76
+ },
66
77
  ],
67
78
  start_branch: @branch,
68
79
  author_email: @author_email,
69
- author_name: @author_name,
80
+ author_name: @author_name,
70
81
  )
71
82
  end
72
83
 
73
84
  # @param description [String]
74
85
  # @param mr_labels [Array<String>]
75
- 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:)
76
90
  params = {
77
- source_branch: new_branch,
78
- target_branch: @branch,
91
+ source_branch: new_branch,
92
+ target_branch: @branch,
79
93
  remove_source_branch: true,
80
- description: description
94
+ description: description,
81
95
  }
82
96
 
83
97
  unless mr_labels.empty?
84
98
  params[:labels] = mr_labels.join(",")
85
99
  end
86
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
+
87
107
  @gitlab.create_merge_request(
88
108
  @project_name,
89
109
  "#{TITLE_PREFIX}#{current_time.strftime("%Y-%m-%d %H:%M:%S %Z")}",
@@ -99,8 +119,8 @@ module Gitlabci
99
119
  compare_linker = CompareLinker.new("dummy", "dummy")
100
120
  compare_linker.formatter = CompareLinker::Formatter::Markdown.new
101
121
  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")
122
+ make_compare_links_from_lockfiles(Bundler::LockfileParser.new(old_lockfile), Bundler::LockfileParser.new(new_lockfile)).
123
+ to_a.join("\n")
104
124
 
105
125
  <<~MARKDOWN
106
126
  **Updated RubyGems:**
@@ -111,52 +131,90 @@ module Gitlabci
111
131
  MARKDOWN
112
132
  end
113
133
 
114
- private
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)
115
153
 
116
- def system!(command)
117
- # NOTE: system(exception: true) requires Ruby 2.6+
118
- ret = system(command)
119
- raise "`#{command}` is failed" unless ret
154
+ unless user
155
+ raise NotFoundUserError, "#{username} isn't found"
156
+ end
157
+
158
+ user
120
159
  end
121
160
 
122
- def restore_bundled_with
123
- RestoreBundledWith::CLI.new.invoke(
124
- :restore,
125
- [],
126
- {
127
- lockfile: lockfile_name,
128
- },
161
+ private
162
+
163
+ def system!(command)
164
+ # NOTE: system(exception: true) requires Ruby 2.6+
165
+ ret = system(command)
166
+ raise "`#{command}` is failed" unless ret
167
+ end
168
+
169
+ def restore_bundled_with
170
+ RestoreBundledWith::CLI.new.invoke(
171
+ :restore,
172
+ [],
173
+ {
174
+ lockfile: lockfile_name,
175
+ },
129
176
  )
130
- end
177
+ end
131
178
 
132
- def gemfile_name
133
- return @gemfile_name if @gemfile_name
179
+ def gemfile_name
180
+ return @gemfile_name if @gemfile_name
134
181
 
135
- @gemfile_name = ENV["BUNDLE_GEMFILE"] || "Gemfile"
182
+ @gemfile_name = ENV["BUNDLE_GEMFILE"] || "Gemfile"
136
183
 
137
- if @gemfile_name.start_with?("#{Dir.pwd}/")
138
- @gemfile_name = @gemfile_name.gsub("#{Dir.pwd}/", "")
184
+ if @gemfile_name.start_with?("#{Dir.pwd}/")
185
+ @gemfile_name = @gemfile_name.gsub("#{Dir.pwd}/", "")
186
+ end
187
+
188
+ @gemfile_name
139
189
  end
140
190
 
141
- @gemfile_name
142
- end
191
+ def lockfile_name
192
+ "#{gemfile_name}.lock"
193
+ end
143
194
 
144
- def lockfile_name
145
- "#{gemfile_name}.lock"
146
- end
195
+ def current_time
196
+ @current_time ||= Time.now
197
+ end
147
198
 
148
- def current_time
149
- @current_time ||= Time.now
150
- end
199
+ def new_branch
200
+ "#{BRANCH_PREFIX}#{current_time.strftime("%Y%m%d%H%M%S")}"
201
+ end
151
202
 
152
- def new_branch
153
- "#{BRANCH_PREFIX}#{current_time.strftime("%Y%m%d%H%M%S")}"
154
- end
203
+ def exists_bundle_update_mr?
204
+ merge_requests = @gitlab.merge_requests(@project_name, state: "opened", target_branch: @branch, search: TITLE_PREFIX.strip)
205
+ merge_requests.any? {|mr| mr.title.start_with?(TITLE_PREFIX) && mr.source_branch.start_with?(BRANCH_PREFIX) }
206
+ end
155
207
 
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
208
+ def accept_merge_request(mr_id)
209
+ @gitlab.accept_merge_request(@project_name, mr_id, merge_when_pipeline_succeeds: true, should_remove_source_branch: true)
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
160
218
  end
161
219
  end
162
220
  end
@@ -2,7 +2,7 @@ module Gitlabci
2
2
  module Bundle
3
3
  module Update
4
4
  module Mr
5
- VERSION = "0.2.0"
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: 0.2.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: 2019-03-06 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
@@ -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
@@ -216,6 +273,7 @@ files:
216
273
  - bin/setup
217
274
  - exe/gitlabci-bundle-update-mr
218
275
  - gitlabci-bundle-update-mr.gemspec
276
+ - gitlabci-templates/continuous_bundle_update.yml
219
277
  - lib/gitlabci/bundle/update/mr.rb
220
278
  - lib/gitlabci/bundle/update/mr/client.rb
221
279
  - lib/gitlabci/bundle/update/mr/version.rb
@@ -234,14 +292,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
292
  requirements:
235
293
  - - ">="
236
294
  - !ruby/object:Gem::Version
237
- version: 2.3.0
295
+ version: 2.5.0
238
296
  required_rubygems_version: !ruby/object:Gem::Requirement
239
297
  requirements:
240
298
  - - ">="
241
299
  - !ruby/object:Gem::Version
242
300
  version: '0'
243
301
  requirements: []
244
- rubygems_version: 3.0.1
302
+ rubygems_version: 3.1.2
245
303
  signing_key:
246
304
  specification_version: 4
247
305
  summary: Create MergeRequest of bundle update in GitLab CI