danger-reviewer 0.0.1 → 0.0.2

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: 4211e52ae29704d83d1efac4c6689a64de52b791863d83091a596dc3efca574e
4
- data.tar.gz: c188ad6c6a539941a7d2c8b5689e7b9d36f82f348f1638f27091e5a66b06abdd
3
+ metadata.gz: 646b0e5035c84b5a44fa8d5e9d1cf595c41b77d2cefc2ee0bfc4247dc75e090c
4
+ data.tar.gz: 9d77d32e0e27a25953c38049d6f7a69f0e2aa62d779f97eec00e348a916e979d
5
5
  SHA512:
6
- metadata.gz: 36e3f6c591b11b494db7327a0939747e7f3682b463781ece7d9ac60329e191a6614bdaaec7f631b52dd75a1b8c4db42f1a67632219ee35d1472e2a32b5fe14c9
7
- data.tar.gz: 6b514184d2ccfa52690081672f64cbdd8449c95a38f0ed748cc0f2a1e031071e0704e551a1fe2b6c35f5fffc5ac85808cb5b0c18633b6064eecfea512650fde4
6
+ metadata.gz: 1dc2417d16f930402640e6df18dc1ba35e69da0c5cf9888363c58637afcce78192f765cab32c54f7163336895920c3c3b181746c8b66270c69cc72ef5db64270
7
+ data.tar.gz: 88133eef61b9fa14c7d8aa28bdd4a6ecb154b7eee6d4b9a4dd524b03c6c9cabc3859d9dd567ae7bd26f6b935550312f6a39c4f3a833a787c5a6ec24efe53213a
@@ -1,3 +1,3 @@
1
1
  module Reviewer
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
@@ -13,7 +13,7 @@ module Danger
13
13
 
14
14
  authors = find_authors
15
15
  members = team_members(team)
16
- reviewers = find_reviewers((authors & members), user_blacklist, (max_reviewers - current.count))
16
+ reviewers = find_reviewers((authors & members), members, user_blacklist, (max_reviewers - current.count))
17
17
 
18
18
  request_reviews(reviewers)
19
19
  end
@@ -21,8 +21,6 @@ module Danger
21
21
  def request_reviews(reviewers)
22
22
  owner, repo = env.ci_source.repo_slug.split('/')
23
23
 
24
- require 'pry'; binding.pry
25
-
26
24
  uri = URI.parse("https://api.github.com/repos/#{owner}/#{repo}/pulls/#{github.pr_json[:number]}/requested_reviewers")
27
25
  header = {'Content-Type': 'text/json', 'Authorization': "token #{ENV['DANGER_GITHUB_API_TOKEN']}" }
28
26
 
@@ -44,6 +42,7 @@ module Danger
44
42
 
45
43
  git.modified_files.each do |file|
46
44
  result = GitHub::Client.query(GitHub::BlameQuery, variables: { repository: repo, owner: owner, ref: branch, file: file })
45
+ next if result.data.repository.ref.nil?
47
46
  result.data.repository.ref.target.blame.ranges.each do |range|
48
47
  lines = (range.ending_line - range.starting_line) + 1
49
48
  users[range.commit.author.user.login] += lines unless range.commit.author.user.nil?
@@ -53,13 +52,21 @@ module Danger
53
52
  users.keys
54
53
  end
55
54
 
56
- def find_reviewers(users, user_blacklist, max_reviewers)
55
+ def find_reviewers(authors, members, user_blacklist, max_reviewers)
57
56
  user_blacklist << github.pr_author
58
57
 
59
- users = users - user_blacklist
60
- users = users.sort_by { |_, value| value }.reverse
58
+ reviewers = []
59
+
60
+ authors = authors - user_blacklist
61
+ authors = authors.sort_by { |_, value| value }.reverse
62
+
63
+ reviewers += authors[0...max_reviewers]
64
+
65
+ if reviewers.count < max_reviewers
66
+ reviewers += (members - reviewers).sample(max_reviewers - reviewers.count)
67
+ end
61
68
 
62
- users[0...max_reviewers]
69
+ reviewers
63
70
  end
64
71
 
65
72
  def current_reviewers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-reviewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikko Kokkonen