gitlab_add_approval_rules_bot 0.1.4 → 0.1.5

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: b151f6b20f53156bb054c7f675f546b0b5ba08c6d0e8bd28a935a16668e72df9
4
- data.tar.gz: dc369f9fba6d58723568ff16dcb724e83f65d2eb4aafd1b37810ee7a44cc6476
3
+ metadata.gz: 228402c58abefdb8bcb340abc611ee8694feee4f2afec50b4d39d3bf84d818bc
4
+ data.tar.gz: 4e63f2f8d173e120291f3dbc53357c15c0c4d851b93e272d0c0baadc7e86994a
5
5
  SHA512:
6
- metadata.gz: c02d2137b86f8ce9eb43cd1d36181d98a5039e932094256815d9c74b2fd750c5bae25c16b833a9b9b47098c242e9bf4a14caea7c9d4577e910f686e9cea91522
7
- data.tar.gz: 3640680674a38467edbe34ba705edc08d9490270a6e4e323f78e1e88052ebe6e95b31411985b1863e3f1bda917d8ddfc73d29cf4ad74ef759f121b7435416596
6
+ metadata.gz: 8fdd3b504e904ca29300fff887d3af1556c34367d2abb91fa3232dcfad6989fd669c710ab5d962a0f72604f8e233c80301f2d1eabe2f9decfeaa6294233fd75f
7
+ data.tar.gz: 804600dea4082bef182d0664735473afa3f58d51db6b446163f191e3f7a1c95532970c73200367ba2785db2add7aee7a0eaeb7639b8a0d5a81c110218de0e330
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gitlab_add_approval_rules_bot (0.1.4)
5
+ dotenv
6
+ gitlab
7
+ thor
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.5.0)
13
+ dotenv (2.7.6)
14
+ gitlab (4.18.0)
15
+ httparty (~> 0.18)
16
+ terminal-table (>= 1.5.1)
17
+ httparty (0.20.0)
18
+ mime-types (~> 3.0)
19
+ multi_xml (>= 0.5.2)
20
+ mime-types (3.4.1)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2022.0105)
23
+ multi_xml (0.6.0)
24
+ rake (13.0.6)
25
+ rspec (3.11.0)
26
+ rspec-core (~> 3.11.0)
27
+ rspec-expectations (~> 3.11.0)
28
+ rspec-mocks (~> 3.11.0)
29
+ rspec-core (3.11.0)
30
+ rspec-support (~> 3.11.0)
31
+ rspec-expectations (3.11.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.11.0)
34
+ rspec-mocks (3.11.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.11.0)
37
+ rspec-support (3.11.0)
38
+ terminal-table (3.0.2)
39
+ unicode-display_width (>= 1.1.1, < 3)
40
+ thor (1.2.1)
41
+ unicode-display_width (2.1.0)
42
+
43
+ PLATFORMS
44
+ x86_64-linux
45
+
46
+ DEPENDENCIES
47
+ gitlab_add_approval_rules_bot!
48
+ rake (~> 13.0)
49
+ rspec (~> 3.0)
50
+
51
+ BUNDLED WITH
52
+ 2.3.7
data/config.yml.sample ADDED
@@ -0,0 +1,19 @@
1
+ global:
2
+ stop_when_error: true
3
+ rules:
4
+ - name: rule1
5
+ approvals_required: 1
6
+ user_ids:
7
+ - 1
8
+ group_ids:
9
+ - 1
10
+ - name: rule2
11
+ approvals_required: 1
12
+ usernames:
13
+ - user2
14
+ groupnames:
15
+ - group2
16
+ user_ids:
17
+ - 2
18
+ group_ids:
19
+ - 2
data/docker/Dockerfile ADDED
@@ -0,0 +1,5 @@
1
+ FROM ruby:3.1.2-alpine3.16
2
+
3
+ RUN gem install gitlab_add_approval_rules_bot
4
+
5
+ CMD ["gitlab_add_approval_rules_bot"]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitlabAddApprovalRulesBot
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -8,7 +8,7 @@ require "dotenv"
8
8
  Dotenv.load
9
9
 
10
10
  Gitlab.configure do |config|
11
- config.endpoint = ENV['GITLAB_ENDPOINT'] or ENV['CI_API_V4_URL']
11
+ config.endpoint = ENV['GITLAB_ENDPOINT'] || ENV['CI_API_V4_URL']
12
12
  config.private_token = ENV['GITLAB_TOKEN']
13
13
  end
14
14
 
@@ -21,65 +21,66 @@ module GitlabAddApprovalRulesBot
21
21
 
22
22
  desc "apply", "apply"
23
23
  option :dry_run, aliases: "-d", type: :boolean, desc: "dry run mode", default: false
24
- def apply(config_filename=nil)
24
+ option :config, aliases: "-c", type: :string, desc: "config file name", default: "config.yml"
25
+ def apply(*rulenames)
25
26
  config_filename = "config.yml" if config_filename.nil?
26
27
  config = YAML.load_file(config_filename)
27
- project_id = ENV['PROJECT_ID'] or ENV['CI_PROJECT_ID']
28
- merge_request_iid = ENV['MERGE_REQUEST_IID'] or ENV['CI_MERGE_REQUEST_IID']
28
+ project_id = ENV['PROJECT_ID'] || ENV['CI_PROJECT_ID']
29
+ merge_request_iid = ENV['MERGE_REQUEST_IID'] || ENV['CI_MERGE_REQUEST_IID']
29
30
 
30
- config['rules'].each do |rule|
31
+ rulenames.each do |rulename|
32
+ if not config['rules'].key? rulename
33
+ puts "SKIP: rulename #{rulename} in not exists."
34
+ next
35
+ end
36
+ rule = config['rules'][rulename]
31
37
  rule_options = {
32
38
  name: rule['name'],
33
39
  approvals_required: rule['approvals_required'],
34
40
  user_ids: [],
35
41
  group_ids: [],
36
42
  }
37
- if rule.has_key? 'approval_project_rule_id'
38
- rule_options[:approval_project_rule_id] = rule['approval_project_rule_id']
39
- end
40
- if rule.has_key? 'user_ids'
41
- rule_options[:user_ids] = rule['user_ids']
42
- end
43
- if rule.has_key? 'group_ids'
44
- rule_options[:group_ids] = rule['group_ids']
45
- end
46
- if rule.has_key? 'usernames'
47
- rule['usernames'].each do |username|
48
- user = Gitlab.user_search(username)&.first
49
- pp user
50
- if not user.nil? and user['username'] == username
51
- rule_options[:user_ids] << user['id'] unless user.nil?
52
- end
43
+
44
+ rule_options[:approval_project_rule_id] = rule['approval_project_rule_id'] || nil
45
+ rule_options[:user_ids] = rule['user_ids'] || []
46
+ rule_options[:group_ids] = rule['group_ids'] || []
47
+
48
+ (rule['usernames'] || []).each do |username|
49
+ user = Gitlab.user_search(username)&.first
50
+ pp user
51
+ if not user.nil? and user['username'] == username.to_s
52
+ rule_options[:user_ids] << user['id']
53
53
  end
54
54
  end
55
- if rule.has_key? 'groupnames'
56
- rule['groupnames'].each do |groupname|
57
- group = Gitlab.group_search(groupname)&.first
58
- pp group
59
- if not group.nil? and group['groupname'] == groupname
60
- rule_options[:group_ids] << group['id'] unless group.nil?
61
- end
62
55
 
56
+ (rule['groupnames'] || []).each do |groupname|
57
+ group = Gitlab.group_search(groupname)&.first
58
+ pp group
59
+ if not group.nil? and group['groupname'] == groupname.to_s
60
+ rule_options[:group_ids] << group['id']
63
61
  end
64
62
  end
63
+
65
64
  puts "project_id: #{project_id}"
66
65
  puts "merge_request_iid: #{merge_request_iid}"
67
66
  puts "options: #{rule_options}"
68
67
  if options[:dry_run]
69
68
  puts "THIS IS DRY RUN MODE!!"
70
- else
71
- if project_id.nil?
72
- puts "project_id is nil"
73
- puts "exit"
74
- return
75
- end
76
- if merge_request_iid.nil?
77
- puts "merge_request_iid is nil"
78
- puts "exit"
79
- return
80
- end
81
- Gitlab.create_merge_request_level_rule(project_id, merge_request_iid, rule_options)
69
+ next
70
+ end
71
+
72
+ if project_id.nil?
73
+ puts "project_id is nil"
74
+ puts "exit"
75
+ next
76
+ end
77
+ if merge_request_iid.nil?
78
+ puts "merge_request_iid is nil"
79
+ puts "exit"
80
+ next
82
81
  end
82
+
83
+ Gitlab.create_merge_request_level_rule(project_id, merge_request_iid, rule_options)
83
84
  end
84
85
  end
85
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_add_approval_rules_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shoma FUKUDA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-16 00:00:00.000000000 Z
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -62,9 +62,12 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".rspec"
64
64
  - Gemfile
65
+ - Gemfile.lock
65
66
  - LICENSE
66
67
  - README.md
67
68
  - Rakefile
69
+ - config.yml.sample
70
+ - docker/Dockerfile
68
71
  - exe/gitlab_add_approval_rules_bot
69
72
  - gitlab_add_approval_rules_bot.gemspec
70
73
  - lib/gitlab_add_approval_rules_bot.rb