gitlabci-bundle-update-mr 0.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 +7 -0
- data/.env.example +5 -0
- data/.gitignore +13 -0
- data/.gitlab-ci.yml +65 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +95 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/bin/console +18 -0
- data/bin/setup +11 -0
- data/exe/gitlabci-bundle-update-mr +21 -0
- data/gitlabci-bundle-update-mr.gemspec +52 -0
- data/lib/gitlabci/bundle/update/mr/client.rb +164 -0
- data/lib/gitlabci/bundle/update/mr/version.rb +9 -0
- data/lib/gitlabci/bundle/update/mr.rb +17 -0
- metadata +204 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8e90b7314c57a24908145a4208f5ebbd6f52c747147a5f5992b0aa0e0fa39a41
|
|
4
|
+
data.tar.gz: c2b804789f4290b40e7f08764d2c6135326eae908fcc54a4d85fd4e9d61c955d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d809b816ae17336303434c881946ed4b702e3bbe48a4f2a9a2a24e4ea7fedf7c296db4ca27d1f14563bc2695e91a55b17ffcc10685f161820a82195c69ba97f5
|
|
7
|
+
data.tar.gz: 72742581d2fc375363c1e357449170d1898aa76cafb1910c762aae7db13f035ddeec466d685e393699c092d0a78294b7f81e5f2e48caa911cb94f56cf0af2e40
|
data/.env.example
ADDED
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
stages:
|
|
2
|
+
- build
|
|
3
|
+
|
|
4
|
+
.test: &test
|
|
5
|
+
stage: build
|
|
6
|
+
|
|
7
|
+
cache:
|
|
8
|
+
key: "$CI_BUILD_NAME"
|
|
9
|
+
paths:
|
|
10
|
+
- vendor/bundle/
|
|
11
|
+
|
|
12
|
+
before_script:
|
|
13
|
+
- bundle install --path vendor/bundle
|
|
14
|
+
- bundle clean
|
|
15
|
+
|
|
16
|
+
script:
|
|
17
|
+
- bundle exec rspec
|
|
18
|
+
- bundle exec ./exe/gitlabci-bundle-update-mr --help
|
|
19
|
+
|
|
20
|
+
except:
|
|
21
|
+
- schedules
|
|
22
|
+
- web
|
|
23
|
+
|
|
24
|
+
test:2.3:
|
|
25
|
+
<<: *test
|
|
26
|
+
|
|
27
|
+
image: rubylang/ruby:2.3-bionic
|
|
28
|
+
|
|
29
|
+
test:2.4:
|
|
30
|
+
<<: *test
|
|
31
|
+
|
|
32
|
+
image: rubylang/ruby:2.4-bionic
|
|
33
|
+
|
|
34
|
+
test:2.5:
|
|
35
|
+
<<: *test
|
|
36
|
+
|
|
37
|
+
image: rubylang/ruby:2.5-bionic
|
|
38
|
+
|
|
39
|
+
test:2.6:
|
|
40
|
+
<<: *test
|
|
41
|
+
|
|
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
|
|
49
|
+
|
|
50
|
+
continuous_bundle_update:
|
|
51
|
+
stage: build
|
|
52
|
+
|
|
53
|
+
image: rubylang/ruby:2.6-bionic
|
|
54
|
+
|
|
55
|
+
before_script:
|
|
56
|
+
# Set timezone to Asia/Tokyo
|
|
57
|
+
- cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
|
|
58
|
+
|
|
59
|
+
script:
|
|
60
|
+
- gem install --no-doc gitlabci-bundle-update-mr
|
|
61
|
+
- gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com"
|
|
62
|
+
|
|
63
|
+
only:
|
|
64
|
+
- schedules
|
|
65
|
+
- web
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
gitlabci-bundle-update-mr (0.1.0)
|
|
5
|
+
bundler
|
|
6
|
+
compare_linker (>= 1.4.3)
|
|
7
|
+
gitlab (>= 4.0.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
addressable (2.5.2)
|
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
|
14
|
+
byebug (11.0.0)
|
|
15
|
+
coderay (1.1.2)
|
|
16
|
+
compare_linker (1.4.3)
|
|
17
|
+
httpclient
|
|
18
|
+
octokit
|
|
19
|
+
crack (0.4.3)
|
|
20
|
+
safe_yaml (~> 1.0.0)
|
|
21
|
+
diff-lcs (1.3)
|
|
22
|
+
dotenv (2.7.1)
|
|
23
|
+
faraday (0.15.4)
|
|
24
|
+
multipart-post (>= 1.2, < 3)
|
|
25
|
+
gitlab (4.10.0)
|
|
26
|
+
httparty (~> 0.14, >= 0.14.0)
|
|
27
|
+
terminal-table (~> 1.5, >= 1.5.1)
|
|
28
|
+
gitlab_awesome_release (1.0.2)
|
|
29
|
+
dotenv
|
|
30
|
+
gitlab (>= 4.0.0)
|
|
31
|
+
thor
|
|
32
|
+
hashdiff (0.3.8)
|
|
33
|
+
httparty (0.16.4)
|
|
34
|
+
mime-types (~> 3.0)
|
|
35
|
+
multi_xml (>= 0.5.2)
|
|
36
|
+
httpclient (2.8.3)
|
|
37
|
+
method_source (0.9.2)
|
|
38
|
+
mime-types (3.2.2)
|
|
39
|
+
mime-types-data (~> 3.2015)
|
|
40
|
+
mime-types-data (3.2018.0812)
|
|
41
|
+
multi_xml (0.6.0)
|
|
42
|
+
multipart-post (2.0.0)
|
|
43
|
+
octokit (4.13.0)
|
|
44
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
|
45
|
+
pry (0.12.2)
|
|
46
|
+
coderay (~> 1.1.0)
|
|
47
|
+
method_source (~> 0.9.0)
|
|
48
|
+
pry-byebug (3.7.0)
|
|
49
|
+
byebug (~> 11.0)
|
|
50
|
+
pry (~> 0.10)
|
|
51
|
+
public_suffix (3.0.3)
|
|
52
|
+
rake (10.5.0)
|
|
53
|
+
rspec (3.8.0)
|
|
54
|
+
rspec-core (~> 3.8.0)
|
|
55
|
+
rspec-expectations (~> 3.8.0)
|
|
56
|
+
rspec-mocks (~> 3.8.0)
|
|
57
|
+
rspec-core (3.8.0)
|
|
58
|
+
rspec-support (~> 3.8.0)
|
|
59
|
+
rspec-expectations (3.8.2)
|
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
61
|
+
rspec-support (~> 3.8.0)
|
|
62
|
+
rspec-mocks (3.8.0)
|
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
64
|
+
rspec-support (~> 3.8.0)
|
|
65
|
+
rspec-support (3.8.0)
|
|
66
|
+
rspec-temp_dir (1.1.0)
|
|
67
|
+
rspec (>= 3.0)
|
|
68
|
+
safe_yaml (1.0.5)
|
|
69
|
+
sawyer (0.8.1)
|
|
70
|
+
addressable (>= 2.3.5, < 2.6)
|
|
71
|
+
faraday (~> 0.8, < 1.0)
|
|
72
|
+
terminal-table (1.8.0)
|
|
73
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
74
|
+
thor (0.20.3)
|
|
75
|
+
unicode-display_width (1.4.1)
|
|
76
|
+
webmock (3.5.1)
|
|
77
|
+
addressable (>= 2.3.6)
|
|
78
|
+
crack (>= 0.3.2)
|
|
79
|
+
hashdiff
|
|
80
|
+
|
|
81
|
+
PLATFORMS
|
|
82
|
+
ruby
|
|
83
|
+
|
|
84
|
+
DEPENDENCIES
|
|
85
|
+
dotenv
|
|
86
|
+
gitlab_awesome_release
|
|
87
|
+
gitlabci-bundle-update-mr!
|
|
88
|
+
pry-byebug
|
|
89
|
+
rake (~> 10.0)
|
|
90
|
+
rspec (~> 3.0)
|
|
91
|
+
rspec-temp_dir
|
|
92
|
+
webmock
|
|
93
|
+
|
|
94
|
+
BUNDLED WITH
|
|
95
|
+
1.17.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 sue445
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Gitlabci::Bundle::Update::Mr
|
|
2
|
+
Create MergeRequest of bundle update in GitLab CI
|
|
3
|
+
|
|
4
|
+
This is inspired by [circleci-bundle-update-pr](https://github.com/masutaka/circleci-bundle-update-pr)
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
```bash
|
|
8
|
+
gem install gitlabci-bundle-update-mr
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Prerequisites
|
|
12
|
+
The application on which you want to run continuous bundle update must be configured to be built on GitLab CI.
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
### Get GitHub personal access token
|
|
16
|
+
1. Go to [your account's settings page](https://github.com/settings/tokens/new?description=gitlabci-bundle-update-mr%20token)
|
|
17
|
+
2. Generate a personal access token with `repo` scope
|
|
18
|
+
3. Save environment variables as `OCTOKIT_ACCESS_TOKEN` to `https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/settings/ci_cd`
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
### Get GitLab personal access token
|
|
23
|
+
1. Go to `https://YOUR-GITLAB/profile/personal_access_tokens`
|
|
24
|
+
* e.g. https://gitlab.com/profile/personal_access_tokens
|
|
25
|
+
2. Generate a personal access token with `api` scope
|
|
26
|
+
3. Save environment variables as `GITLAB_API_PRIVATE_TOKEN` to `https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/settings/ci_cd`
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
### Save CI environment variables
|
|
31
|
+
1. Go to `https://https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/settings/ci_cd`
|
|
32
|
+
2. Save environment variables
|
|
33
|
+
* `GITLAB_API_ENDPOINT` : GitLab API endpoint (e.g. `https://gitlab.com/api/v4`)
|
|
34
|
+
* `GITLAB_API_PRIVATE_TOKEN` : GitLab personal access token
|
|
35
|
+
* `OCTOKIT_ACCESS_TOKEN` : GitHub personal access token
|
|
36
|
+
|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
Configure your `.gitlab-ci.yml` to run `gitlabci-bundle-update-mr`, for example:
|
|
41
|
+
|
|
42
|
+
```yml
|
|
43
|
+
stages:
|
|
44
|
+
- build
|
|
45
|
+
|
|
46
|
+
continuous_bundle_update:
|
|
47
|
+
stage: build
|
|
48
|
+
|
|
49
|
+
image: rubylang/ruby:2.6-bionic
|
|
50
|
+
|
|
51
|
+
before_script:
|
|
52
|
+
# Set timezone to Asia/Tokyo
|
|
53
|
+
- cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
|
|
54
|
+
|
|
55
|
+
script:
|
|
56
|
+
- gem install --no-doc gitlabci-bundle-update-mr
|
|
57
|
+
- gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com"
|
|
58
|
+
|
|
59
|
+
only:
|
|
60
|
+
- schedules
|
|
61
|
+
- web
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
And register scheduler to `https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/pipeline_schedules`
|
|
65
|
+
|
|
66
|
+

|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
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.
|
|
71
|
+
|
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
73
|
+
|
|
74
|
+
## Contributing
|
|
75
|
+
|
|
76
|
+
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/sue445/gitlabci-bundle-update-mr.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "gitlabci/bundle/update/mr"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
require "dotenv"
|
|
10
|
+
Dotenv.load
|
|
11
|
+
|
|
12
|
+
author_email = `git config user.email`.strip
|
|
13
|
+
author_name = `git config user.name`.strip
|
|
14
|
+
|
|
15
|
+
@client = Gitlabci::Bundle::Update::Mr::Client.new(author_email: author_email, author_name: author_name)
|
|
16
|
+
|
|
17
|
+
require "pry"
|
|
18
|
+
Pry.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "gitlabci/bundle/update/mr"
|
|
4
|
+
require "optparse"
|
|
5
|
+
opt = OptionParser.new
|
|
6
|
+
opt.version = Gitlabci::Bundle::Update::Mr::VERSION
|
|
7
|
+
|
|
8
|
+
author_email = `git config user.email`.strip
|
|
9
|
+
author_name = `git config user.name`.strip
|
|
10
|
+
allow_dup_mr = false
|
|
11
|
+
mr_labels = []
|
|
12
|
+
|
|
13
|
+
opt.on("--email EMAIL", "git email address (default. `git config user.email`)") { |v| author_email = v }
|
|
14
|
+
opt.on("--user USER", "git username (default. `git config user.name`)") { |v| author_name = v }
|
|
15
|
+
opt.on("-d", "--duplicate", "Make MR even if it has already existed") { |v| allow_dup_mr = v }
|
|
16
|
+
opt.on("-l", "--labels 'In Review, Update'", Array, "Add labels to the MR") { |v| mr_labels = v.map(&:strip) }
|
|
17
|
+
|
|
18
|
+
opt.parse!(ARGV)
|
|
19
|
+
|
|
20
|
+
client = Gitlabci::Bundle::Update::Mr::Client.new(author_email: author_email, author_name: author_name)
|
|
21
|
+
client.perform(allow_dup_mr: allow_dup_mr, mr_labels: mr_labels)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "gitlabci/bundle/update/mr/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "gitlabci-bundle-update-mr"
|
|
8
|
+
spec.version = Gitlabci::Bundle::Update::Mr::VERSION
|
|
9
|
+
spec.authors = ["sue445"]
|
|
10
|
+
spec.email = ["sue445@sue445.net"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Create MergeRequest of bundle update in GitLab CI}
|
|
13
|
+
spec.description = %q{Create MergeRequest of bundle update in GitLab CI}
|
|
14
|
+
spec.homepage = "https://gitlab.com/sue445/gitlabci-bundle-update-mr"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
21
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
22
|
+
spec.metadata["changelog_uri"] = "https://gitlab.com/sue445/gitlabci-bundle-update-mr/blob/master/CHANGELOG.md"
|
|
23
|
+
else
|
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
25
|
+
"public gem pushes."
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
|
29
|
+
# 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)/}) }
|
|
32
|
+
end
|
|
33
|
+
spec.files.reject! { |file| file =~ %r{img/} }
|
|
34
|
+
|
|
35
|
+
spec.bindir = "exe"
|
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
37
|
+
spec.require_paths = ["lib"]
|
|
38
|
+
|
|
39
|
+
spec.required_ruby_version = ">= 2.3.0"
|
|
40
|
+
|
|
41
|
+
spec.add_dependency "bundler"
|
|
42
|
+
spec.add_dependency "compare_linker", ">= 1.4.3"
|
|
43
|
+
spec.add_dependency "gitlab", ">= 4.0.0"
|
|
44
|
+
|
|
45
|
+
spec.add_development_dependency "dotenv"
|
|
46
|
+
spec.add_development_dependency "gitlab_awesome_release"
|
|
47
|
+
spec.add_development_dependency "pry-byebug"
|
|
48
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
49
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
50
|
+
spec.add_development_dependency "rspec-temp_dir"
|
|
51
|
+
spec.add_development_dependency "webmock"
|
|
52
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
module Gitlabci
|
|
2
|
+
module Bundle
|
|
3
|
+
module Update
|
|
4
|
+
module Mr
|
|
5
|
+
class Client
|
|
6
|
+
BRANCH_PREFIX = "bundle-update-"
|
|
7
|
+
TITLE_PREFIX = "bundle update at "
|
|
8
|
+
|
|
9
|
+
# @param check_env_keys [Boolean] Check whether env is correct
|
|
10
|
+
# @param author_email [String]
|
|
11
|
+
# @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"]
|
|
17
|
+
@author_email = author_email
|
|
18
|
+
@author_name = author_name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @param allow_dup_mr [Boolean]
|
|
22
|
+
# @param mr_labels [Array<String>]
|
|
23
|
+
def perform(allow_dup_mr:, mr_labels:)
|
|
24
|
+
if !allow_dup_mr && exists_bundle_update_mr?
|
|
25
|
+
puts "Skip because it has already existed."
|
|
26
|
+
return
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
old_lockfile = File.read(lockfile_name)
|
|
30
|
+
|
|
31
|
+
system!("bundle update")
|
|
32
|
+
system!("bundle update --ruby")
|
|
33
|
+
|
|
34
|
+
new_lockfile = File.read(lockfile_name)
|
|
35
|
+
|
|
36
|
+
if old_lockfile == new_lockfile
|
|
37
|
+
puts "#{lockfile_name} is not updated"
|
|
38
|
+
return
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
commit_gemfile_lock(new_lockfile)
|
|
42
|
+
description = merge_request_description(old_lockfile, new_lockfile)
|
|
43
|
+
create_merge_request(description: description, mr_labels: mr_labels)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @param lockfile [String]
|
|
47
|
+
def commit_gemfile_lock(lockfile)
|
|
48
|
+
gitlab.create_commit(
|
|
49
|
+
@project_name,
|
|
50
|
+
new_branch,
|
|
51
|
+
"$ bundle update && bundle update --ruby",
|
|
52
|
+
[
|
|
53
|
+
{
|
|
54
|
+
action: "update",
|
|
55
|
+
file_path: lockfile_name,
|
|
56
|
+
content: lockfile,
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
start_branch: @branch,
|
|
60
|
+
author_email: @author_email,
|
|
61
|
+
author_name: @author_name,
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @param description [String]
|
|
66
|
+
# @param mr_labels [Array<String>]
|
|
67
|
+
def create_merge_request(description:, mr_labels:)
|
|
68
|
+
params = {
|
|
69
|
+
source_branch: new_branch,
|
|
70
|
+
target_branch: @branch,
|
|
71
|
+
remove_source_branch: true,
|
|
72
|
+
description: description
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
unless mr_labels.empty?
|
|
76
|
+
params[:labels] = mr_labels.join(",")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
gitlab.create_merge_request(
|
|
80
|
+
@project_name,
|
|
81
|
+
"#{TITLE_PREFIX}#{current_time.strftime("%Y-%m-%d %H:%M:%S %Z")}",
|
|
82
|
+
params,
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# @param old_lockfile [String]
|
|
87
|
+
# @param new_lockfile [String]
|
|
88
|
+
def merge_request_description(old_lockfile, new_lockfile)
|
|
89
|
+
compare_linker = CompareLinker.new("dummy", "dummy")
|
|
90
|
+
compare_linker.formatter = CompareLinker::Formatter::Markdown.new
|
|
91
|
+
compare_links = compare_linker.
|
|
92
|
+
make_compare_links_from_lockfiles(Bundler::LockfileParser.new(old_lockfile), Bundler::LockfileParser.new(new_lockfile)).
|
|
93
|
+
to_a.join("\n")
|
|
94
|
+
|
|
95
|
+
<<~MARKDOWN
|
|
96
|
+
**Updated RubyGems:**
|
|
97
|
+
|
|
98
|
+
#{compare_links}
|
|
99
|
+
|
|
100
|
+
Powered by [gitlabci-bundle-update-mr](https://rubygems.org/gems/gitlabci-bundle-update-mr)
|
|
101
|
+
MARKDOWN
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
private
|
|
105
|
+
|
|
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
|
+
def system!(command)
|
|
123
|
+
# NOTE: system(exception: true) requires Ruby 2.6+
|
|
124
|
+
ret = system(command)
|
|
125
|
+
raise unless ret
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def gemfile_name
|
|
129
|
+
return @gemfile_name if @gemfile_name
|
|
130
|
+
|
|
131
|
+
@gemfile_name = ENV["BUNDLE_GEMFILE"] || "Gemfile"
|
|
132
|
+
|
|
133
|
+
if @gemfile_name.start_with?("#{Dir.pwd}/")
|
|
134
|
+
@gemfile_name = @gemfile_name.gsub("#{Dir.pwd}/", "")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
@gemfile_name
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def lockfile_name
|
|
141
|
+
"#{gemfile_name}.lock"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def gitlab
|
|
145
|
+
@gitlab ||= Gitlab.client(endpoint: ENV["GITLAB_API_ENDPOINT"], private_token: ENV["GITLAB_API_PRIVATE_TOKEN"])
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def current_time
|
|
149
|
+
@current_time ||= Time.now
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def new_branch
|
|
153
|
+
"#{BRANCH_PREFIX}#{current_time.strftime("%Y%m%d%H%M%S")}"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def exists_bundle_update_mr?
|
|
157
|
+
merge_requests = gitlab.merge_requests(@project_name, state: "opened", target_branch: @branch)
|
|
158
|
+
merge_requests.any? { |mr| mr.title.start_with?(TITLE_PREFIX) && mr.source_branch.start_with?(BRANCH_PREFIX) }
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require "gitlabci/bundle/update/mr/version"
|
|
2
|
+
require "gitlabci/bundle/update/mr/client"
|
|
3
|
+
require "gitlab"
|
|
4
|
+
require "compare_linker"
|
|
5
|
+
require "bundler"
|
|
6
|
+
|
|
7
|
+
module Gitlabci
|
|
8
|
+
module Bundle
|
|
9
|
+
module Update
|
|
10
|
+
module Mr
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
|
|
13
|
+
class MissingKeyError < Error; end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gitlabci-bundle-update-mr
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- sue445
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: compare_linker
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.4.3
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.4.3
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: gitlab
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 4.0.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 4.0.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: dotenv
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: gitlab_awesome_release
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: pry-byebug
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rake
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '10.0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '10.0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rspec
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '3.0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '3.0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: rspec-temp_dir
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: webmock
|
|
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'
|
|
153
|
+
description: Create MergeRequest of bundle update in GitLab CI
|
|
154
|
+
email:
|
|
155
|
+
- sue445@sue445.net
|
|
156
|
+
executables:
|
|
157
|
+
- gitlabci-bundle-update-mr
|
|
158
|
+
extensions: []
|
|
159
|
+
extra_rdoc_files: []
|
|
160
|
+
files:
|
|
161
|
+
- ".env.example"
|
|
162
|
+
- ".gitignore"
|
|
163
|
+
- ".gitlab-ci.yml"
|
|
164
|
+
- ".rspec"
|
|
165
|
+
- CHANGELOG.md
|
|
166
|
+
- Gemfile
|
|
167
|
+
- Gemfile.lock
|
|
168
|
+
- LICENSE.txt
|
|
169
|
+
- README.md
|
|
170
|
+
- Rakefile
|
|
171
|
+
- bin/console
|
|
172
|
+
- bin/setup
|
|
173
|
+
- exe/gitlabci-bundle-update-mr
|
|
174
|
+
- gitlabci-bundle-update-mr.gemspec
|
|
175
|
+
- lib/gitlabci/bundle/update/mr.rb
|
|
176
|
+
- lib/gitlabci/bundle/update/mr/client.rb
|
|
177
|
+
- lib/gitlabci/bundle/update/mr/version.rb
|
|
178
|
+
homepage: https://gitlab.com/sue445/gitlabci-bundle-update-mr
|
|
179
|
+
licenses:
|
|
180
|
+
- MIT
|
|
181
|
+
metadata:
|
|
182
|
+
homepage_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr
|
|
183
|
+
source_code_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr
|
|
184
|
+
changelog_uri: https://gitlab.com/sue445/gitlabci-bundle-update-mr/blob/master/CHANGELOG.md
|
|
185
|
+
post_install_message:
|
|
186
|
+
rdoc_options: []
|
|
187
|
+
require_paths:
|
|
188
|
+
- lib
|
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - ">="
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
version: 2.3.0
|
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
|
+
requirements:
|
|
196
|
+
- - ">="
|
|
197
|
+
- !ruby/object:Gem::Version
|
|
198
|
+
version: '0'
|
|
199
|
+
requirements: []
|
|
200
|
+
rubygems_version: 3.0.1
|
|
201
|
+
signing_key:
|
|
202
|
+
specification_version: 4
|
|
203
|
+
summary: Create MergeRequest of bundle update in GitLab CI
|
|
204
|
+
test_files: []
|