danger 4.0.5 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/danger/ci_source/bitrise.rb +1 -1
- data/lib/danger/ci_source/buildkite.rb +1 -1
- data/lib/danger/ci_source/circle.rb +1 -1
- data/lib/danger/ci_source/drone.rb +1 -1
- data/lib/danger/ci_source/jenkins.rb +1 -1
- data/lib/danger/ci_source/local_git_repo.rb +1 -1
- data/lib/danger/ci_source/semaphore.rb +1 -1
- data/lib/danger/ci_source/surf.rb +1 -1
- data/lib/danger/ci_source/teamcity.rb +1 -1
- data/lib/danger/ci_source/travis.rb +1 -1
- data/lib/danger/ci_source/xcode_server.rb +1 -1
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +21 -0
- data/lib/danger/request_sources/{github.rb → github/github.rb} +12 -1
- data/lib/danger/request_sources/github/github_review.rb +126 -0
- data/lib/danger/request_sources/github/github_review_resolver.rb +18 -0
- data/lib/danger/request_sources/github/octokit_pr_review.rb +83 -0
- data/lib/danger/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c20b75e7236d76c54237d5f47ebb4798615f659
|
4
|
+
data.tar.gz: 98524be99ef12531db7486fc61b0640a05e5fde4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a76fe9cb2bef2d94fa5e89be15f91ef59013a74229a28f93676a2a156e089a57e5a20446938292f3ade71dde3d745b4142f10102a7602a9f630cfea82629f26
|
7
|
+
data.tar.gz: f2a4cf663952697d007fb5d992e64969fed2c59820061c897e68be894ef230ee0b969d10edc4b638d738ba892dbbae51e2fd01818d308c853367cd30b8a5de1a
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables
|
2
2
|
# https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
|
3
|
-
require "danger/request_sources/github"
|
3
|
+
require "danger/request_sources/github/github"
|
4
4
|
require "danger/request_sources/gitlab"
|
5
5
|
require "danger/request_sources/bitbucket_server"
|
6
6
|
require "danger/request_sources/bitbucket_cloud"
|
@@ -92,6 +92,27 @@ module Danger
|
|
92
92
|
"github"
|
93
93
|
end
|
94
94
|
|
95
|
+
# @!group PR Review
|
96
|
+
#
|
97
|
+
# In Beta. Provides access to creating a GitHub Review instead of a typical GitHub comment.
|
98
|
+
#
|
99
|
+
# To use you announce the start of your review, and the end via the `start` and `submit` functions,
|
100
|
+
# for example:
|
101
|
+
#
|
102
|
+
# ```
|
103
|
+
# github.review.start
|
104
|
+
# github.review.fail("Please add a CHANGELOG entry") if has_no_changelog
|
105
|
+
# github.review.warn("PR has no body entry") if github.pr_body.length == 0
|
106
|
+
# github.review.message("You might want to read #{url}") if may_require_docs
|
107
|
+
# github.review.markdown("##Failed Test results #{failed_results}") if failed_results
|
108
|
+
# github.review.submit
|
109
|
+
# ```
|
110
|
+
#
|
111
|
+
# @return [ReviewDSL]
|
112
|
+
def review
|
113
|
+
@github.review
|
114
|
+
end
|
115
|
+
|
95
116
|
# @!group PR Metadata
|
96
117
|
# The title of the Pull Request.
|
97
118
|
# @return [String]
|
@@ -2,7 +2,8 @@
|
|
2
2
|
require "octokit"
|
3
3
|
require "danger/helpers/comments_helper"
|
4
4
|
require "danger/helpers/comment"
|
5
|
-
|
5
|
+
require "danger/request_sources/github/github_review"
|
6
|
+
require "danger/request_sources/github/octokit_pr_review.rb"
|
6
7
|
require "danger/request_sources/support/get_ignored_violation"
|
7
8
|
|
8
9
|
module Danger
|
@@ -63,6 +64,16 @@ module Danger
|
|
63
64
|
@pr_diff ||= client.pull_request(ci_source.repo_slug, ci_source.pull_request_id, accept: "application/vnd.github.v3.diff")
|
64
65
|
end
|
65
66
|
|
67
|
+
def review
|
68
|
+
return @review unless @review.nil?
|
69
|
+
@review = client.pull_request_reviews(ci_source.repo_slug, ci_source.pull_request_id)
|
70
|
+
.map { |review_json| Danger::RequestSources::GitHubSource::Review.new(client, ci_source, review_json) }
|
71
|
+
.select(&:generated_by_danger?)
|
72
|
+
.last
|
73
|
+
@review ||= Danger::RequestSources::GitHubSource::Review.new(client, ci_source)
|
74
|
+
@review
|
75
|
+
end
|
76
|
+
|
66
77
|
def setup_danger_branches
|
67
78
|
# we can use a github specific feature here:
|
68
79
|
base_commit = self.pr_json["base"]["sha"]
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "octokit"
|
3
|
+
require "danger/ci_source/ci_source"
|
4
|
+
require "danger/request_sources/github/octokit_pr_review"
|
5
|
+
require "danger/request_sources/github/github_review_resolver"
|
6
|
+
require "danger/danger_core/messages/violation"
|
7
|
+
require "danger/danger_core/messages/markdown"
|
8
|
+
require "danger/helpers/comments_helper"
|
9
|
+
require "danger/helpers/comment"
|
10
|
+
|
11
|
+
module Danger
|
12
|
+
module RequestSources
|
13
|
+
module GitHubSource
|
14
|
+
class Review
|
15
|
+
include Danger::Helpers::CommentsHelper
|
16
|
+
|
17
|
+
# @see https://developer.github.com/v3/pulls/reviews/ for all possible events
|
18
|
+
EVENT_APPROVE = "APPROVE".freeze
|
19
|
+
EVENT_REQUEST_CHANGES = "REQUEST_CHANGES".freeze
|
20
|
+
EVENT_COMMENT = "COMMENT".freeze
|
21
|
+
|
22
|
+
# Current review status, if the review has not been submitted yet -> STATUS_PENDING
|
23
|
+
STATUS_APPROVED = "APPROVED".freeze
|
24
|
+
STATUS_REQUESTED_CHANGES = "CHANGES_REQUESTED".freeze
|
25
|
+
STATUS_COMMENTED = "COMMENTED".freeze
|
26
|
+
STATUS_PENDING = "PENDING".freeze
|
27
|
+
|
28
|
+
attr_reader :id, :body, :status, :review_json
|
29
|
+
|
30
|
+
def initialize(client, ci_source, review_json = nil)
|
31
|
+
@ci_source = ci_source
|
32
|
+
@client = client
|
33
|
+
@review_json = review_json
|
34
|
+
end
|
35
|
+
|
36
|
+
def id
|
37
|
+
return nil unless self.review_json
|
38
|
+
self.review_json["id"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def body
|
42
|
+
return "" unless self.review_json
|
43
|
+
self.review_json["body"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def status
|
47
|
+
return STATUS_PENDING if self.review_json.nil?
|
48
|
+
return self.review_json["state"]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Starts the new review process
|
52
|
+
def start
|
53
|
+
@warnings = []
|
54
|
+
@errors = []
|
55
|
+
@messages = []
|
56
|
+
@markdowns = []
|
57
|
+
end
|
58
|
+
|
59
|
+
# Submits the prepared review
|
60
|
+
def submit
|
61
|
+
general_violations = generate_general_violations
|
62
|
+
submission_body = generate_body
|
63
|
+
|
64
|
+
# If the review resolver says that there is nothing to submit we skip submission
|
65
|
+
return unless ReviewResolver.should_submit?(self, submission_body)
|
66
|
+
|
67
|
+
@review_json = @client.create_pull_request_review(@ci_source.repo_slug, @ci_source.pull_request_id, generate_event(general_violations), submission_body)
|
68
|
+
end
|
69
|
+
|
70
|
+
def generated_by_danger?(danger_id = "danger")
|
71
|
+
self.review_json["body"].include?("generated_by_#{danger_id}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def message(message, sticky = true, file = nil, line = nil)
|
75
|
+
@messages << Violation.new(message, sticky, file, line)
|
76
|
+
end
|
77
|
+
|
78
|
+
def warn(message, sticky = true, file = nil, line = nil)
|
79
|
+
@warnings << Violation.new(message, sticky, file, line)
|
80
|
+
end
|
81
|
+
|
82
|
+
def fail(message, sticky = true, file = nil, line = nil)
|
83
|
+
@errors << Violation.new(message, sticky, file, line)
|
84
|
+
end
|
85
|
+
|
86
|
+
def markdown(message, file = nil, line = nil)
|
87
|
+
@markdowns << Markdown.new(message, file, line)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
# The only reason to request changes for the PR is to have errors from Danger
|
93
|
+
# otherwise let's just notify user and we're done
|
94
|
+
def generate_event(violations)
|
95
|
+
violations[:errors].empty? ? EVENT_APPROVE : EVENT_REQUEST_CHANGES
|
96
|
+
end
|
97
|
+
|
98
|
+
def generate_body(danger_id: "danger")
|
99
|
+
previous_violations = parse_comment(body)
|
100
|
+
general_violations = generate_general_violations
|
101
|
+
new_body = generate_comment(warnings: general_violations[:warnings],
|
102
|
+
errors: general_violations[:errors],
|
103
|
+
messages: general_violations[:messages],
|
104
|
+
markdowns: general_violations[:markdowns],
|
105
|
+
previous_violations: previous_violations,
|
106
|
+
danger_id: danger_id,
|
107
|
+
template: "github")
|
108
|
+
return new_body
|
109
|
+
end
|
110
|
+
|
111
|
+
def generate_general_violations
|
112
|
+
general_warnings = @warnings.reject(&:inline?)
|
113
|
+
general_errors = @errors.reject(&:inline?)
|
114
|
+
general_messages = @messages.reject(&:inline?)
|
115
|
+
general_markdowns = @markdowns.reject(&:inline?)
|
116
|
+
{
|
117
|
+
warnings: general_warnings,
|
118
|
+
markdowns: general_markdowns,
|
119
|
+
errors: general_errors,
|
120
|
+
messages: general_messages
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "danger/request_sources/github/github_review"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
module RequestSources
|
6
|
+
module GitHubSource
|
7
|
+
class ReviewResolver
|
8
|
+
def self.should_submit?(review, body)
|
9
|
+
return !same_body?(body, review.body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.same_body?(body1, body2)
|
13
|
+
return !body1.nil? && !body2.nil? && body1 == body2
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "octokit"
|
3
|
+
|
4
|
+
module Octokit
|
5
|
+
class Client
|
6
|
+
# The Pull Request Review API is currently available for developers to preview.
|
7
|
+
# During the preview period, the API may change without advance notice.
|
8
|
+
# please see the blog post for full details.
|
9
|
+
# To access the API during the preview period, you must provide
|
10
|
+
# a custom media type in the Accept header:
|
11
|
+
CUSTOM_ACCEPT_HEADER = "application/vnd.github.black-cat-preview+json".freeze
|
12
|
+
|
13
|
+
# Approve pull request event
|
14
|
+
PULL_REQUEST_REVIEW_EVENT_APPROVE = "APPROVE".freeze
|
15
|
+
|
16
|
+
# Request changes on the pull request event
|
17
|
+
PULL_REQUEST_REVIEW_EVENT_REQUEST_CHANGES = "REQUEST_CHANGES".freeze
|
18
|
+
|
19
|
+
# Left a gemeneral comment on the pull request event
|
20
|
+
PULL_REQUEST_REVIEW_EVENT_COMMENT = "COMMENT".freeze
|
21
|
+
|
22
|
+
# List pull request reviews for a pull request
|
23
|
+
#
|
24
|
+
# @see https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request
|
25
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
26
|
+
# @param pull_request_number [Integer] Number of the pull request to fetch reviews for
|
27
|
+
# @return [Array<Sawyer::Resource>] Array of reviews
|
28
|
+
# @example
|
29
|
+
# Octokit.pull_request_reviews('rails/rails', :state => 'closed')
|
30
|
+
def pull_request_reviews(repo, pull_request_number, options = {})
|
31
|
+
accept = {
|
32
|
+
accept: CUSTOM_ACCEPT_HEADER
|
33
|
+
}
|
34
|
+
paginate "#{Repository.path repo}/pulls/#{pull_request_number}/reviews", options.merge(accept)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create a pull request review
|
38
|
+
#
|
39
|
+
# @see https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
|
40
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
41
|
+
# @param pull_request_number [Integer] Number of the pull request to create review for
|
42
|
+
# @param event [String] The review action (event) to perform. Can be one of
|
43
|
+
# PULL_REQUEST_REVIEW_EVENT_APPROVE
|
44
|
+
# PULL_REQUEST_REVIEW_EVENT_REQUEST_CHANGES
|
45
|
+
# PULL_REQUEST_REVIEW_EVENT_COMMENT
|
46
|
+
# @param body [String] The body for the pull request review (optional). Supports GFM.
|
47
|
+
# @return [Sawyer::Resource] The newly created pull request
|
48
|
+
# @example
|
49
|
+
# @client.create_pull_request_review("octokit/octokit.rb", "APPROVE", "Thanks for your contribution")
|
50
|
+
def create_pull_request_review(repo, pull_request_number, event, body = nil, options = {})
|
51
|
+
review = {
|
52
|
+
event: event,
|
53
|
+
accept: CUSTOM_ACCEPT_HEADER
|
54
|
+
}
|
55
|
+
review[:body] = body unless body.nil?
|
56
|
+
post "#{Repository.path repo}/pulls/#{pull_request_number}/reviews", options.merge(review)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Submit a pull request review
|
60
|
+
#
|
61
|
+
# @see https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
|
62
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
63
|
+
# @param pull_request_number [Integer] Number of the pull request to create review for
|
64
|
+
# @param review_id [Integer] ID of the pull request review to submit
|
65
|
+
# @param event [String] The review action (event) to perform. Can be one of
|
66
|
+
# PULL_REQUEST_REVIEW_EVENT_APPROVE
|
67
|
+
# PULL_REQUEST_REVIEW_EVENT_REQUEST_CHANGES
|
68
|
+
# PULL_REQUEST_REVIEW_EVENT_COMMENT
|
69
|
+
# @param body [String] The body for the pull request review (optional). Supports GFM.
|
70
|
+
# @return [Sawyer::Resource] The newly created pull request
|
71
|
+
# @example
|
72
|
+
# @client.submit_pull_request_review("octokit/octokit.rb", "REQUEST_CHANGES",
|
73
|
+
# "Nice changes, but please make couple of imrovements")
|
74
|
+
def submit_pull_request_review(repo, pull_request_number, review_id, event, body = nil, options = {})
|
75
|
+
review = {
|
76
|
+
event: event,
|
77
|
+
accept: CUSTOM_ACCEPT_HEADER
|
78
|
+
}
|
79
|
+
review[:body] = body unless body.nil?
|
80
|
+
post "#{Repository.path repo}/pulls/#{pull_request_number}/reviews/#{review_id}/events", options.merge(review)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/danger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orta Therox
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-01-
|
12
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -255,14 +255,14 @@ dependencies:
|
|
255
255
|
requirements:
|
256
256
|
- - "~>"
|
257
257
|
- !ruby/object:Gem::Version
|
258
|
-
version:
|
258
|
+
version: 0.46.0
|
259
259
|
type: :development
|
260
260
|
prerelease: false
|
261
261
|
version_requirements: !ruby/object:Gem::Requirement
|
262
262
|
requirements:
|
263
263
|
- - "~>"
|
264
264
|
- !ruby/object:Gem::Version
|
265
|
-
version:
|
265
|
+
version: 0.46.0
|
266
266
|
- !ruby/object:Gem::Dependency
|
267
267
|
name: yard
|
268
268
|
requirement: !ruby/object:Gem::Requirement
|
@@ -433,7 +433,10 @@ files:
|
|
433
433
|
- lib/danger/request_sources/bitbucket_cloud_api.rb
|
434
434
|
- lib/danger/request_sources/bitbucket_server.rb
|
435
435
|
- lib/danger/request_sources/bitbucket_server_api.rb
|
436
|
-
- lib/danger/request_sources/github.rb
|
436
|
+
- lib/danger/request_sources/github/github.rb
|
437
|
+
- lib/danger/request_sources/github/github_review.rb
|
438
|
+
- lib/danger/request_sources/github/github_review_resolver.rb
|
439
|
+
- lib/danger/request_sources/github/octokit_pr_review.rb
|
437
440
|
- lib/danger/request_sources/gitlab.rb
|
438
441
|
- lib/danger/request_sources/request_source.rb
|
439
442
|
- lib/danger/request_sources/support/get_ignored_violation.rb
|