gitlab_add_approval_rules_bot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 81962cc2d72ae66fb21336cf41280e885d3d9cf67b4d1d9fdb387a67b7e460f2
4
+ data.tar.gz: '09b3915ebf67302fa75af58446d56b8db10b4d3273713c18be62aee5becd329c'
5
+ SHA512:
6
+ metadata.gz: 6eb8d9058fba110b90f28bac0b21c64ddf38611d0a14029ce5cd71f17952f2c9b19e8e419ab02592d25fdf73eb8c925927f848a974bd5e88740a65935309b6b1
7
+ data.tar.gz: ac1c16d0f8fd78f96973697e66bcf59cfebb796d9bd0a3dafe2a212a64a140201ae0ae554678c1e6f1eed44e1a5b5640f6821a693bab8b69edc5f8381d2ecc42
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in gitlab_add_approval_rules_bot.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Shoma FUKUDA
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # GitlabAddApprovalRulesBot
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitlab_add_approval_rules_bot`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gitlab_add_approval_rules_bot'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gitlab_add_approval_rules_bot
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gitlab_add_approval_rules_bot.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ # require "rspec/core/rake_task"
5
+
6
+ # RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'gitlab_add_approval_rules_bot'
5
+
6
+ GitlabAddApprovalRulesBot::CLI.start(ARGV)
7
+ exit
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/gitlab_add_approval_rules_bot/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gitlab_add_approval_rules_bot"
7
+ spec.version = GitlabAddApprovalRulesBot::VERSION
8
+ spec.authors = ["Shoma FUKUDA"]
9
+ spec.email = ["fkshom@gmail.com"]
10
+
11
+ spec.summary = "Add Merge Request Approval Rule Automatically in .gitlab-ci.yml"
12
+ spec.description = "Add Merge Request Approval Rule Automatically in .gitlab-ci.yml"
13
+ spec.homepage = "https://github.com/fkshom/gitlab_add_approval_rules_bot"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/fkshom/gitlab_add_approval_rules_bot"
20
+ spec.metadata["changelog_uri"] = "https://github.com/fkshom/gitlab_add_approval_rules_bot/README.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+ spec.add_dependency "gitlab"
36
+ spec.add_dependency "thor"
37
+ spec.add_dependency "dotenv"
38
+
39
+ # For more information and examples about making a new gem, check out our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitlabAddApprovalRulesBot
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gitlab_add_approval_rules_bot/version"
4
+ require "gitlab"
5
+ require "yaml"
6
+ require "thor"
7
+ require "dotenv"
8
+ Dotenv.load
9
+
10
+ Gitlab.configure do |config|
11
+ config.endpoint = ENV['GITLAB_ENDPOINT']
12
+ config.private_token = ENV['GITLAB_TOKEN']
13
+ end
14
+
15
+ module GitlabAddApprovalRulesBot
16
+ class Error < StandardError; end
17
+ class CLI < Thor
18
+ class_option :help, :type => :boolean, :aliases => '-h', :desc => 'help message.'
19
+ class_option :version, :type => :boolean, :desc => 'version'
20
+ default_task :help
21
+
22
+ desc "apply", "apply"
23
+ def apply(config_filename=nil, dry_run=true)
24
+ config_filename = "config.yml" if config_filename.nil?
25
+ config = YAML.load_file(config_filename)
26
+ project_id = ENV['PROJECT_ID'] or ENV['CI_PROJECT_ID']
27
+ merge_request_iid = ENV['MERGE_REQUEST_IID'] or ENV['CI_MERGE_REQUEST_IID']
28
+
29
+ config['rules'].each do |rule|
30
+ options = {
31
+ name: rule['name'],
32
+ approvals_required: rule['approvals_required'],
33
+ user_ids: [],
34
+ group_ids: [],
35
+ }
36
+ if rule.has_key? 'approval_project_rule_id'
37
+ options[:approval_project_rule_id] = rule['approval_project_rule_id']
38
+ end
39
+ if rule.has_key? 'user_ids'
40
+ options[:user_ids] = rule['user_ids']
41
+ end
42
+ if rule.has_key? 'group_ids'
43
+ options[:group_ids] = rule['group_ids']
44
+ end
45
+ if rule.has_key? 'usernames'
46
+ rule['usernames'].each do |username|
47
+ user = Gitlab.users(options: {username: username})&.first
48
+ pp user
49
+ options[:user_ids] << user['id'] unless user.nil?
50
+ end
51
+ end
52
+ if rule.has_key? 'groupnames'
53
+ rule['groupnames'].each do |groupname|
54
+ group = Gitlab.groups(options: {groupname: groupname})&.first
55
+ pp group
56
+ options[:group_ids] << group['id'] unless group.nil?
57
+ end
58
+ end
59
+ puts "project_id: #{project_id}"
60
+ puts "merge_request_iid: #{merge_request_iid}"
61
+ puts "options: #{options}"
62
+ if dry_run
63
+ puts "THIS IS DRY RUN MODE!!"
64
+ else
65
+ Gitlab.create_merge_request_level_rule(project_id, merge_request_iid, options)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,4 @@
1
+ module GitlabAddApprovalRulesBot
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab_add_approval_rules_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shoma FUKUDA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gitlab
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: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Add Merge Request Approval Rule Automatically in .gitlab-ci.yml
56
+ email:
57
+ - fkshom@gmail.com
58
+ executables:
59
+ - gitlab_add_approval_rules_bot
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - exe/gitlab_add_approval_rules_bot
69
+ - gitlab_add_approval_rules_bot.gemspec
70
+ - lib/gitlab_add_approval_rules_bot.rb
71
+ - lib/gitlab_add_approval_rules_bot/version.rb
72
+ - sig/gitlab_add_approval_rules_bot.rbs
73
+ homepage: https://github.com/fkshom/gitlab_add_approval_rules_bot
74
+ licenses: []
75
+ metadata:
76
+ allowed_push_host: https://rubygems.org
77
+ homepage_uri: https://github.com/fkshom/gitlab_add_approval_rules_bot
78
+ source_code_uri: https://github.com/fkshom/gitlab_add_approval_rules_bot
79
+ changelog_uri: https://github.com/fkshom/gitlab_add_approval_rules_bot/README.md
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.6.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.3.7
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Add Merge Request Approval Rule Automatically in .gitlab-ci.yml
99
+ test_files: []