gitlab_add_approval_rules_bot 0.1.2 → 0.1.5

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: 86b42dbf8571c0128deea792d806b1e4ac7597bc17a9006c2753f3f155dc6bce
4
- data.tar.gz: 4908d7b507ee44a9da81380f0e0d3dde80fd43884a192249f431283453b8d5e5
3
+ metadata.gz: 228402c58abefdb8bcb340abc611ee8694feee4f2afec50b4d39d3bf84d818bc
4
+ data.tar.gz: 4e63f2f8d173e120291f3dbc53357c15c0c4d851b93e272d0c0baadc7e86994a
5
5
  SHA512:
6
- metadata.gz: 1285063a7244435f6c1510f83563e7e1f9bcfb71d3fbbf2320befaebc21f327b0b71803e37cf57d5c4388e516cc76dfd92312c75f5340c662a45caa0088f74eb
7
- data.tar.gz: 17e0dccaec4a29fa61b600578e7cd345e02972f39bc98ea5886fc8c302a220607393d78dff86523be369b501b45f7454248ff01d6e4c2ed9cf56d7826b3ccc11
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.2"
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']
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,55 +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
- 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
72
76
  end
77
+ if merge_request_iid.nil?
78
+ puts "merge_request_iid is nil"
79
+ puts "exit"
80
+ next
81
+ end
82
+
83
+ Gitlab.create_merge_request_level_rule(project_id, merge_request_iid, rule_options)
73
84
  end
74
85
  end
75
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.2
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