danger-mention 0.1 → 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
  SHA1:
3
- metadata.gz: a931bd08ddadf8a06b2782b68f0ea90578a886ea
4
- data.tar.gz: 663f78d18918c436f6cd52bdb311c46385d8cb84
3
+ metadata.gz: 8297f54a5ea709aa67d5c032f4bd4b7c203abe7d
4
+ data.tar.gz: fa6c8849b61ee0e0a5bbdff94ef06070b3301097
5
5
  SHA512:
6
- metadata.gz: b7b3307926962942d07d84dc7e01572f1d60c8bb54c85a1252b4580fc1a8bcdcb37716332ca50bc6f22115fe96d87fab1527942ef0b98367f2078c1ba0b80fe2
7
- data.tar.gz: 424e61736c5ff435b5fec6fc936dd0d88ac53719b187188afcc8aa95d66c4b44e7594f84ff305d976d2208444eb3c2684b9574048264b6cebff9dca91f019108
6
+ metadata.gz: c2a807ac485bce802c103cdf982b988ee847941853a8027ce0174bc5680a3047a849120c71965a848a2ccb9b326d4c9c4ba361a9397a1deb5305301009ea2cfc
7
+ data.tar.gz: e253ef9e4789852d7b642f1c1d3aed67f267519b59119a509d5dfa3bff14e8dc6debfe89466322c40aac848a2fbd4e28071952906940b41999ac9000349f4bd9
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'rspec', '~> 3.4'
data/Gemfile.lock CHANGED
@@ -27,6 +27,7 @@ GEM
27
27
  octokit (~> 4.2)
28
28
  redcarpet (~> 3.3)
29
29
  terminal-table (~> 1)
30
+ diff-lcs (1.2.5)
30
31
  faraday (0.9.2)
31
32
  multipart-post (>= 1.2, < 3)
32
33
  faraday-http-cache (1.3.0)
@@ -39,6 +40,19 @@ GEM
39
40
  open4 (1.3.4)
40
41
  rake (10.5.0)
41
42
  redcarpet (3.3.4)
43
+ rspec (3.5.0)
44
+ rspec-core (~> 3.5.0)
45
+ rspec-expectations (~> 3.5.0)
46
+ rspec-mocks (~> 3.5.0)
47
+ rspec-core (3.5.1)
48
+ rspec-support (~> 3.5.0)
49
+ rspec-expectations (3.5.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.5.0)
52
+ rspec-mocks (3.5.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.5.0)
55
+ rspec-support (3.5.0)
42
56
  sawyer (0.7.0)
43
57
  addressable (>= 2.3.5, < 2.5)
44
58
  faraday (~> 0.8, < 0.10)
@@ -51,6 +65,7 @@ DEPENDENCIES
51
65
  bundler (~> 1.3)
52
66
  danger-mention!
53
67
  rake (~> 10.0)
68
+ rspec (~> 3.4)
54
69
 
55
70
  BUNDLED WITH
56
71
  1.11.2
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = DangerMention::VERSION
9
9
  spec.authors = ['Wojtek Lukaszuk']
10
10
  spec.email = ['wojciech.lukaszuk@icloud.com']
11
- spec.description = %q{Danger plugin to automatically mention potential reviewers on pull requests.}
12
- spec.summary = %q{Danger plugin to automatically mention potential reviewers on pull requests}
11
+ spec.description = 'Danger plugin to automatically mention potential reviewers on pull requests.'
12
+ spec.summary = 'Danger plugin to automatically mention potential reviewers on pull requests.'
13
13
  spec.homepage = 'https://github.com/wojteklu/danger-mention'
14
14
  spec.license = 'MIT'
15
15
 
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'bundler', '~> 1.3'
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
24
 
25
+ # Testing support
26
+ spec.add_development_dependency 'rspec', '~> 3.4'
27
+
25
28
  end
data/lib/danger_plugin.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'open-uri'
2
+ require_relative 'finder'
2
3
 
3
4
  module Danger
4
5
 
@@ -47,21 +48,16 @@ module Danger
47
48
  end
48
49
  end
49
50
 
50
- private
51
-
52
51
  def select_files(file_blacklist)
53
- files = modified_files + deleted_files
52
+ files = Finder.parse(env.scm.diff)
53
+
54
54
  file_blacklist = file_blacklist.map { |f| /#{f}/ }
55
55
  re = Regexp.union(file_blacklist)
56
-
57
56
  files = files.select { |f| !f.match(re) }
58
57
 
59
- # select just 6 random files
60
- # gonna be changed in next version
61
- files[0...6]
58
+ files[0...3]
62
59
  end
63
60
 
64
-
65
61
  def compose_urls(files)
66
62
  host = 'https://' + env.request_source.host
67
63
  repo_slug = env.ci_source.repo_slug
@@ -97,11 +93,9 @@ module Danger
97
93
  def find_reviewers(users, user_blacklist, max_reviewers)
98
94
  user_blacklist << pr_author
99
95
  users = users.select { |k, _| !user_blacklist.include? k }
96
+ users = users.sort_by { |_, value| value }.reverse
100
97
 
101
- max_values = users.values.sort.reverse[0..max_reviewers]
102
- users = users.select { |_, v| max_values.include? v }
103
-
104
- users.keys
98
+ users[0...max_reviewers].map { |u| u[0] }
105
99
  end
106
100
 
107
101
  end
data/lib/finder.rb ADDED
@@ -0,0 +1,37 @@
1
+ class FileInfo
2
+ attr_accessor :name
3
+ attr_accessor :changed_lines
4
+
5
+ def initialize(name, changed_lines)
6
+ self.name = name
7
+ self.changed_lines = changed_lines
8
+ end
9
+ end
10
+
11
+ class Finder
12
+ def self.parse(diff)
13
+ files = []
14
+
15
+ diff.each do |f|
16
+ name = f.path
17
+
18
+ if f.type != 'modified'
19
+ files << FileInfo.new(name, 0)
20
+ next
21
+ end
22
+
23
+ lines = f.patch.split(/\n/).reject(&:empty?)
24
+
25
+ count = 0
26
+ lines[4..-1].each do |line|
27
+ count += 1 if line.start_with?('-', '+')
28
+ end
29
+
30
+ files << FileInfo.new(name, count)
31
+ end
32
+
33
+ files = files.sort_by(&:changed_lines).reverse
34
+ files.map(&:name)
35
+ end
36
+
37
+ end
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module DangerMention
2
- VERSION = "0.1"
3
- DESCRIPTION = "Danger plugin to automatically mention potential reviewers on pull requests"
2
+ VERSION = '0.2'
3
+ DESCRIPTION = 'Danger plugin to automatically mention potential reviewers on pull requests'
4
4
  end
@@ -0,0 +1,92 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe DangerMention do
5
+ before do
6
+ @mention = testing_dangerfile.mention
7
+ end
8
+
9
+ it 'is a plugin' do
10
+ expect(Danger::DangerMention < Danger::Plugin).to be_truthy
11
+ end
12
+
13
+ describe :select_files do
14
+ before do
15
+ modified_files = (1..2).to_a.map { |i| format('M%d', i) }
16
+ deleted_files = (1..2).to_a.map { |i| format('D%d', i) }
17
+ allow(Finder).to receive(:parse).and_return(modified_files + deleted_files)
18
+ end
19
+
20
+ it 'takes first 3 modified files' do
21
+ files = @mention.select_files([])
22
+ expect(files).to eq %w(M1 M2 D1)
23
+ end
24
+
25
+ it 'does not return blacklisted files' do
26
+ files = @mention.select_files(['M.*'])
27
+ expect(files).to eq %w(D1 D2)
28
+ end
29
+ end
30
+
31
+ describe :compose_urls do
32
+ before do
33
+ allow(@mention).to receive_message_chain('env.request_source.host').and_return('host')
34
+ allow(@mention).to receive_message_chain('env.ci_source.repo_slug').and_return('slug')
35
+ allow(@mention).to receive_message_chain('branch_for_base').and_return('branch')
36
+ end
37
+
38
+ it 'composes urls for files' do
39
+ files = (1..4).to_a.map { |i| format('M%d', i) }
40
+ expected = files.map { |f| format('https://host/slug/blame/branch/%s', f) }
41
+ results = @mention.compose_urls(files)
42
+ expect(results).to eq expected
43
+ end
44
+
45
+ describe :compose_urls do
46
+ before do
47
+ allow(@mention).to receive(:pr_author).and_return('author')
48
+ end
49
+
50
+ it 'finds potential reviewers' do
51
+ users = Hash[(1..10).to_a.collect { |v| [format('user%s', v), v] }]
52
+ expected = %w(user10 user9 user8)
53
+ results = @mention.find_reviewers(users, [], 3)
54
+
55
+ expect(results).to eq expected
56
+ end
57
+
58
+ it 'does not return pr author' do
59
+ users = Hash['author' => 1]
60
+ results = @mention.find_reviewers(users, [], 3)
61
+
62
+ expect(results).to eq []
63
+ end
64
+
65
+ it 'does not return blacklisted users' do
66
+ users = Hash['user10' => 1]
67
+ results = @mention.find_reviewers(users, ['user10'], 1)
68
+
69
+ expect(results).to eq []
70
+ end
71
+ end
72
+
73
+ describe :run do
74
+ before do
75
+ allow(@mention).to receive(:select_files).and_return(%w(M1 M2))
76
+ allow(@mention).to receive(:parse_blame).and_return({})
77
+ allow(@mention).to receive(:find_reviewers).and_return(%w(user1 user2))
78
+ end
79
+
80
+ it 'mentions potential reviewers' do
81
+ @mention.run
82
+ output = @mention.status_report[:markdowns].first
83
+
84
+ expect(output).to_not be_empty
85
+ expect(output).to include('@user1')
86
+ expect(output).to include('@user2')
87
+ end
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,31 @@
1
+ require 'pathname'
2
+
3
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
4
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
5
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
6
+
7
+ RSpec.configure do |config|
8
+ # Use color in STDOUT
9
+ config.color = true
10
+ end
11
+
12
+ require 'danger'
13
+ require 'cork'
14
+ require 'danger_plugin'
15
+
16
+ def testing_ui
17
+ Cork::Board.new(silent: true)
18
+ end
19
+
20
+ def testing_env
21
+ {
22
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
23
+ 'TRAVIS_PULL_REQUEST' => '1',
24
+ 'TRAVIS_REPO_SLUG' => 'test'
25
+ }
26
+ end
27
+
28
+ def testing_dangerfile
29
+ env = Danger::EnvironmentManager.new(testing_env)
30
+ Danger::Dangerfile.new(env, testing_ui)
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-mention
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojtek Lukaszuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2016-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
55
69
  description: Danger plugin to automatically mention potential reviewers on pull requests.
56
70
  email:
57
71
  - wojciech.lukaszuk@icloud.com
@@ -67,7 +81,10 @@ files:
67
81
  - Rakefile
68
82
  - danger-mention.gemspec
69
83
  - lib/danger_plugin.rb
84
+ - lib/finder.rb
70
85
  - lib/version.rb
86
+ - spec/danger_plugin_spec.rb
87
+ - spec/spec_helper.rb
71
88
  homepage: https://github.com/wojteklu/danger-mention
72
89
  licenses:
73
90
  - MIT
@@ -91,5 +108,5 @@ rubyforge_project:
91
108
  rubygems_version: 2.4.6
92
109
  signing_key:
93
110
  specification_version: 4
94
- summary: Danger plugin to automatically mention potential reviewers on pull requests
111
+ summary: Danger plugin to automatically mention potential reviewers on pull requests.
95
112
  test_files: []