danger-gitlab_reviewbot 1.1.6 → 1.1.8
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gitlab_reviewbot/gem_version.rb +1 -1
- data/lib/gitlab_reviewbot/gitlab.rb +54 -26
- data/spec/gitlab_ext_spec.rb +51 -0
- data/spec/spec_helper.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a7eaa5cd15e0c7c399b577b76461cf7eb3580b1d1350bcc0175c5126784fc1c
|
4
|
+
data.tar.gz: 17c5294182aad19fb6d68dcf6858ab313a1ed140a53acffa6ef815abdb4b5a48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b66136604fadac6c2d49a53739b5435a40a3634a269683d68af032a0bd5475a8070f3a6f8a49801bc537a167c4f3b5955fd97fa464ea9349c268056612526708
|
7
|
+
data.tar.gz: 776cc841222ceb2f057aa7c9bc4fda90b3dff2fddfa602c4863e036f71ab6af098a1a22b0606dda00a829d98edcd7da77d02bf68b4c3ab9adc299489d0471f4a
|
data/Gemfile.lock
CHANGED
@@ -19,12 +19,33 @@ module Gitlab
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
class
|
22
|
+
class ClientHelper
|
23
|
+
def initialize(client)
|
24
|
+
@client = client
|
25
|
+
end
|
26
|
+
|
27
|
+
def users_with_pending_mr_review(project_id)
|
28
|
+
outstanding_mrs = fetch_mrs_requiring_review(project_id)
|
29
|
+
all_assignees = outstanding_mrs.reduce([]) { |acc, mr| acc + mr.assignees - assignees_with_review(project_id, mr.id, mr.assignees)}
|
30
|
+
assignees_id_map = all_assignees.each_with_object({}) do |a, acc|
|
31
|
+
aid = a["id"]
|
32
|
+
ausername = a["username"]
|
33
|
+
assignee = acc[aid] || User.new(aid, ausername)
|
34
|
+
assignee.review_count += 1
|
35
|
+
acc[aid] = assignee
|
36
|
+
end
|
37
|
+
assignees_id_map.values
|
38
|
+
end
|
39
|
+
|
40
|
+
def fetch_mrs_requiring_review(project_id)
|
41
|
+
@client.merge_requests(project_id, state: "opened", per_page: "100")
|
42
|
+
end
|
43
|
+
|
23
44
|
def fetch_users_for_group(group_name)
|
24
|
-
group_id =
|
45
|
+
group_id = search_group_with_path(group_name)
|
25
46
|
return nil if group_id.nil?
|
26
47
|
|
27
|
-
res = group_members(group_id)
|
48
|
+
res = @client.group_members(group_id, :per_page => 100)
|
28
49
|
|
29
50
|
developer_access_level = 30
|
30
51
|
res.select { |u| u.state == "active" && u.access_level >= developer_access_level }.map { |u| User.new(u.id, u.username) }
|
@@ -32,44 +53,28 @@ module Gitlab
|
|
32
53
|
|
33
54
|
def assign_mr_to_users(project_id, mr_iid, users)
|
34
55
|
user_ids = users.map(&:id)
|
35
|
-
update_merge_request(project_id, mr_iid, "assignee_ids" => user_ids)
|
56
|
+
@client.update_merge_request(project_id, mr_iid, "assignee_ids" => user_ids)
|
57
|
+
|
36
58
|
end
|
37
59
|
|
38
60
|
def fetch_author_for_mr(project_id, mr_iid)
|
39
|
-
res = merge_request(project_id, mr_iid)
|
61
|
+
res = @client.merge_request(project_id, mr_iid)
|
40
62
|
User.new(res.author.id, res.author.name)
|
41
63
|
end
|
42
64
|
|
43
|
-
def fetch_mrs_requiring_review(project_id)
|
44
|
-
merge_requests(project_id, state: "opened", per_page: "100")
|
45
|
-
end
|
46
|
-
|
47
65
|
def find_user_with_username(username)
|
48
|
-
users({ username: username }).map { |u| User.new(u.id, u.username) }
|
49
|
-
end
|
50
|
-
|
51
|
-
def users_with_pending_mr_review(project_id)
|
52
|
-
outstanding_mrs = fetch_mrs_requiring_review(project_id)
|
53
|
-
all_assignees = outstanding_mrs.reduce([]) { |acc, mr| acc + mr.assignees }
|
54
|
-
assignees_id_map = all_assignees.each_with_object({}) do |a, acc|
|
55
|
-
aid = a["id"]
|
56
|
-
ausername = a["username"]
|
57
|
-
assignee = acc[aid] || User.new(aid, ausername)
|
58
|
-
assignee.review_count += 1
|
59
|
-
acc[aid] = assignee
|
60
|
-
end
|
61
|
-
assignees_id_map.values
|
66
|
+
@client.users({ username: username }).map { |u| User.new(u.id, u.username) }
|
62
67
|
end
|
63
68
|
|
64
69
|
def fetch_mr_reviewers(project_id, mr_iid)
|
65
|
-
merge_request(project_id, mr_iid).assignees.map { |u| User.new(u["id"], u["username"]) }
|
70
|
+
@client.merge_request(project_id, mr_iid).assignees.map { |u| User.new(u["id"], u["username"]) }
|
66
71
|
end
|
67
72
|
|
68
73
|
private
|
69
74
|
|
70
|
-
def
|
75
|
+
def search_group_with_path(group_name)
|
71
76
|
short_name = group_name.split("/").last
|
72
|
-
res = group_search(short_name)
|
77
|
+
res = @client.group_search(short_name)
|
73
78
|
res = res.find { |i| i.full_path == group_name }
|
74
79
|
|
75
80
|
if res.nil?
|
@@ -78,5 +83,28 @@ module Gitlab
|
|
78
83
|
res.id
|
79
84
|
end
|
80
85
|
end
|
86
|
+
|
87
|
+
def assignees_with_review(project_id, mr_iid, gusers)
|
88
|
+
approvals = @client.merge_request_approval_state(project_id, mr_iid)
|
89
|
+
approved_by = approvals.rules.reduce([]) { |acc, r| acc + r['approved_by'] }
|
90
|
+
gusers.filter { |u| approved_by.index { |au| au['id'] == u['id'] } != nil }
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
class Client < API
|
96
|
+
|
97
|
+
def client_helper
|
98
|
+
@client_helper ||= ClientHelper.new(self)
|
99
|
+
end
|
100
|
+
|
101
|
+
def method_missing(method, *args)
|
102
|
+
if @client_helper.respond_to?(method)
|
103
|
+
@client_helper.send(method, *args)
|
104
|
+
else
|
105
|
+
super
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
81
109
|
end
|
82
110
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("spec_helper", __dir__)
|
4
|
+
|
5
|
+
|
6
|
+
module Danger
|
7
|
+
describe Gitlab::Client do
|
8
|
+
before do
|
9
|
+
#
|
10
|
+
# @sam = Gitlab::User.new(1, "Sam")
|
11
|
+
# @tom = Gitlab::User.new(2, "Tom")
|
12
|
+
# @nic = Gitlab::User.new(3, "Nic")
|
13
|
+
# @luke = Gitlab::User.new(4, "Luke")
|
14
|
+
@mock_client = double(Gitlab::Client)
|
15
|
+
@client_helper = Gitlab::ClientHelper.new(@mock_client)
|
16
|
+
@sam = Gitlab::User.new(1, "Sam")
|
17
|
+
@tom = Gitlab::User.new(2, "Tom")
|
18
|
+
@nic = Gitlab::User.new(3, "Nic")
|
19
|
+
@assignees = [{'id' => 1, 'username' => "Sam"},
|
20
|
+
{'id' => 2, 'username' => "Tom"},
|
21
|
+
{'id' => 3, 'username' => "Nic"}]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "Correctly calculates users with pending reviews" do
|
25
|
+
already_reviewed = [@assignees[0]]
|
26
|
+
|
27
|
+
allow(@mock_client).to receive(:merge_requests).with(10, {:per_page=>"100", :state=>"opened"}).and_return([Gitlab::ObjectifiedHash.new({'id' => 110, 'assignees' => @assignees})])
|
28
|
+
allow(@mock_client).to receive(:merge_request_approval_state).with(10, 110).and_return(Gitlab::ObjectifiedHash.new({'rules' => [{'approved_by' => already_reviewed}]}))
|
29
|
+
|
30
|
+
expect(@client_helper.users_with_pending_mr_review(10)).to be == [@tom, @nic]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "Correctly calculates users with pending reviews (multi rule)" do
|
34
|
+
allow(@mock_client).to receive(:merge_requests).with(10, {:per_page=>"100", :state=>"opened"}).and_return([Gitlab::ObjectifiedHash.new({'id' => 110, 'assignees' => @assignees})])
|
35
|
+
allow(@mock_client).to receive(:merge_request_approval_state).with(10, 110).and_return(Gitlab::ObjectifiedHash.new({'rules' => [{'approved_by' => [{'id' => 1, 'username' => "Sam"}]}, {'approved_by' => [{'id' => 2, 'username' => "Tom"}]}]}))
|
36
|
+
|
37
|
+
expect(@client_helper.users_with_pending_mr_review(10)).to be == [@nic]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Fetches only active developer users for group" do
|
41
|
+
active_users = [Gitlab::ObjectifiedHash.new({'id' => 1, 'username' => 'Sam', 'state' => 'active', 'access_level' => 30}),
|
42
|
+
Gitlab::ObjectifiedHash.new({'id' => 2, 'username' => 'Tom', 'state' => 'active', 'access_level' => 50})]
|
43
|
+
inactive_users = [Gitlab::ObjectifiedHash.new({'id' => 3, 'username' => 'OldSam', 'state' => 'inactive', 'access_level' => 30})]
|
44
|
+
non_developer_users = [Gitlab::ObjectifiedHash.new({'id' => 4, 'username' => 'Reporter', 'state' => 'active', 'access_level' => 20})]
|
45
|
+
allow(@mock_client).to receive(:group_search).with("mygroup").and_return([Gitlab::ObjectifiedHash.new({'id' => 10, 'full_path' => "mygroup"})])
|
46
|
+
allow(@mock_client).to receive(:group_members).with(10).and_return(active_users + inactive_users + non_developer_users)
|
47
|
+
expect(@client_helper.fetch_users_for_group("mygroup")).to be == [@sam, @tom]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-gitlab_reviewbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Gallonetto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- lib/gitlab_reviewbot/strategies/least_busy.rb
|
219
219
|
- lib/gitlab_reviewbot/strategies/random.rb
|
220
220
|
- lib/gitlab_reviewbot/strategies/strategy.rb
|
221
|
+
- spec/gitlab_ext_spec.rb
|
221
222
|
- spec/gitlab_reviewbot_spec.rb
|
222
223
|
- spec/least_busy_strategy_spec.rb
|
223
224
|
- spec/random_strategy_spec.rb
|
@@ -246,6 +247,7 @@ signing_key:
|
|
246
247
|
specification_version: 4
|
247
248
|
summary: A review raffle bot for Gitlab.
|
248
249
|
test_files:
|
250
|
+
- spec/gitlab_ext_spec.rb
|
249
251
|
- spec/gitlab_reviewbot_spec.rb
|
250
252
|
- spec/least_busy_strategy_spec.rb
|
251
253
|
- spec/random_strategy_spec.rb
|