gitlabci-bundle-update-mr 0.1.0 → 0.1.1

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: 8e90b7314c57a24908145a4208f5ebbd6f52c747147a5f5992b0aa0e0fa39a41
4
- data.tar.gz: c2b804789f4290b40e7f08764d2c6135326eae908fcc54a4d85fd4e9d61c955d
3
+ metadata.gz: a13cdd08c861aabacc9b6b6f4a4776800b88fba42e6fd9725c9f261684be55ef
4
+ data.tar.gz: 2db4957efe87e12d4e7e7e71619e474821e2e6de61986d51c876c4a749955932
5
5
  SHA512:
6
- metadata.gz: d809b816ae17336303434c881946ed4b702e3bbe48a4f2a9a2a24e4ea7fedf7c296db4ca27d1f14563bc2695e91a55b17ffcc10685f161820a82195c69ba97f5
7
- data.tar.gz: 72742581d2fc375363c1e357449170d1898aa76cafb1910c762aae7db13f035ddeec466d685e393699c092d0a78294b7f81e5f2e48caa911cb94f56cf0af2e40
6
+ metadata.gz: 73b22faf854e49fd0a66eb5f2bcbc77218c0447f916474fe1376592bea708c50d34bdfa0e31a95fce8c4fbf5e920793551270f87dda5d0e1c977ff1737aad536
7
+ data.tar.gz: 788ba9a965cb5a228233265250744a827886e9a1f74481499dc8c4d4972d6dbd00dbb31147a66a8d33fd0ee7bc1172cd46a04d1184825eae8b3d6adf97e35444
data/.env.gitlab ADDED
@@ -0,0 +1,2 @@
1
+ GITLAB_API_ENDPOINT=https://gitlab.com/api/v4
2
+ GITLAB_PROJECT_NAME=sue445/gitlabci-bundle-update-mr
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  .rspec_status
12
12
 
13
13
  .env
14
+ public/
data/.gitlab-ci.yml CHANGED
@@ -1,9 +1,8 @@
1
1
  stages:
2
2
  - build
3
+ - deploy
3
4
 
4
- .test: &test
5
- stage: build
6
-
5
+ .default: &default
7
6
  cache:
8
7
  key: "$CI_BUILD_NAME"
9
8
  paths:
@@ -13,44 +12,44 @@ stages:
13
12
  - bundle install --path vendor/bundle
14
13
  - bundle clean
15
14
 
16
- script:
17
- - bundle exec rspec
18
- - bundle exec ./exe/gitlabci-bundle-update-mr --help
19
-
20
15
  except:
21
16
  - schedules
22
17
  - web
18
+ - tags
19
+
20
+ .test: &test
21
+ <<: *default
22
+
23
+ stage: build
24
+
25
+ script:
26
+ - bundle exec rspec
27
+ - bundle exec ./exe/gitlabci-bundle-update-mr --help
23
28
 
24
29
  test:2.3:
25
30
  <<: *test
26
31
 
27
- image: rubylang/ruby:2.3-bionic
32
+ image: ruby:2.3
28
33
 
29
34
  test:2.4:
30
35
  <<: *test
31
36
 
32
- image: rubylang/ruby:2.4-bionic
37
+ image: ruby:2.4
33
38
 
34
39
  test:2.5:
35
40
  <<: *test
36
41
 
37
- image: rubylang/ruby:2.5-bionic
42
+ image: ruby:2.5
38
43
 
39
44
  test:2.6:
40
45
  <<: *test
41
46
 
42
- image: rubylang/ruby:2.6-bionic
43
-
44
- test:trunk:
45
- <<: *test
46
-
47
- image: rubylang/ruby:trunk-nightly-bionic
48
- allow_failure: true
47
+ image: ruby:2.6
49
48
 
50
49
  continuous_bundle_update:
51
50
  stage: build
52
51
 
53
- image: rubylang/ruby:2.6-bionic
52
+ image: ruby
54
53
 
55
54
  before_script:
56
55
  # Set timezone to Asia/Tokyo
@@ -58,8 +57,23 @@ continuous_bundle_update:
58
57
 
59
58
  script:
60
59
  - gem install --no-doc gitlabci-bundle-update-mr
61
- - gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com"
60
+ - gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com" --labels="bundle update"
62
61
 
63
62
  only:
64
63
  - schedules
65
64
  - web
65
+
66
+ pages:
67
+ <<: *default
68
+
69
+ stage: deploy
70
+
71
+ image: ruby
72
+
73
+ script:
74
+ - bundle exec yard
75
+ artifacts:
76
+ paths:
77
+ - public
78
+ only:
79
+ - master
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ --no-private
3
+ --output-dir public
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  ## Unreleased
2
- [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.1.0...HEAD)
2
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.1.1...HEAD)
3
+
4
+ ## v0.1.1
5
+ [full changelog](https://gitlab.com/sue445/gitlabci-bundle-update-mr/compare/v0.1.0...v0.1.1)
6
+
7
+ ### Refactorings
8
+ * Print MR url after created [!20](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/20) *@sue445*
9
+ * Search only bundle update MR [!21](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/21) *@sue445*
10
+
11
+ ### Others
12
+ * Fixed unstable bundle update [!16](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/16) *@sue445*
13
+ * Setup simplecov [!17](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/17) *@sue445*
14
+ * Setup yard [!18](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/18) *@sue445*
15
+ * Rewrite spec [!19](https://gitlab.com/sue445/gitlabci-bundle-update-mr/merge_requests/19) *@sue445*
3
16
 
4
17
  ## v0.1.0
5
18
  * first release
19
+
20
+ *This Change Log was automatically generated by [gitlab_awesome_release](https://gitlab.com/sue445/gitlab_awesome_release)*
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in gitlabci-bundle-update-mr.gemspec
4
4
  gemspec
5
+
6
+ # FIXME: following gems are often downgraded when `bundle update`
7
+ gem "faraday", ">= 0.15.4"
8
+ gem "octokit", ">= 4.13.0"
9
+ gem "sawyer", ">= 0.8.1"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlabci-bundle-update-mr (0.1.0)
4
+ gitlabci-bundle-update-mr (0.1.1)
5
5
  bundler
6
6
  compare_linker (>= 1.4.3)
7
7
  gitlab (>= 4.0.0)
@@ -19,6 +19,7 @@ GEM
19
19
  crack (0.4.3)
20
20
  safe_yaml (~> 1.0.0)
21
21
  diff-lcs (1.3)
22
+ docile (1.3.1)
22
23
  dotenv (2.7.1)
23
24
  faraday (0.15.4)
24
25
  multipart-post (>= 1.2, < 3)
@@ -34,6 +35,7 @@ GEM
34
35
  mime-types (~> 3.0)
35
36
  multi_xml (>= 0.5.2)
36
37
  httpclient (2.8.3)
38
+ json (2.2.0)
37
39
  method_source (0.9.2)
38
40
  mime-types (3.2.2)
39
41
  mime-types-data (~> 3.2015)
@@ -69,6 +71,11 @@ GEM
69
71
  sawyer (0.8.1)
70
72
  addressable (>= 2.3.5, < 2.6)
71
73
  faraday (~> 0.8, < 1.0)
74
+ simplecov (0.16.1)
75
+ docile (~> 1.1)
76
+ json (>= 1.8, < 3)
77
+ simplecov-html (~> 0.10.0)
78
+ simplecov-html (0.10.2)
72
79
  terminal-table (1.8.0)
73
80
  unicode-display_width (~> 1.1, >= 1.1.1)
74
81
  thor (0.20.3)
@@ -77,19 +84,25 @@ GEM
77
84
  addressable (>= 2.3.6)
78
85
  crack (>= 0.3.2)
79
86
  hashdiff
87
+ yard (0.9.18)
80
88
 
81
89
  PLATFORMS
82
90
  ruby
83
91
 
84
92
  DEPENDENCIES
85
93
  dotenv
94
+ faraday (>= 0.15.4)
86
95
  gitlab_awesome_release
87
96
  gitlabci-bundle-update-mr!
97
+ octokit (>= 4.13.0)
88
98
  pry-byebug
89
99
  rake (~> 10.0)
90
100
  rspec (~> 3.0)
91
101
  rspec-temp_dir
102
+ sawyer (>= 0.8.1)
103
+ simplecov
92
104
  webmock
105
+ yard
93
106
 
94
107
  BUNDLED WITH
95
108
  1.17.3
data/README.md CHANGED
@@ -3,6 +3,8 @@ Create MergeRequest of bundle update in GitLab CI
3
3
 
4
4
  This is inspired by [circleci-bundle-update-pr](https://github.com/masutaka/circleci-bundle-update-pr)
5
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/gitlabci-bundle-update-mr.svg)](https://badge.fury.io/rb/gitlabci-bundle-update-mr)
7
+
6
8
  ## Installation
7
9
  ```bash
8
10
  gem install gitlabci-bundle-update-mr
@@ -54,7 +56,7 @@ continuous_bundle_update:
54
56
 
55
57
  script:
56
58
  - gem install --no-doc gitlabci-bundle-update-mr
57
- - gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com"
59
+ - gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com" --labels="bundle update"
58
60
 
59
61
  only:
60
62
  - schedules
@@ -65,6 +67,16 @@ And register scheduler to `https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/pipeline_sche
65
67
 
66
68
  ![gitlab_scheduler](img/gitlab_scheduler.png)
67
69
 
70
+ ## CLI command references
71
+ ```bash
72
+ $ gitlabci-bundle-update-mr --help
73
+ Usage: gitlabci-bundle-update-mr [options]
74
+ --email EMAIL git email address (default. `git config user.email`)
75
+ --user USER git username (default. `git config user.name`)
76
+ -d, --duplicate Make MR even if it has already existed
77
+ -l, --labels 'In Review, Update' Add labels to the MR
78
+ ```
79
+
68
80
  ## Development
69
81
 
70
82
  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.
data/bin/console CHANGED
@@ -12,7 +12,16 @@ Dotenv.load
12
12
  author_email = `git config user.email`.strip
13
13
  author_name = `git config user.name`.strip
14
14
 
15
- @client = Gitlabci::Bundle::Update::Mr::Client.new(author_email: author_email, author_name: author_name)
15
+ Gitlabci::Bundle::Update::Mr.assert_env_keys
16
+
17
+ @client = Gitlabci::Bundle::Update::Mr::Client.new(
18
+ gitlab_api_endpoint: ENV["GITLAB_API_ENDPOINT"],
19
+ gitlab_api_private_token: ENV["GITLAB_API_PRIVATE_TOKEN"],
20
+ project_name: ENV["CI_PROJECT_PATH"],
21
+ branch: ENV["CI_COMMIT_REF_NAME"],
22
+ author_email: author_email,
23
+ author_name: author_name,
24
+ )
16
25
 
17
26
  require "pry"
18
27
  Pry.start
@@ -17,5 +17,15 @@ opt.on("-l", "--labels 'In Review, Update'", Array, "Add labels to the MR") { |v
17
17
 
18
18
  opt.parse!(ARGV)
19
19
 
20
- client = Gitlabci::Bundle::Update::Mr::Client.new(author_email: author_email, author_name: author_name)
20
+ Gitlabci::Bundle::Update::Mr.assert_env_keys
21
+
22
+ client = Gitlabci::Bundle::Update::Mr::Client.new(
23
+ gitlab_api_endpoint: ENV["GITLAB_API_ENDPOINT"],
24
+ gitlab_api_private_token: ENV["GITLAB_API_PRIVATE_TOKEN"],
25
+ project_name: ENV["CI_PROJECT_PATH"],
26
+ branch: ENV["CI_COMMIT_REF_NAME"],
27
+ author_email: author_email,
28
+ author_name: author_name,
29
+ )
30
+
21
31
  client.perform(allow_dup_mr: allow_dup_mr, mr_labels: mr_labels)
@@ -48,5 +48,7 @@ Gem::Specification.new do |spec|
48
48
  spec.add_development_dependency "rake", "~> 10.0"
49
49
  spec.add_development_dependency "rspec", "~> 3.0"
50
50
  spec.add_development_dependency "rspec-temp_dir"
51
+ spec.add_development_dependency "simplecov"
51
52
  spec.add_development_dependency "webmock"
53
+ spec.add_development_dependency "yard"
52
54
  end
@@ -11,6 +11,23 @@ module Gitlabci
11
11
  class Error < StandardError; end
12
12
 
13
13
  class MissingKeyError < Error; end
14
+
15
+ def self.assert_env_keys
16
+ %w(
17
+ OCTOKIT_ACCESS_TOKEN
18
+ GITLAB_API_ENDPOINT
19
+ GITLAB_API_PRIVATE_TOKEN
20
+ CI_PROJECT_PATH
21
+ CI_COMMIT_REF_NAME
22
+ ).each do |key|
23
+ assert_env_key(key)
24
+ end
25
+ end
26
+
27
+ def self.assert_env_key(key)
28
+ raise MissingKeyError, "#{key} is required" if !ENV[key] || ENV[key].empty?
29
+ end
30
+ private_class_method :assert_env_key
14
31
  end
15
32
  end
16
33
  end
@@ -6,14 +6,17 @@ module Gitlabci
6
6
  BRANCH_PREFIX = "bundle-update-"
7
7
  TITLE_PREFIX = "bundle update at "
8
8
 
9
- # @param check_env_keys [Boolean] Check whether env is correct
9
+ # @param gitlab_api_endpoint [String]
10
+ # @param gitlab_api_private_token [String]
11
+ # @param project_name [String]
12
+ # @param branch [String]
10
13
  # @param author_email [String]
11
14
  # @param author_name [String]
12
- def initialize(check_env_keys: true, author_email:, author_name:)
13
- assert_env_keys if check_env_keys
14
-
15
- @project_name = ENV["CI_PROJECT_PATH"]
16
- @branch = ENV["CI_COMMIT_REF_NAME"]
15
+ def initialize(gitlab_api_endpoint:, gitlab_api_private_token:,
16
+ project_name:, branch:, author_email:, author_name:)
17
+ @gitlab = Gitlab.client(endpoint: gitlab_api_endpoint, private_token: gitlab_api_private_token)
18
+ @project_name = project_name
19
+ @branch = branch
17
20
  @author_email = author_email
18
21
  @author_name = author_name
19
22
  end
@@ -40,12 +43,14 @@ module Gitlabci
40
43
 
41
44
  commit_gemfile_lock(new_lockfile)
42
45
  description = merge_request_description(old_lockfile, new_lockfile)
43
- create_merge_request(description: description, mr_labels: mr_labels)
46
+
47
+ mr = create_merge_request(description: description, mr_labels: mr_labels)
48
+ puts "MR is created: #{mr.web_url}"
44
49
  end
45
50
 
46
51
  # @param lockfile [String]
47
52
  def commit_gemfile_lock(lockfile)
48
- gitlab.create_commit(
53
+ @gitlab.create_commit(
49
54
  @project_name,
50
55
  new_branch,
51
56
  "$ bundle update && bundle update --ruby",
@@ -76,7 +81,7 @@ module Gitlabci
76
81
  params[:labels] = mr_labels.join(",")
77
82
  end
78
83
 
79
- gitlab.create_merge_request(
84
+ @gitlab.create_merge_request(
80
85
  @project_name,
81
86
  "#{TITLE_PREFIX}#{current_time.strftime("%Y-%m-%d %H:%M:%S %Z")}",
82
87
  params,
@@ -103,26 +108,10 @@ module Gitlabci
103
108
 
104
109
  private
105
110
 
106
- def assert_env_keys
107
- %w(
108
- OCTOKIT_ACCESS_TOKEN
109
- GITLAB_API_ENDPOINT
110
- GITLAB_API_PRIVATE_TOKEN
111
- CI_PROJECT_PATH
112
- CI_COMMIT_REF_NAME
113
- ).each do |key|
114
- assert_env_key(key)
115
- end
116
- end
117
-
118
- def assert_env_key(key)
119
- raise MissingKeyError, "#{key} is required" if !ENV[key] || ENV[key].empty?
120
- end
121
-
122
111
  def system!(command)
123
112
  # NOTE: system(exception: true) requires Ruby 2.6+
124
113
  ret = system(command)
125
- raise unless ret
114
+ raise "`#{command}` is failed" unless ret
126
115
  end
127
116
 
128
117
  def gemfile_name
@@ -141,10 +130,6 @@ module Gitlabci
141
130
  "#{gemfile_name}.lock"
142
131
  end
143
132
 
144
- def gitlab
145
- @gitlab ||= Gitlab.client(endpoint: ENV["GITLAB_API_ENDPOINT"], private_token: ENV["GITLAB_API_PRIVATE_TOKEN"])
146
- end
147
-
148
133
  def current_time
149
134
  @current_time ||= Time.now
150
135
  end
@@ -154,7 +139,7 @@ module Gitlabci
154
139
  end
155
140
 
156
141
  def exists_bundle_update_mr?
157
- merge_requests = gitlab.merge_requests(@project_name, state: "opened", target_branch: @branch)
142
+ merge_requests = @gitlab.merge_requests(@project_name, state: "opened", target_branch: @branch, search: TITLE_PREFIX.strip)
158
143
  merge_requests.any? { |mr| mr.title.start_with?(TITLE_PREFIX) && mr.source_branch.start_with?(BRANCH_PREFIX) }
159
144
  end
160
145
  end
@@ -2,7 +2,7 @@ module Gitlabci
2
2
  module Bundle
3
3
  module Update
4
4
  module Mr
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
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.1.0
4
+ version: 0.1.1
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-03 00:00:00.000000000 Z
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: webmock
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  description: Create MergeRequest of bundle update in GitLab CI
154
182
  email:
155
183
  - sue445@sue445.net
@@ -159,9 +187,11 @@ extensions: []
159
187
  extra_rdoc_files: []
160
188
  files:
161
189
  - ".env.example"
190
+ - ".env.gitlab"
162
191
  - ".gitignore"
163
192
  - ".gitlab-ci.yml"
164
193
  - ".rspec"
194
+ - ".yardopts"
165
195
  - CHANGELOG.md
166
196
  - Gemfile
167
197
  - Gemfile.lock