danger-mention 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a931bd08ddadf8a06b2782b68f0ea90578a886ea
4
+ data.tar.gz: 663f78d18918c436f6cd52bdb311c46385d8cb84
5
+ SHA512:
6
+ metadata.gz: b7b3307926962942d07d84dc7e01572f1d60c8bb54c85a1252b4580fc1a8bcdcb37716332ca50bc6f22115fe96d87fab1527942ef0b98367f2078c1ba0b80fe2
7
+ data.tar.gz: 424e61736c5ff435b5fec6fc936dd0d88ac53719b187188afcc8aa95d66c4b44e7594f84ff305d976d2208444eb3c2684b9574048264b6cebff9dca91f019108
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-mention (0.1)
5
+ danger
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.4.0)
11
+ claide (1.0.0)
12
+ claide-plugins (0.9.0)
13
+ cork (~> 0)
14
+ nap (~> 1.0)
15
+ open4 (~> 1.3)
16
+ colored (1.2)
17
+ cork (0.1.0)
18
+ colored (~> 1.2)
19
+ danger (0.10.0)
20
+ claide (~> 1.0)
21
+ claide-plugins (~> 0.9)
22
+ colored (~> 1.2)
23
+ cork (~> 0.1)
24
+ faraday (~> 0)
25
+ faraday-http-cache (~> 1.0)
26
+ git (~> 1)
27
+ octokit (~> 4.2)
28
+ redcarpet (~> 3.3)
29
+ terminal-table (~> 1)
30
+ faraday (0.9.2)
31
+ multipart-post (>= 1.2, < 3)
32
+ faraday-http-cache (1.3.0)
33
+ faraday (~> 0.8)
34
+ git (1.3.0)
35
+ multipart-post (2.0.0)
36
+ nap (1.1.0)
37
+ octokit (4.3.0)
38
+ sawyer (~> 0.7.0, >= 0.5.3)
39
+ open4 (1.3.4)
40
+ rake (10.5.0)
41
+ redcarpet (3.3.4)
42
+ sawyer (0.7.0)
43
+ addressable (>= 2.3.5, < 2.5)
44
+ faraday (~> 0.8, < 0.10)
45
+ terminal-table (1.6.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.3)
52
+ danger-mention!
53
+ rake (~> 10.0)
54
+
55
+ BUNDLED WITH
56
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Wojtek Lukaszuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Danger Mention
2
+
3
+ A [Danger](https://github.com/danger/danger) plugin to automatically mention potential reviewers on pull requests.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Gemfile:
8
+
9
+ ```rb
10
+ gem 'danger-mention'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ The easiest way to use is just add this to your Dangerfile:
16
+
17
+ ```rb
18
+ mention.run
19
+ ```
20
+
21
+ Additionally you can set up maximum number of people to ping in the PR message, regexes of ignored files and list of users that will never be mentioned.
22
+
23
+ ```rb
24
+ mention.run(2, [".*.h"], ["wojteklu"])
25
+ ```
26
+
27
+ ## License
28
+
29
+ This project is licensed under the terms of the MIT license. See the LICENSE file.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-mention'
8
+ spec.version = DangerMention::VERSION
9
+ spec.authors = ['Wojtek Lukaszuk']
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}
13
+ spec.homepage = 'https://github.com/wojteklu/danger-mention'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'danger'
20
+
21
+ # General ruby development
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+
25
+ end
@@ -0,0 +1,108 @@
1
+ require 'open-uri'
2
+
3
+ module Danger
4
+
5
+ # Automatically mention potential reviewers on pull requests.
6
+ # It downloads and parses the blame information of changed files
7
+ # to figure out who may be a good reviewer.
8
+ #
9
+ # @example Specifying max reviewers.
10
+ #
11
+ # # Find maximum two reviewers without specifying
12
+ # # ignored files and users
13
+ # mention.run(2, [], [])
14
+ #
15
+ class DangerMention < Plugin
16
+
17
+ # Mention potential reviewers.
18
+ #
19
+ # @param Integer max_reviewers
20
+ # Maximum number of people to ping in the PR message, default is 3.
21
+ # @param [String] file_blacklist
22
+ # Regexes of ignored files.
23
+ # @param [String] user_blacklist
24
+ # List of users that will never be mentioned.
25
+ # @return [void]
26
+ #
27
+ def run(max_reviewers = 3, file_blacklist = [], user_blacklist = [])
28
+ files = select_files(file_blacklist)
29
+ return if files.empty?
30
+
31
+ authors = {}
32
+ compose_urls(files).each do |url|
33
+ result = parse_blame(url)
34
+ authors.merge!(result) { |_, m, n| m + n }
35
+ end
36
+
37
+ reviewers = find_reviewers(authors, user_blacklist, max_reviewers)
38
+
39
+ if reviewers.count > 0
40
+ reviewers = reviewers.map { |r| '@' + r }
41
+
42
+ result = format('By analyzing the blame information on this pull '\
43
+ 'request, we identified %s to be potential reviewer%s.',
44
+ reviewers.join(', '), reviewers.count > 1 ? 's' : '')
45
+
46
+ markdown result
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def select_files(file_blacklist)
53
+ files = modified_files + deleted_files
54
+ file_blacklist = file_blacklist.map { |f| /#{f}/ }
55
+ re = Regexp.union(file_blacklist)
56
+
57
+ files = files.select { |f| !f.match(re) }
58
+
59
+ # select just 6 random files
60
+ # gonna be changed in next version
61
+ files[0...6]
62
+ end
63
+
64
+
65
+ def compose_urls(files)
66
+ host = 'https://' + env.request_source.host
67
+ repo_slug = env.ci_source.repo_slug
68
+ path = host + '/' + repo_slug + '/' + 'blame' + '/' + branch_for_base
69
+
70
+ urls = []
71
+ files.each do |file|
72
+ urls << path + '/' + file
73
+ end
74
+
75
+ urls
76
+ end
77
+
78
+ def parse_blame(url)
79
+ regex = %r{(?:rel="(?:author|contributor)">([^<]+)</a> authored|(?:<tr class="blame-line">))}
80
+ source = open(url, &:read)
81
+ matches = source.scan(regex).to_a.flatten
82
+
83
+ current = nil
84
+ lines = {}
85
+
86
+ matches.each do |user|
87
+ if user
88
+ current = user
89
+ else
90
+ lines[current] = lines[current].to_i + 1
91
+ end
92
+ end
93
+
94
+ lines
95
+ end
96
+
97
+ def find_reviewers(users, user_blacklist, max_reviewers)
98
+ user_blacklist << pr_author
99
+ users = users.select { |k, _| !user_blacklist.include? k }
100
+
101
+ max_values = users.values.sort.reverse[0..max_reviewers]
102
+ users = users.select { |_, v| max_values.include? v }
103
+
104
+ users.keys
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,4 @@
1
+ module DangerMention
2
+ VERSION = "0.1"
3
+ DESCRIPTION = "Danger plugin to automatically mention potential reviewers on pull requests"
4
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-mention
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Wojtek Lukaszuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Danger plugin to automatically mention potential reviewers on pull requests.
56
+ email:
57
+ - wojciech.lukaszuk@icloud.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - danger-mention.gemspec
69
+ - lib/danger_plugin.rb
70
+ - lib/version.rb
71
+ homepage: https://github.com/wojteklu/danger-mention
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Danger plugin to automatically mention potential reviewers on pull requests
95
+ test_files: []