danger-gitlab_reviewbot 1.1.2 → 1.1.4
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/.gitlab-ci.yml +19 -0
- data/Gemfile.lock +1 -1
- data/danger-gitlab_reviewbot.gemspec +1 -1
- data/lib/danger_gitlab_reviewbot.rb +2 -0
- data/lib/danger_plugin.rb +2 -0
- data/lib/gitlab_reviewbot/gem_version.rb +3 -1
- data/lib/gitlab_reviewbot/gitlab.rb +14 -13
- data/lib/gitlab_reviewbot/plugin.rb +35 -34
- data/lib/gitlab_reviewbot/strategies/least_busy.rb +11 -10
- data/lib/gitlab_reviewbot/strategies/random.rb +6 -4
- data/lib/gitlab_reviewbot/strategies/strategy.rb +13 -9
- data/lib/gitlab_reviewbot/strategies.rb +5 -4
- data/spec/gitlab_reviewbot_spec.rb +13 -14
- data/spec/least_busy_strategy_spec.rb +31 -13
- data/spec/random_strategy_spec.rb +10 -11
- data/spec/spec_helper.rb +11 -9
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2886d84d0e6fb6e296379feeb66e4e183d5aa8bd8598a3f4e2713aa5b4b5927
|
4
|
+
data.tar.gz: 0b1aa53383e71c481256c8893064ca54cda389c8dad6f2dcad014d48117c8edb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a4d8a9e9da4ce0883efae5cd949d18497b0e571b916443c4276a884b1fe6be2fe35a143c803665bb0d6f810a16b1687032fde49585a92066d381811ed52507a
|
7
|
+
data.tar.gz: '03528aa2084af65294610316cdff1a584c6507ccd88ed407270d87ed27029d6734e73a0ef06f4c9af5b60ce2bd68292debc456187c48107b015760b5f8a1393f'
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
image: "ruby:2.6"
|
2
|
+
|
3
|
+
cache:
|
4
|
+
paths:
|
5
|
+
- vendor/bundle/
|
6
|
+
|
7
|
+
test:
|
8
|
+
stage: test
|
9
|
+
script:
|
10
|
+
- gem install bundler
|
11
|
+
- bundle --path vendor/bundle
|
12
|
+
- bundle exec rake spec
|
13
|
+
- bundle exec rake build
|
14
|
+
artifacts:
|
15
|
+
paths:
|
16
|
+
- rspec.xml
|
17
|
+
reports:
|
18
|
+
junit: rspec.xml
|
19
|
+
|
data/Gemfile.lock
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['fabio.gallonetto@curve.com']
|
11
11
|
spec.description = %q{A review raffle bot for Gitlab }
|
12
12
|
spec.summary = %q{A review raffle bot for Gitlab.}
|
13
|
-
spec.homepage = 'https://
|
13
|
+
spec.homepage = 'https://git.curve.tools/fabio.gallonetto/danger-gitlab_reviewbot'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/danger_plugin.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "gitlab"
|
2
4
|
|
3
5
|
module Gitlab
|
4
6
|
class User
|
@@ -25,12 +27,12 @@ module Gitlab
|
|
25
27
|
res = group_members(group_id)
|
26
28
|
|
27
29
|
developer_access_level = 30
|
28
|
-
res.select { |u| u.state ==
|
30
|
+
res.select { |u| u.state == "active" && u.access_level >= developer_access_level }.map { |u| User.new(u.id, u.username) }
|
29
31
|
end
|
30
32
|
|
31
33
|
def assign_mr_to_users(project_id, mr_iid, users)
|
32
34
|
user_ids = users.map(&:id)
|
33
|
-
update_merge_request(project_id, mr_iid,
|
35
|
+
update_merge_request(project_id, mr_iid, "assignee_ids" => user_ids)
|
34
36
|
end
|
35
37
|
|
36
38
|
def fetch_author_for_mr(project_id, mr_iid)
|
@@ -39,34 +41,34 @@ module Gitlab
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def fetch_mrs_requiring_review(project_id)
|
42
|
-
merge_requests(project_id, :
|
44
|
+
merge_requests(project_id, state: "opened", per_page: "100").reject { |mr| mr.merge_status == "can_be_merged" }
|
43
45
|
end
|
44
46
|
|
45
47
|
def find_user_with_username(username)
|
46
|
-
users({:username
|
48
|
+
users({ username: username }).map { |u| User.new(u.id, u.username) }
|
47
49
|
end
|
48
50
|
|
49
51
|
def users_with_pending_mr_review(project_id)
|
50
52
|
outstanding_mrs = fetch_mrs_requiring_review(project_id)
|
51
53
|
all_assignees = outstanding_mrs.reduce([]) { |acc, mr| acc + mr.assignees }
|
52
|
-
assignees_id_map = all_assignees.
|
53
|
-
aid = a[
|
54
|
-
ausername = a[
|
54
|
+
assignees_id_map = all_assignees.each_with_object({}) do |a, acc|
|
55
|
+
aid = a["id"]
|
56
|
+
ausername = a["username"]
|
55
57
|
assignee = acc[aid] || User.new(aid, ausername)
|
56
58
|
assignee.review_count += 1
|
57
59
|
acc[aid] = assignee
|
58
|
-
|
59
|
-
}
|
60
|
+
end
|
60
61
|
assignees_id_map.values
|
61
62
|
end
|
62
63
|
|
63
64
|
def fetch_mr_reviewers(project_id, mr_iid)
|
64
|
-
merge_request(project_id, mr_iid).assignees.map { |u| User.new(u[
|
65
|
+
merge_request(project_id, mr_iid).assignees.map { |u| User.new(u["id"], u["username"]) }
|
65
66
|
end
|
66
67
|
|
67
68
|
private
|
69
|
+
|
68
70
|
def search_group(group_name)
|
69
|
-
short_name = group_name.split(
|
71
|
+
short_name = group_name.split("/").last
|
70
72
|
res = group_search(short_name)
|
71
73
|
res = res.find { |i| i.full_path == group_name }
|
72
74
|
|
@@ -78,4 +80,3 @@ module Gitlab
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
81
|
-
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "gitlab_reviewbot/strategies"
|
3
4
|
|
4
5
|
module Danger
|
5
6
|
# This is your plugin class. Any attributes or methods you expose here will
|
@@ -20,8 +21,7 @@ module Danger
|
|
20
21
|
# @tags monday, weekends, time, rattata
|
21
22
|
#
|
22
23
|
class DangerGitlabReviewbot < Plugin
|
23
|
-
|
24
|
-
# Define the group to take the reviewers from.
|
24
|
+
# Define the group to take the reviewers from.
|
25
25
|
# NOTE: This is the group full path as in 'tech/iOS' instead of just the group name
|
26
26
|
#
|
27
27
|
# @return String
|
@@ -44,31 +44,10 @@ module Danger
|
|
44
44
|
# * Danger::AssignStrategies::LeastBusyStrategy - assign the N users with the least amount of open MRs
|
45
45
|
# to review
|
46
46
|
#
|
47
|
-
def strategy
|
48
|
-
@strategy #|| Danger::AssignStrategies::RandomStrategy.new(client: gitlab.api, project: project_id, mr: mr_iid)
|
49
|
-
end
|
50
|
-
|
51
47
|
def strategy=(klass)
|
52
|
-
@strategy = klass.new(client: gitlab.api, project: project_id,
|
53
|
-
end
|
54
|
-
|
55
|
-
def project_id
|
56
|
-
ENV['CI_PROJECT_ID']
|
57
|
-
end
|
58
|
-
|
59
|
-
def mr_iid
|
60
|
-
ENV['CI_MERGE_REQUEST_IID']
|
48
|
+
@strategy = klass.new(client: gitlab.api, project: project_id, mr_iid: mr_iid)
|
61
49
|
end
|
62
50
|
|
63
|
-
#Once a strategy is in place, adopt the conf methods
|
64
|
-
def method_missing(method, *args)
|
65
|
-
super unless method.to_s.start_with? 'strategy_'
|
66
|
-
if strategy.respond_to? method.to_s.delete_prefix('strategy_')
|
67
|
-
strategy.send(method.to_s.delete_prefix('strategy_'), *args)
|
68
|
-
else
|
69
|
-
super
|
70
|
-
end
|
71
|
-
end
|
72
51
|
|
73
52
|
# Call this method from the Dangerfile to assign reviewers to your merge requests
|
74
53
|
# @return The usernames list of assigned reviewes [Array<String>]
|
@@ -82,14 +61,14 @@ module Danger
|
|
82
61
|
raise "Env variable CI_PROJECT_ID doesn't point to a valid project id"
|
83
62
|
end
|
84
63
|
|
85
|
-
current_assignees = (ENV[
|
86
|
-
already_assigned_count = current_assignees.length
|
87
|
-
required_assignees_count = [assignees_amount - already_assigned_count, 0].max
|
64
|
+
current_assignees = (ENV["CI_MERGE_REQUEST_ASSIGNEES"] || "").split(",") # buggy?
|
65
|
+
# already_assigned_count = current_assignees.length
|
66
|
+
# required_assignees_count = [assignees_amount - already_assigned_count, 0].max
|
88
67
|
|
89
|
-
puts "Project ID: #{project_id}" if verbose
|
90
|
-
puts "MR IID: #{mr_iid}" if verbose
|
91
|
-
puts "Currently assigned: #{current_assignees}" if verbose
|
92
|
-
|
68
|
+
ui.puts "Project ID: #{project_id}" if verbose
|
69
|
+
ui.puts "MR IID: #{mr_iid}" if verbose
|
70
|
+
ui.puts "Currently assigned: #{current_assignees}" if verbose
|
71
|
+
# puts "Required: #{required_assignees_count}" if @verbose
|
93
72
|
|
94
73
|
# if required_assignees_count == 0
|
95
74
|
# puts "Nothing to do" if verbose
|
@@ -100,12 +79,34 @@ module Danger
|
|
100
79
|
|
101
80
|
assignees = @strategy.assign! assignees_amount
|
102
81
|
|
103
|
-
puts "Assigning: #{assignees}" if verbose
|
82
|
+
ui.puts "Assigning: #{assignees}" if verbose
|
104
83
|
return assignees
|
105
84
|
end
|
106
85
|
|
107
86
|
private
|
108
87
|
|
88
|
+
attr_reader :strategy
|
89
|
+
|
90
|
+
def project_id
|
91
|
+
ENV["CI_PROJECT_ID"]
|
92
|
+
end
|
93
|
+
|
94
|
+
def mr_iid
|
95
|
+
ENV["CI_MERGE_REQUEST_IID"]
|
96
|
+
end
|
97
|
+
|
98
|
+
# Once a strategy is in place, adopt the conf methods
|
99
|
+
def method_missing(method, *args)
|
100
|
+
super unless method.to_s.start_with? "strategy_"
|
101
|
+
if strategy.respond_to? method.to_s.delete_prefix("strategy_")
|
102
|
+
strategy.send(method.to_s.delete_prefix("strategy_"), *args)
|
103
|
+
else
|
104
|
+
super
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def respond_to_missing?(method_name, include_private = false)
|
109
|
+
method_name.to_s.start_with?("strategy_") || super
|
110
|
+
end
|
109
111
|
end
|
110
112
|
end
|
111
|
-
|
@@ -1,21 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "gitlab_reviewbot/gitlab"
|
2
4
|
|
3
5
|
module Danger
|
4
6
|
module AssignStrategies
|
5
7
|
class LeastBusyStrategy < Strategy
|
6
8
|
def assignees(amount)
|
7
|
-
|
8
|
-
|
9
|
-
invalid_assignees = [
|
9
|
+
# This doesn't fetch the review count for the users so we need to fetch it separately later
|
10
|
+
users_in_group = fetch_users_in_group
|
11
|
+
invalid_assignees = [fetch_author] + fetch_assigned_reviewers
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
group_users_with_reviews_pending = client.users_with_pending_mr_review(project_id).filter { |u| users_in_group.include? u }
|
14
|
+
group_users_without_reviews_pending = users_in_group.filter { |u| !group_users_with_reviews_pending.include? u }
|
13
15
|
|
14
|
-
(
|
15
|
-
|
16
|
-
|
16
|
+
(group_users_with_reviews_pending + group_users_without_reviews_pending).filter { |u| !invalid_assignees.include? u }
|
17
|
+
.sort_by(&:review_count)
|
18
|
+
.first(amount)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "gitlab_reviewbot/gitlab"
|
2
4
|
|
3
5
|
module Danger
|
4
6
|
module AssignStrategies
|
5
7
|
class RandomStrategy < Strategy
|
6
8
|
def assignees(amount)
|
7
|
-
invalid_assignees = [
|
8
|
-
fetch_users_in_group.filter { |u| !
|
9
|
-
|
9
|
+
invalid_assignees = [fetch_author] + fetch_assigned_reviewers
|
10
|
+
fetch_users_in_group.filter { |u| !invalid_assignees.include? u }
|
11
|
+
.sample(amount)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danger
|
2
4
|
module AssignStrategies
|
3
5
|
class Strategy
|
@@ -7,25 +9,25 @@ module Danger
|
|
7
9
|
attr_accessor :client
|
8
10
|
attr_accessor :excluded_users
|
9
11
|
|
10
|
-
def initialize(client:, project:,
|
12
|
+
def initialize(client:, project:, mr_iid:)
|
11
13
|
@client = client
|
12
14
|
@project_id = project
|
13
|
-
@mr_iid =
|
15
|
+
@mr_iid = mr_iid
|
14
16
|
@excluded_users = []
|
15
17
|
end
|
16
18
|
|
17
19
|
def assign!(amount)
|
18
|
-
currently_assigned = fetch_assigned_reviewers
|
20
|
+
currently_assigned = fetch_assigned_reviewers
|
19
21
|
return [] if (amount - currently_assigned.length) <= 0
|
20
22
|
|
21
23
|
to_be_assigned = assignees(amount - currently_assigned.length)
|
22
24
|
all_assignees = currently_assigned + to_be_assigned
|
23
25
|
|
24
|
-
|
26
|
+
client.assign_mr_to_users(project_id, mr_iid, all_assignees)
|
25
27
|
all_assignees.map(&:username)
|
26
28
|
end
|
27
29
|
|
28
|
-
def assignees(
|
30
|
+
def assignees(_amount)
|
29
31
|
raise "To be implemented in the subclasses"
|
30
32
|
end
|
31
33
|
|
@@ -38,11 +40,13 @@ module Danger
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def fetch_users_in_group
|
41
|
-
excluded = @excluded_users.map
|
42
|
-
|
43
|
+
excluded = @excluded_users.map do |u|
|
44
|
+
server_user = client.find_user_with_username(u).first
|
45
|
+
raise "ERROR: Invalid username #{u} among excluded_users" if server_user.nil?
|
46
|
+
server_user
|
47
|
+
end
|
48
|
+
client.fetch_users_for_group(@group_name).filter { |u| !excluded.include? u }
|
43
49
|
end
|
44
|
-
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
48
|
-
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Danger
|
2
4
|
module AssignStrategies
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
5
|
+
require "gitlab_reviewbot/strategies/strategy"
|
6
|
+
require "gitlab_reviewbot/strategies/random"
|
7
|
+
require "gitlab_reviewbot/strategies/least_busy"
|
6
8
|
end
|
7
9
|
end
|
8
|
-
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("spec_helper", __dir__)
|
2
4
|
|
3
5
|
module Danger
|
4
6
|
describe Danger::DangerGitlabReviewbot do
|
@@ -11,25 +13,24 @@ module Danger
|
|
11
13
|
#
|
12
14
|
describe "with Dangerfile" do
|
13
15
|
before do
|
14
|
-
testing_env.each { |k,v| ENV[k] =
|
16
|
+
testing_env.each { |k, v| ENV[k] = v.to_s }
|
15
17
|
|
16
18
|
@dangerfile = testing_dangerfile
|
17
19
|
@plugin = @dangerfile.gitlab_reviewbot
|
18
20
|
@strategy_mock = instance_double(Danger::AssignStrategies::Strategy)
|
19
21
|
allow(Danger::AssignStrategies::RandomStrategy).to receive(:new).and_return(@strategy_mock)
|
20
|
-
allow(@strategy_mock).to receive(:group_name=).with(
|
22
|
+
allow(@strategy_mock).to receive(:group_name=).with("tech/ios")
|
21
23
|
@plugin.strategy = Danger::AssignStrategies::RandomStrategy
|
22
|
-
@plugin.gitlab_group =
|
23
|
-
|
24
|
+
@plugin.gitlab_group = "tech/ios"
|
24
25
|
end
|
25
26
|
|
26
27
|
it "Assign one reviewer" do
|
27
|
-
expect(@strategy_mock).to receive(:assign!).with(1).and_return([
|
28
|
+
expect(@strategy_mock).to receive(:assign!).with(1).and_return(["Sam"])
|
28
29
|
|
29
30
|
@plugin.assign!
|
30
31
|
end
|
31
32
|
it "Assign one reviewer" do
|
32
|
-
expect(@strategy_mock).to receive(:assign!).with(1).and_return([
|
33
|
+
expect(@strategy_mock).to receive(:assign!).with(1).and_return(["Sam"])
|
33
34
|
|
34
35
|
@plugin.assign!
|
35
36
|
end
|
@@ -37,7 +38,7 @@ module Danger
|
|
37
38
|
it "Assign multiple reviewers" do
|
38
39
|
@plugin.assignees_amount = 2
|
39
40
|
|
40
|
-
expect(@strategy_mock).to receive(:assign!).with(2).and_return([
|
41
|
+
expect(@strategy_mock).to receive(:assign!).with(2).and_return(["Sam, Nic"])
|
41
42
|
|
42
43
|
@plugin.assign!
|
43
44
|
end
|
@@ -46,18 +47,16 @@ module Danger
|
|
46
47
|
expect(@strategy_mock).to receive(:excluded_users=)
|
47
48
|
expect(@strategy_mock).to receive(:excluded_users).and_return([])
|
48
49
|
|
49
|
-
@plugin.strategy_excluded_users = [
|
50
|
-
@plugin.strategy_excluded_users <<
|
51
|
-
|
50
|
+
@plugin.strategy_excluded_users = ["Tom"]
|
51
|
+
@plugin.strategy_excluded_users << "Sam"
|
52
52
|
end
|
53
53
|
|
54
|
-
[
|
54
|
+
["CI_PROJECT_ID", "CI_MERGE_REQUEST_IID"].each do |var|
|
55
55
|
it "Fails when required #{var} variables are not available" do
|
56
56
|
ENV[var] = nil
|
57
|
-
expect{@plugin.assign!}.to raise_error(RuntimeError)
|
57
|
+
expect { @plugin.assign! }.to raise_error(RuntimeError)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
@@ -1,15 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("spec_helper", __dir__)
|
2
4
|
|
3
5
|
module Danger
|
4
6
|
describe Danger::AssignStrategies::LeastBusyStrategy do
|
5
7
|
before do
|
6
|
-
testing_env.each { |k,v| ENV[k] =
|
8
|
+
testing_env.each { |k, v| ENV[k] = v.to_s }
|
7
9
|
@dangerfile = testing_dangerfile
|
8
10
|
|
9
|
-
@sam = Gitlab::User.new(1,
|
10
|
-
@tom = Gitlab::User.new(2,
|
11
|
-
@nic = Gitlab::User.new(3,
|
12
|
-
@luke = Gitlab::User.new(4,
|
11
|
+
@sam = Gitlab::User.new(1, "Sam")
|
12
|
+
@tom = Gitlab::User.new(2, "Tom")
|
13
|
+
@nic = Gitlab::User.new(3, "Nic")
|
14
|
+
@luke = Gitlab::User.new(4, "Luke")
|
13
15
|
|
14
16
|
@mock_client = double(Gitlab::Client)
|
15
17
|
@author = @nic
|
@@ -18,9 +20,8 @@ module Danger
|
|
18
20
|
allow(@mock_client).to receive(:fetch_author_for_mr).and_return(@author)
|
19
21
|
allow(@mock_client).to receive(:fetch_users_for_group).with("tech/ios").and_return(@members)
|
20
22
|
|
21
|
-
@strategy = AssignStrategies::LeastBusyStrategy.new(client: @mock_client, project: 10,
|
23
|
+
@strategy = AssignStrategies::LeastBusyStrategy.new(client: @mock_client, project: 10, mr_iid: 110)
|
22
24
|
@strategy.group_name = "tech/ios"
|
23
|
-
|
24
25
|
end
|
25
26
|
|
26
27
|
it "Assign the one least busy" do
|
@@ -92,16 +93,17 @@ module Danger
|
|
92
93
|
@strategy.assign!(1)
|
93
94
|
end
|
94
95
|
|
96
|
+
# TODO: This should go up to the superclass for testing
|
95
97
|
it "honours excluded users" do
|
96
98
|
allow(@mock_client).to receive(:fetch_mr_reviewers).with(10, 110).and_return([])
|
97
|
-
@tom.review_count =
|
99
|
+
@tom.review_count = 0
|
98
100
|
@sam.review_count = 4
|
99
101
|
@luke.review_count = 3
|
100
|
-
users_with_pending_mr_review = [@author, @sam, @
|
102
|
+
users_with_pending_mr_review = [@author, @sam, @luke]
|
101
103
|
expect(@mock_client).to receive(:users_with_pending_mr_review).and_return(users_with_pending_mr_review)
|
102
104
|
|
103
|
-
allow(@mock_client).to receive(:find_user_with_username).with(
|
104
|
-
@strategy.excluded_users = [
|
105
|
+
allow(@mock_client).to receive(:find_user_with_username).with("Tom").and_return([@tom])
|
106
|
+
@strategy.excluded_users = ["Tom"]
|
105
107
|
|
106
108
|
expect(@mock_client).to receive(:assign_mr_to_users) do |project, mr, users|
|
107
109
|
expect(project).to be == 10
|
@@ -112,6 +114,22 @@ module Danger
|
|
112
114
|
@strategy.assign!(1)
|
113
115
|
end
|
114
116
|
|
117
|
+
it "Raises error when excluded_user is invalid" do
|
118
|
+
allow(@mock_client).to receive(:fetch_mr_reviewers).with(10, 110).and_return([])
|
119
|
+
|
120
|
+
allow(@mock_client).to receive(:find_user_with_username).with("WrongTom").and_return([])
|
121
|
+
@strategy.excluded_users = ["WrongTom"]
|
122
|
+
|
123
|
+
expect { @strategy.assign!(1) }.to raise_error("ERROR: Invalid username WrongTom among excluded_users")
|
124
|
+
end
|
125
|
+
|
126
|
+
# it "test" do
|
127
|
+
# strategy = AssignStrategies::LeastBusyStrategy.new(client: @dangerfile.gitlab.api, project: 346, mr_iid: 960)
|
128
|
+
# strategy.excluded_users << 'fabio.gallonetto'
|
129
|
+
# strategy.group_name = 'tech/ios'
|
130
|
+
# require 'pry'
|
131
|
+
# binding.pry
|
132
|
+
# puts strategy.assign!(2)
|
133
|
+
# end
|
115
134
|
end
|
116
135
|
end
|
117
|
-
|
@@ -1,17 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("spec_helper", __dir__)
|
2
4
|
|
3
5
|
module Danger
|
4
6
|
describe Danger::AssignStrategies::RandomStrategy do
|
5
7
|
before do
|
6
|
-
testing_env.each { |k,v| ENV[k] =
|
8
|
+
testing_env.each { |k, v| ENV[k] = v.to_s }
|
7
9
|
@dangerfile = testing_dangerfile
|
8
10
|
|
9
|
-
@sam = Gitlab::User.new(1,
|
10
|
-
@tom = Gitlab::User.new(2,
|
11
|
-
@nic = Gitlab::User.new(3,
|
12
|
-
@luke = Gitlab::User.new(4,
|
13
|
-
@lei = Gitlab::User.new(5,
|
14
|
-
|
11
|
+
@sam = Gitlab::User.new(1, "Sam")
|
12
|
+
@tom = Gitlab::User.new(2, "Tom")
|
13
|
+
@nic = Gitlab::User.new(3, "Nic")
|
14
|
+
@luke = Gitlab::User.new(4, "Luke")
|
15
|
+
@lei = Gitlab::User.new(5, "Lei")
|
15
16
|
|
16
17
|
@mock_client = double(Gitlab::Client)
|
17
18
|
@author = @lei
|
@@ -19,7 +20,7 @@ module Danger
|
|
19
20
|
allow(@mock_client).to receive(:fetch_author_for_mr).and_return(@author)
|
20
21
|
allow(@mock_client).to receive(:fetch_users_for_group).with("tech/ios").and_return(@members)
|
21
22
|
|
22
|
-
@strategy = AssignStrategies::RandomStrategy.new(client: @mock_client, project: 10,
|
23
|
+
@strategy = AssignStrategies::RandomStrategy.new(client: @mock_client, project: 10, mr_iid: 110)
|
23
24
|
@strategy.group_name = "tech/ios"
|
24
25
|
end
|
25
26
|
|
@@ -56,7 +57,5 @@ module Danger
|
|
56
57
|
|
57
58
|
@strategy.assign!(2)
|
58
59
|
end
|
59
|
-
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "pathname"
|
2
|
-
ROOT = Pathname.new(File.expand_path("
|
4
|
+
ROOT = Pathname.new(File.expand_path("..", __dir__))
|
3
5
|
$:.unshift((ROOT + "lib").to_s)
|
4
6
|
$:.unshift((ROOT + "spec").to_s)
|
5
7
|
|
@@ -9,7 +11,7 @@ require "pry"
|
|
9
11
|
require "rspec"
|
10
12
|
require "danger"
|
11
13
|
|
12
|
-
if `git remote -v` ==
|
14
|
+
if `git remote -v` == ""
|
13
15
|
puts "You cannot run tests without setting a local git remote on this repo"
|
14
16
|
puts "It's a weird side-effect of Danger's internals."
|
15
17
|
exit(0)
|
@@ -50,14 +52,14 @@ end
|
|
50
52
|
# running a PR on TravisCI
|
51
53
|
def testing_env
|
52
54
|
{
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
"CI_MERGE_REQUEST_IID" => "549",
|
56
|
+
"CI_MERGE_REQUEST_PROJECT_PATH" => "...",
|
57
|
+
"CI_MERGE_REQUEST_PROJECT_URL" => "...",
|
58
|
+
"DANGER_GITLAB_HOST" => "git.curve.tools", # This needs to be the same as where the repo is stored due to Danger internals :facepalm:
|
59
|
+
"CI_API_V4_URL" => "https://git.curve.tools/api/v4",
|
60
|
+
"CI_PROJECT_ID" => "346",
|
59
61
|
"GITLAB_CI" => true,
|
60
|
-
"DANGER_GITLAB_API_TOKEN" => "
|
62
|
+
"DANGER_GITLAB_API_TOKEN" => "jgUhHSk2vGNYYFr3QsPq"
|
61
63
|
}
|
62
64
|
end
|
63
65
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Gallonetto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -200,6 +200,7 @@ extensions: []
|
|
200
200
|
extra_rdoc_files: []
|
201
201
|
files:
|
202
202
|
- ".gitignore"
|
203
|
+
- ".gitlab-ci.yml"
|
203
204
|
- ".rubocop.yml"
|
204
205
|
- Gemfile
|
205
206
|
- Gemfile.lock
|
@@ -221,7 +222,7 @@ files:
|
|
221
222
|
- spec/least_busy_strategy_spec.rb
|
222
223
|
- spec/random_strategy_spec.rb
|
223
224
|
- spec/spec_helper.rb
|
224
|
-
homepage: https://
|
225
|
+
homepage: https://git.curve.tools/fabio.gallonetto/danger-gitlab_reviewbot
|
225
226
|
licenses:
|
226
227
|
- MIT
|
227
228
|
metadata: {}
|