danger-pr_reviewers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adedda6f14b9ffb2b09b6a915abcae35273e2522
4
+ data.tar.gz: ee567f93c881ffb077b1d01a7bd04ffb5a0b14ff
5
+ SHA512:
6
+ metadata.gz: bed27210f7b7982dbf5df2bd4d8141c256e2477a21a87373abb6acc72a26fe59e2ea8846d202f939cf4e3040c3758b90783638652a30d3d56237883bb01e7264
7
+ data.tar.gz: 9f1d6405f37cc321d2a3b6d34cab898e26bb7306570e64450c62b0524216481bd6746ed2228cd2a6f84a16ab886ceae79b8b4a38ef690cfa2c319e7baa9ffc25
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ Include:
3
+ - Rakefile
4
+ Exclude:
5
+ - vendor/**/*
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'Rakefile'
10
+ - '**/*.rake'
11
+ - 'spec/**/*.rb'
12
+
13
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,75 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-03-28 20:55:23 +0200 using RuboCop version 0.48.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 22
12
+
13
+ # Offense count: 109
14
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
15
+ # URISchemes: http, https
16
+ Metrics/LineLength:
17
+ Max: 254
18
+
19
+ # Offense count: 3
20
+ # Configuration parameters: CountComments.
21
+ Metrics/MethodLength:
22
+ Max: 14
23
+
24
+ # Offense count: 3
25
+ Style/Documentation:
26
+ Exclude:
27
+ - 'spec/**/*'
28
+ - 'test/**/*'
29
+ - 'lib/changelog/config.rb'
30
+ - 'lib/changelog/plugin.rb'
31
+
32
+ # Offense count: 3
33
+ Style/DoubleNegation:
34
+ Exclude:
35
+ - 'lib/changelog/changelog_file.rb'
36
+
37
+ # Offense count: 4
38
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
39
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
40
+ Style/FileName:
41
+ Exclude:
42
+ - 'Dangerfile'
43
+ - 'Gemfile'
44
+ - 'Guardfile'
45
+ - 'danger-changelog.gemspec'
46
+
47
+ # Offense count: 2
48
+ # Cop supports --auto-correct.
49
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
50
+ # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
51
+ Style/IndentHeredoc:
52
+ Exclude:
53
+ - 'lib/changelog/plugin.rb'
54
+
55
+ # Offense count: 1
56
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
57
+ # SupportedStyles: module_function, extend_self
58
+ Style/ModuleFunction:
59
+ Exclude:
60
+ - 'lib/changelog/config.rb'
61
+
62
+ # Offense count: 2
63
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
64
+ # NamePrefix: is_, has_, have_
65
+ # NamePrefixBlacklist: is_, has_, have_
66
+ # NameWhitelist: is_a?
67
+ Style/PredicateName:
68
+ Exclude:
69
+ - 'spec/**/*'
70
+ - 'lib/changelog/plugin.rb'
71
+
72
+ Style/FileName:
73
+ Include:
74
+ - 'lib/**/*'
75
+ - 'spec/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.0
8
+ - 2.1.3
9
+ - 2.3.1
10
+
11
+ script:
12
+ - bundle exec rake spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## Changelog
2
+
3
+
4
+ ### 0.1.0 (27/06/2017)
5
+
6
+ * [#1](https://github.com/conichiGMBH/danger-pr_reviewers/pull/1): Add gem documentation - [@antondomashnev](https://github.com/antondomashnev).
data/Dangerfile ADDED
@@ -0,0 +1 @@
1
+ changelog.check
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'danger-changelog', '~> 0.1'
6
+ gem 'danger', '~> 5.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,139 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-pr_reviewers (0.1.0)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.1)
11
+ public_suffix (~> 2.0, >= 2.0.2)
12
+ ast (2.3.0)
13
+ claide (1.0.2)
14
+ claide-plugins (0.9.2)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.1)
19
+ colored2 (3.1.2)
20
+ cork (0.3.0)
21
+ colored2 (~> 3.1)
22
+ danger (5.3.1)
23
+ claide (~> 1.0)
24
+ claide-plugins (>= 0.9.2)
25
+ colored2 (~> 3.1)
26
+ cork (~> 0.1)
27
+ faraday (~> 0.9)
28
+ faraday-http-cache (~> 1.0)
29
+ git (~> 1)
30
+ kramdown (~> 1.5)
31
+ octokit (~> 4.2)
32
+ terminal-table (~> 1)
33
+ danger-changelog (0.2.0)
34
+ danger-plugin-api (~> 1.0)
35
+ danger-plugin-api (1.0.0)
36
+ danger (> 2.0)
37
+ diff-lcs (1.3)
38
+ faraday (0.12.1)
39
+ multipart-post (>= 1.2, < 3)
40
+ faraday-http-cache (1.3.1)
41
+ faraday (~> 0.8)
42
+ ffi (1.9.18)
43
+ formatador (0.2.5)
44
+ git (1.3.0)
45
+ guard (2.14.1)
46
+ formatador (>= 0.2.4)
47
+ listen (>= 2.7, < 4.0)
48
+ lumberjack (~> 1.0)
49
+ nenv (~> 0.1)
50
+ notiffany (~> 0.0)
51
+ pry (>= 0.9.12)
52
+ shellany (~> 0.0)
53
+ thor (>= 0.18.1)
54
+ guard-compat (1.2.1)
55
+ guard-rspec (4.7.3)
56
+ guard (~> 2.1)
57
+ guard-compat (~> 1.1)
58
+ rspec (>= 2.99.0, < 4.0)
59
+ kramdown (1.13.2)
60
+ listen (3.0.7)
61
+ rb-fsevent (>= 0.9.3)
62
+ rb-inotify (>= 0.9.7)
63
+ lumberjack (1.0.12)
64
+ method_source (0.8.2)
65
+ multipart-post (2.0.0)
66
+ nap (1.1.0)
67
+ nenv (0.3.0)
68
+ notiffany (0.1.1)
69
+ nenv (~> 0.1)
70
+ shellany (~> 0.0)
71
+ octokit (4.7.0)
72
+ sawyer (~> 0.8.0, >= 0.5.3)
73
+ open4 (1.3.4)
74
+ parallel (1.11.2)
75
+ parser (2.4.0.0)
76
+ ast (~> 2.2)
77
+ powerpack (0.1.1)
78
+ pry (0.10.4)
79
+ coderay (~> 1.1.0)
80
+ method_source (~> 0.8.1)
81
+ slop (~> 3.4)
82
+ public_suffix (2.0.5)
83
+ rainbow (2.2.2)
84
+ rake
85
+ rake (10.5.0)
86
+ rb-fsevent (0.9.8)
87
+ rb-inotify (0.9.10)
88
+ ffi (>= 0.5.0, < 2)
89
+ rspec (3.6.0)
90
+ rspec-core (~> 3.6.0)
91
+ rspec-expectations (~> 3.6.0)
92
+ rspec-mocks (~> 3.6.0)
93
+ rspec-core (3.6.0)
94
+ rspec-support (~> 3.6.0)
95
+ rspec-expectations (3.6.0)
96
+ diff-lcs (>= 1.2.0, < 2.0)
97
+ rspec-support (~> 3.6.0)
98
+ rspec-mocks (3.6.0)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.6.0)
101
+ rspec-support (3.6.0)
102
+ rubocop (0.49.1)
103
+ parallel (~> 1.10)
104
+ parser (>= 2.3.3.1, < 3.0)
105
+ powerpack (~> 0.1)
106
+ rainbow (>= 1.99.1, < 3.0)
107
+ ruby-progressbar (~> 1.7)
108
+ unicode-display_width (~> 1.0, >= 1.0.1)
109
+ ruby-progressbar (1.8.1)
110
+ sawyer (0.8.1)
111
+ addressable (>= 2.3.5, < 2.6)
112
+ faraday (~> 0.8, < 1.0)
113
+ shellany (0.0.1)
114
+ slop (3.6.0)
115
+ terminal-table (1.8.0)
116
+ unicode-display_width (~> 1.1, >= 1.1.1)
117
+ thor (0.19.4)
118
+ unicode-display_width (1.3.0)
119
+ yard (0.9.9)
120
+
121
+ PLATFORMS
122
+ ruby
123
+
124
+ DEPENDENCIES
125
+ bundler (~> 1.3)
126
+ danger (~> 5.0)
127
+ danger-changelog (~> 0.1)
128
+ danger-pr_reviewers!
129
+ guard (~> 2.14)
130
+ guard-rspec (~> 4.7)
131
+ listen (= 3.0.7)
132
+ pry
133
+ rake (~> 10.0)
134
+ rspec (~> 3.4)
135
+ rubocop (~> 0.41)
136
+ yard (~> 0.8)
137
+
138
+ BUNDLED WITH
139
+ 1.13.7
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Conichi
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.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Anton Domashnev <antondomashnev@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ [![Build Status](https://travis-ci.org/conichiGMBH/danger-pr_reviewers.svg?branch=master)](https://travis-ci.org/conichiGMBH/danger-pr_reviewers)
2
+
3
+ # danger-pr_reviewers
4
+
5
+ The plugin deals with the PRs on the GitHub innregards to reviews. Based on the given parameters
6
+ it automatically assigns the developer to review the PRs. In [ios team](https://github.com/conichiGMBH/ios-team) we have [rules](https://github.com/conichiGMBH/ios-team/blob/master/docs/pr_protocol.md#creating-the-pr) to ask our designers to review the UI changed in PR, by checkin the attached image or gif. The `pr_reviewers` can also ask for review based on that rule.
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ $ gem install danger-pr_reviewers
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ developers_usernames = ["Superman", "Batman", "Iron-Man"]
18
+ number_of_developers_required_for_review = 1
19
+ designers_usernames = ["Pablo-Picasso", "Salvador-Dali"]
20
+ number_of_designers_required_for_review = 1
21
+ pr_reviewers.run(developers_usernames,
22
+ designers_usernames,
23
+ number_of_developers_required_for_review,
24
+ number_of_designers_required_for_review)
25
+ ```
26
+
27
+ ## Development
28
+
29
+ 1. Clone this repo
30
+ 2. Run `bundle install` to setup dependencies.
31
+ 3. Run `bundle exec rake spec` to run the tests.
32
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
33
+ 5. Make your changes.
data/RELEASING.md ADDED
@@ -0,0 +1,67 @@
1
+ # Releasing Danger-PR-Reviewers
2
+
3
+ There're no hard rules about when to release `danger-pr_reviewers`. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
4
+
5
+ ### Release
6
+
7
+ Install bundle, run tests, check that all tests succeed locally.
8
+
9
+ ```
10
+ bundle install
11
+ rake
12
+ ```
13
+
14
+ Check that the last build succeeded in [Travis CI](https://travis-ci.org/conichiGMBH/danger-pr_reviewers) for all supported platforms.
15
+
16
+ Increment the version, modify [lib/pr_reviewers/gem_version.rb](lib/pr_reviewers/gem_version.rb).
17
+
18
+ Following the [Semantic Versioning](http://semver.org/):
19
+ * Increment the third number if the release has bug fixes and/or very minor features with backward compatibility, only (eg. change `0.2.1` to `0.2.2`).
20
+ * Increment the second number if the release contains major features or breaking API changes (eg. change `0.2.1` to `0.3.0`).
21
+
22
+ Create a new version and mark it as Next in [CHANGELOG.md](CHANGELOG.md).
23
+
24
+ ```
25
+ ### 0.2.2 (12/03/2016)
26
+ ```
27
+
28
+ Remove the line with "* Your contribution here.", since there will be no more contributions to this release.
29
+
30
+ Commit your changes.
31
+
32
+ ```
33
+ git add CHANGELOG.md lib/pr_reviewers/gem_version.rb
34
+ git commit -m "Preparing for release 0.2.2."
35
+ git push origin master
36
+ ```
37
+
38
+ Release.
39
+
40
+ ```
41
+ $ rake release
42
+
43
+ danger-pr_reviewers 0.2.2 built to pkg/danger-pr_reviewers-0.2.2.gem.
44
+ Tagged v0.2.2.
45
+ Pushed git commits and tags.
46
+ Pushed danger-pr_reviewers 0.2.2 to rubygems.org.
47
+ ```
48
+
49
+ ### Prepare for the Next Version
50
+
51
+ Add the next release to [CHANGELOG.md](CHANGELOG.md).
52
+
53
+ ```
54
+ ### 0.2.3 (Next)
55
+
56
+ * Your contribution here.
57
+ ```
58
+
59
+ Increment the third version number in [lib/pr_reviewers/gem_version.rb](lib/pr_reviewers/gem_version.rb).
60
+
61
+ Commit your changes.
62
+
63
+ ```
64
+ git add CHANGELOG.md lib/pr_reviewers/version.rb
65
+ git commit -m "Preparing for next development iteration, 0.2.3."
66
+ git push origin master
67
+ ```
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'pr_reviewers/gem_version.rb'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'danger-pr_reviewers'
9
+ spec.version = PrReviewers::VERSION
10
+ spec.authors = ['Anton Domashnev']
11
+ spec.email = ['anton.domashnev@conichi.com']
12
+ spec.description = 'Picks the reviewers for the your PRs.'
13
+ spec.summary = "It's literally the simplest version of a mention plugin already
14
+ existed in Danger ecosystem."
15
+ spec.homepage = 'https://github.com/conichiGMBH/danger-pr_reviewers'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
24
+
25
+ # General ruby development
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+
29
+ # Testing support
30
+ spec.add_development_dependency 'rspec', '~> 3.4'
31
+
32
+ # Linting code and docs
33
+ spec.add_development_dependency 'rubocop', '~> 0.41'
34
+ spec.add_development_dependency 'yard', '~> 0.8'
35
+
36
+ # Makes testing easy via `bundle exec guard`
37
+ spec.add_development_dependency 'guard', '~> 2.14'
38
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
39
+
40
+ # If you want to work on older builds of ruby
41
+ spec.add_development_dependency 'listen', '3.0.7'
42
+
43
+ # This gives you the chance to run a REPL inside your tests
44
+ # via:
45
+ #
46
+ # require 'pry'
47
+ # binding.pry
48
+ #
49
+ # This will stop test execution and let you inspect the results
50
+ spec.add_development_dependency 'pry'
51
+ end
@@ -0,0 +1 @@
1
+ require 'pr_reviewers/plugin'
@@ -0,0 +1 @@
1
+ require 'pr_reviewers/gem_version'
@@ -0,0 +1,3 @@
1
+ module PrReviewers
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,63 @@
1
+ module Danger
2
+ #
3
+ # The idea of the plugin is to let the machine rules the PR reviewers decision =)
4
+ # * It will assign a random %n developers from the given Array to review the code
5
+ # * It will assign a random %n designers from the given Array to
6
+ # review the UI if there is an image attached to the PR body
7
+ #
8
+ # @example Assigns reviewers for the PR
9
+ #
10
+ # pr_reviewers.run
11
+ #
12
+ # @see conichiGMBH/danger-pr_reviewers
13
+ # @tags github, review, mention
14
+ #
15
+ class DangerPrReviewers < Plugin
16
+ # Request a review from potential reviewers.
17
+ #
18
+ # @param [Integer] number_of_code_reviewers
19
+ # Maximum number of developers to request a review from, default is 1.
20
+ # @param [Integer] number_of_design_reviewers
21
+ # Maximum number of designers to request a review from, default is 1.
22
+ # @param [Array<String>] developers
23
+ # List of developers GitHub's usernames.
24
+ # @param [Array<String>] designers
25
+ # List of designers GitHub's usernames.
26
+ # @return [void]
27
+ #
28
+ def run(developers, designers, number_of_code_reviewers = 1, number_of_design_reviewers = 1)
29
+ unless @dangerfile.github.pr_author.nil?
30
+ developers -= [@dangerfile.github.pr_author]
31
+ designers -= [@dangerfile.github.pr_author]
32
+ end
33
+ reviewers = find_developers(number_of_code_reviewers, developers)
34
+ reviewers += find_designers(number_of_design_reviewers, designers) if need_design_review?
35
+ request_review(reviewers)
36
+ message("Danger has assigned @#{reviewers.join(' @')} to review the PR", sticky: true)
37
+ end
38
+
39
+ private
40
+
41
+ def find_developers(number_of_code_reviewers, developers)
42
+ developers.sample([number_of_code_reviewers, developers.count].min)
43
+ end
44
+
45
+ def find_designers(number_of_design_reviewers, designers)
46
+ designers.sample([number_of_design_reviewers, designers.count].min)
47
+ end
48
+
49
+ def need_design_review?
50
+ pr_body = @dangerfile.github.pr_body
51
+ return true if pr_body =~ /<img([\w\W]+?)>/
52
+ return true if pr_body =~ %r{\[.*\]\((https|http):\/\/.*\.(PNG|png|jpeg|jpg)\)}
53
+ false
54
+ end
55
+
56
+ def request_review(reviewers)
57
+ github = @dangerfile.env.request_source
58
+ pr_id = @dangerfile.env.ci_source.pull_request_id
59
+ repo = @dangerfile.env.ci_source.repo_slug
60
+ github.client.request_pull_request_review(repo, pr_id, reviewers)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,110 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerPrReviewers do
5
+ it 'should be a plugin' do
6
+ expect(Danger::DangerPrReviewers.new(nil)).to be_a Danger::Plugin
7
+ end
8
+ end
9
+
10
+ context 'with dangerfile' do
11
+ let(:pr_id) { testing_env['TRAVIS_PULL_REQUEST'] }
12
+ let(:repo_slug) { testing_env['TRAVIS_REPO_SLUG'] }
13
+ let(:dangerfile) { testing_dangerfile }
14
+ let(:developers) { ['Antondomashnev', 'Mourad-Aly', 'David-Henner', 'Superman'] }
15
+ let(:designers) { ['denis-sharypin', 'johnny'] }
16
+ let(:pr_reviewers) { dangerfile.pr_reviewers }
17
+ let(:client) { double(Octokit::Client) }
18
+ let(:github) { dangerfile.github }
19
+
20
+ context 'in a PR' do
21
+ before do
22
+ allow(client).to receive(:request_pull_request_review).with(anything, anything, anything)
23
+ allow(dangerfile.env.request_source).to receive(:client).and_return(client)
24
+ end
25
+
26
+ context 'with the pr author as a deloper' do
27
+ let(:pr_author) { 'Antondomashnev' }
28
+
29
+ before do
30
+ allow(github).to receive(:pr_author).and_return(pr_author)
31
+ allow(github).to receive(:pr_body).and_return('Hey! Here is a snapshot of ![simulator screen shot 23 jun 2017 14 19 41](https://user-images.githubusercontent.com/6436181/27482218-d972c1c2-5820-11e7-9806-9006500952de.png)')
32
+ end
33
+
34
+ it 'excludes author from potential reviewer' do
35
+ expect(client).to_not receive(:request_pull_request_review).with(repo_slug, pr_id, array_including(pr_author))
36
+ pr_reviewers.run(developers, designers, 4, 2)
37
+ end
38
+ end
39
+
40
+ context 'with the pr author as a designer' do
41
+ let(:pr_author) { 'johnny' }
42
+
43
+ before do
44
+ allow(github).to receive(:pr_author).and_return(pr_author)
45
+ allow(github).to receive(:pr_body).and_return('Hey! Here is a snapshot of ![simulator screen shot 23 jun 2017 14 19 41](https://user-images.githubusercontent.com/6436181/27482218-d972c1c2-5820-11e7-9806-9006500952de.png)')
46
+ end
47
+
48
+ it 'excludes author from potential reviewer' do
49
+ expect(client).to_not receive(:request_pull_request_review).with(repo_slug, pr_id, array_including(pr_author))
50
+ pr_reviewers.run(developers, designers, 4, 2)
51
+ end
52
+ end
53
+
54
+ context 'with image' do
55
+ before do
56
+ allow(github).to receive(:pr_author).and_return('Foo')
57
+ end
58
+
59
+ context 'inserted as markdown link' do
60
+ before do
61
+ allow(github).to receive(:pr_body).and_return('Hey! Here is a snapshot of ![simulator screen shot 23 jun 2017 14 19 41](https://user-images.githubusercontent.com/6436181/27482218-d972c1c2-5820-11e7-9806-9006500952de.png)')
62
+ end
63
+
64
+ it 'asks designer for review' do
65
+ expect(client).to receive(:request_pull_request_review).with(repo_slug, pr_id, array_including_sample_of(designers, 2))
66
+ pr_reviewers.run(developers, designers, 3, 2)
67
+ end
68
+
69
+ it 'asks developer for review' do
70
+ expect(client).to receive(:request_pull_request_review).with(repo_slug, pr_id, array_including_sample_of(developers, 3))
71
+ pr_reviewers.run(developers, designers, 3, 2)
72
+ end
73
+ end
74
+
75
+ context 'inserted as html tag' do
76
+ before do
77
+ allow(github).to receive(:pr_body).and_return('Please check only what inside the red rectangle 😄 <img src="https://monosnap.com/file/DF8OnfmdHRbJ3UH4e6phCVf8blJln4.png" width=640>')
78
+ end
79
+
80
+ it 'asks designer for review' do
81
+ expect(client).to receive(:request_pull_request_review).with(repo_slug, pr_id, array_including_sample_of(designers, 2))
82
+ pr_reviewers.run(developers, designers, 3, 2)
83
+ end
84
+
85
+ it 'asks developer for review' do
86
+ expect(client).to receive(:request_pull_request_review).with(repo_slug, pr_id, array_including_sample_of(developers, 3))
87
+ pr_reviewers.run(developers, designers, 3, 2)
88
+ end
89
+ end
90
+ end
91
+
92
+ context 'without image' do
93
+ before do
94
+ allow(github).to receive(:pr_author).and_return('Foo')
95
+ allow(github).to receive(:pr_body).and_return('This is my amazing PR without images')
96
+ end
97
+
98
+ it 'doesnt ask designer for review' do
99
+ expect(client).to_not receive(:request_pull_request_review).with(repo_slug, pr_id, array_including_sample_of(designers, 2))
100
+ pr_reviewers.run(developers, designers, 3, 2)
101
+ end
102
+
103
+ it 'asks developer for review' do
104
+ expect(client).to receive(:request_pull_request_review).with(repo_slug, pr_id, array_including_sample_of(developers, 3))
105
+ pr_reviewers.run(developers, designers, 3, 2)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,69 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'pry'
8
+
9
+ require 'rspec'
10
+ require 'danger'
11
+
12
+ # Use coloured output, it's the best.
13
+ RSpec.configure do |config|
14
+ config.filter_gems_from_backtrace 'bundler'
15
+ config.color = true
16
+ config.tty = true
17
+ end
18
+
19
+ require 'danger_plugin'
20
+
21
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
22
+ # If you are expanding these files, see if it's already been done ^.
23
+
24
+ # A silent version of the user interface,
25
+ # it comes with an extra function `.string` which will
26
+ # strip all ANSI colours from the string.
27
+
28
+ # rubocop:disable Lint/NestedMethodDefinition
29
+ def testing_ui
30
+ @output = StringIO.new
31
+ def @output.winsize
32
+ [20, 9999]
33
+ end
34
+
35
+ cork = Cork::Board.new(out: @output)
36
+ def cork.string
37
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
38
+ end
39
+ cork
40
+ end
41
+ # rubocop:enable Lint/NestedMethodDefinition
42
+
43
+ # Example environment (ENV) that would come from
44
+ # running a PR on TravisCI
45
+ def testing_env
46
+ {
47
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
48
+ 'TRAVIS_PULL_REQUEST' => '800',
49
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
50
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
51
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
52
+ }
53
+ end
54
+
55
+ # A stubbed out Dangerfile for use in tests
56
+ def testing_dangerfile
57
+ env = Danger::EnvironmentManager.new(testing_env)
58
+ Danger::Dangerfile.new(env, testing_ui)
59
+ end
60
+
61
+ RSpec::Matchers.define :array_including_sample_of do |*attributes|
62
+ match do |actual|
63
+ contained_elements_count = 0
64
+ attributes[0].each do |element|
65
+ contained_elements_count += 1 if actual.include? element
66
+ end
67
+ contained_elements_count == attributes[1]
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-pr_reviewers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anton Domashnev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.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
+ - !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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.41'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.41'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: listen
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.7
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.7
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Picks the reviewers for the your PRs.
154
+ email:
155
+ - anton.domashnev@conichi.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rubocop.yml"
162
+ - ".rubocop_todo.yml"
163
+ - ".travis.yml"
164
+ - CHANGELOG.md
165
+ - Dangerfile
166
+ - Gemfile
167
+ - Gemfile.lock
168
+ - Guardfile
169
+ - LICENSE
170
+ - LICENSE.txt
171
+ - README.md
172
+ - RELEASING.md
173
+ - Rakefile
174
+ - danger-pr_reviewers.gemspec
175
+ - lib/danger_plugin.rb
176
+ - lib/danger_pr_reviewers.rb
177
+ - lib/pr_reviewers/gem_version.rb
178
+ - lib/pr_reviewers/plugin.rb
179
+ - spec/pr_reviewers_spec.rb
180
+ - spec/spec_helper.rb
181
+ homepage: https://github.com/conichiGMBH/danger-pr_reviewers
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.5.1
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: It's literally the simplest version of a mention plugin already existed in
205
+ Danger ecosystem.
206
+ test_files:
207
+ - spec/pr_reviewers_spec.rb
208
+ - spec/spec_helper.rb