danger 3.2.2 → 3.3.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/jenkins.rb +1 -1
- data/lib/danger/core_ext/string.rb +6 -8
- data/lib/danger/danger_core/dangerfile.rb +2 -1
- data/lib/danger/danger_core/messages/markdown.rb +6 -5
- data/lib/danger/danger_core/messages/violation.rb +6 -5
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +198 -0
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +2 -0
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +16 -0
- data/lib/danger/helpers/comment.rb +22 -0
- data/lib/danger/helpers/comments_helper.rb +0 -21
- data/lib/danger/helpers/comments_parsing_helper.rb +1 -1
- data/lib/danger/request_source/bitbucket_cloud.rb +78 -0
- data/lib/danger/request_source/bitbucket_cloud_api.rb +80 -0
- data/lib/danger/request_source/github.rb +1 -0
- data/lib/danger/request_source/gitlab.rb +1 -0
- data/lib/danger/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e10fb247dbfbbf65bddac255ef51fbde2886ec7
|
4
|
+
data.tar.gz: 26e8a81ba580a77b844ee956875974dc52605e41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5af8334759ab6fd99078bdc24b25723f21266fc2a3ef603c66ea0940576f7b2228740aead12e1d6198afce6ce1ce46fb2f074d4b111d615f693bb29bb4eda08a
|
7
|
+
data.tar.gz: a9248512d06c5c37cbcf45f2d29ebb8ff02f325e8609c540b9eb05629fb0a01ac81fce622a198a7b13fc76fe3f04c1d879312f915a7480f44bf6b91db94c737b
|
@@ -38,7 +38,7 @@ module Danger
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def supported_request_sources
|
41
|
-
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab, Danger::RequestSources::BitbucketServer]
|
41
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab, Danger::RequestSources::BitbucketServer, Danger::RequestSources::BitbucketCloud]
|
42
42
|
end
|
43
43
|
|
44
44
|
def initialize(env)
|
@@ -1,17 +1,15 @@
|
|
1
1
|
class String
|
2
|
-
|
3
|
-
split("_").collect!(&:capitalize).join
|
4
|
-
end
|
5
|
-
|
2
|
+
# @return [String] the plural form of self determined by count
|
6
3
|
def danger_pluralize(count)
|
7
4
|
"#{count} #{self}#{'s' unless count == 1}"
|
8
5
|
end
|
9
6
|
|
7
|
+
# @return [String] converts to underscored, lowercase form
|
10
8
|
def danger_underscore
|
11
|
-
self.gsub(/::/, "/").
|
12
|
-
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
13
|
-
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
14
|
-
tr("-", "_").
|
9
|
+
self.gsub(/::/, "/".freeze).
|
10
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'.freeze).
|
11
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2'.freeze).
|
12
|
+
tr("-".freeze, "_".freeze).
|
15
13
|
downcase
|
16
14
|
end
|
17
15
|
end
|
@@ -9,6 +9,7 @@ require "danger/danger_core/plugins/dangerfile_git_plugin"
|
|
9
9
|
require "danger/danger_core/plugins/dangerfile_github_plugin"
|
10
10
|
require "danger/danger_core/plugins/dangerfile_gitlab_plugin"
|
11
11
|
require "danger/danger_core/plugins/dangerfile_bitbucket_server_plugin"
|
12
|
+
require "danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin"
|
12
13
|
|
13
14
|
module Danger
|
14
15
|
class Dangerfile
|
@@ -36,7 +37,7 @@ module Danger
|
|
36
37
|
|
37
38
|
# The ones that everything would break without
|
38
39
|
def self.essential_plugin_classes
|
39
|
-
[DangerfileMessagingPlugin, DangerfileGitPlugin, DangerfileDangerPlugin, DangerfileGitHubPlugin, DangerfileGitLabPlugin, DangerfileBitbucketServerPlugin]
|
40
|
+
[DangerfileMessagingPlugin, DangerfileGitPlugin, DangerfileDangerPlugin, DangerfileGitHubPlugin, DangerfileGitLabPlugin, DangerfileBitbucketServerPlugin, DangerfileBitbucketCloudPlugin]
|
40
41
|
end
|
41
42
|
|
42
43
|
# Both of these methods exist on all objects
|
@@ -2,7 +2,7 @@ module Danger
|
|
2
2
|
class Markdown
|
3
3
|
attr_accessor :message, :file, :line
|
4
4
|
|
5
|
-
def initialize(message, file, line)
|
5
|
+
def initialize(message, file = nil, line = nil)
|
6
6
|
self.message = message
|
7
7
|
self.file = file
|
8
8
|
self.line = line
|
@@ -17,16 +17,17 @@ module Danger
|
|
17
17
|
other.line == line
|
18
18
|
end
|
19
19
|
|
20
|
+
# @return [Boolean] returns true if is a file or line, false otherwise
|
20
21
|
def inline?
|
21
|
-
|
22
|
+
file || line
|
22
23
|
end
|
23
24
|
|
24
25
|
def to_s
|
25
26
|
extra = []
|
26
|
-
extra << "file: #{file}" unless file
|
27
|
-
extra << "line: #{line}" unless line
|
27
|
+
extra << "file: #{file}" unless file
|
28
|
+
extra << "line: #{line}" unless line
|
28
29
|
|
29
|
-
"Markdown #{message} { #{extra.join ', '} }"
|
30
|
+
"Markdown #{message} { #{extra.join ', '.freeze} }"
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -2,7 +2,7 @@ module Danger
|
|
2
2
|
class Violation
|
3
3
|
attr_accessor :message, :sticky, :file, :line
|
4
4
|
|
5
|
-
def initialize(message, sticky, file, line)
|
5
|
+
def initialize(message, sticky, file = nil, line = nil)
|
6
6
|
self.message = message
|
7
7
|
self.sticky = sticky
|
8
8
|
self.file = file
|
@@ -19,17 +19,18 @@ module Danger
|
|
19
19
|
other.line == line
|
20
20
|
end
|
21
21
|
|
22
|
+
# @return [Boolean] returns true if is a file or line, false otherwise
|
22
23
|
def inline?
|
23
|
-
|
24
|
+
file || line
|
24
25
|
end
|
25
26
|
|
26
27
|
def to_s
|
27
28
|
extra = []
|
28
29
|
extra << "sticky: true" if sticky
|
29
|
-
extra << "file: #{file}" unless file
|
30
|
-
extra << "line: #{line}" unless line
|
30
|
+
extra << "file: #{file}" unless file
|
31
|
+
extra << "line: #{line}" unless line
|
31
32
|
|
32
|
-
"Violation #{message} { #{extra.join ', '} }"
|
33
|
+
"Violation #{message} { #{extra.join ', '.freeze} }"
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "danger/plugin_support/plugin"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
# Handles interacting with Bitbucket Cloud inside a Dangerfile. Provides a few functions which wrap `pr_json` and also
|
6
|
+
# through a few standard functions to simplify your code.
|
7
|
+
#
|
8
|
+
# @example Warn when a PR is classed as work in progress
|
9
|
+
#
|
10
|
+
# warn "PR is classed as Work in Progress" if bitbucket_cloud.pr_title.include? "[WIP]"
|
11
|
+
#
|
12
|
+
# @example Declare a PR to be simple to avoid specific Danger rules
|
13
|
+
#
|
14
|
+
# declared_trivial = (bitbucket_cloud.pr_title + bitbucket_cloud.pr_body).include?("#trivial")
|
15
|
+
#
|
16
|
+
# @example Ensure that labels have been used on the PR
|
17
|
+
#
|
18
|
+
# fail "Please add labels to this PR" if bitbucket_cloud.pr_labels.empty?
|
19
|
+
#
|
20
|
+
# @example Ensure there is a summary for a PR
|
21
|
+
#
|
22
|
+
# fail "Please provide a summary in the Pull Request description" if bitbucket_cloud.pr_body.length < 5
|
23
|
+
#
|
24
|
+
# @example Only accept PRs to the develop branch
|
25
|
+
#
|
26
|
+
# fail "Please re-submit this PR to develop, we may have already fixed your issue." if bitbucket_cloud.branch_for_base != "develop"
|
27
|
+
#
|
28
|
+
# @example Highlight when a celebrity makes a pull request
|
29
|
+
#
|
30
|
+
# message "Welcome, Danger." if bitbucket_cloud.pr_author == "dangermcshane"
|
31
|
+
#
|
32
|
+
# @example Ensure that all PRs have an assignee
|
33
|
+
#
|
34
|
+
# warn "This PR does not have any assignees yet." unless bitbucket_cloud.pr_json["reviewers"].length == 0
|
35
|
+
#
|
36
|
+
# @example Send a message with links to a collection of specific files
|
37
|
+
#
|
38
|
+
# if git.modified_files.include? "config/*.js"
|
39
|
+
# config_files = git.modified_files.select { |path| path.include? "config/" }
|
40
|
+
# message "This PR changes #{ bitbucket_cloud.html_link(config_files) }"
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# @example Highlight with a clickable link if a Package.json is changed
|
44
|
+
#
|
45
|
+
# warn "#{bitbucket_cloud.html_link("Package.json")} was edited." if git.modified_files.include? "Package.json"
|
46
|
+
#
|
47
|
+
# @see danger/danger
|
48
|
+
# @tags core, bitbucket_cloud
|
49
|
+
#
|
50
|
+
class DangerfileBitbucketCloudPlugin < Plugin
|
51
|
+
# So that this init can fail.
|
52
|
+
def self.new(dangerfile)
|
53
|
+
return nil if dangerfile.env.request_source.class != Danger::RequestSources::BitbucketCloud
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
# The instance name used in the Dangerfile
|
58
|
+
# @return [String]
|
59
|
+
#
|
60
|
+
def self.instance_name
|
61
|
+
"bitbucket_cloud"
|
62
|
+
end
|
63
|
+
|
64
|
+
def initialize(dangerfile)
|
65
|
+
super(dangerfile)
|
66
|
+
@bs = dangerfile.env.request_source
|
67
|
+
end
|
68
|
+
|
69
|
+
# @!group Bitbucket Cloud Misc
|
70
|
+
# The hash that represents the PR's JSON. For an example of what this looks like
|
71
|
+
# see the [Danger Fixture'd one](https://raw.githubusercontent.com/danger/danger/master/spec/fixtures/bitbucket_cloud_api/pr_response.json).
|
72
|
+
# @return [Hash]
|
73
|
+
def pr_json
|
74
|
+
@bs.pr_json
|
75
|
+
end
|
76
|
+
|
77
|
+
# @!group PR Metadata
|
78
|
+
# The title of the Pull Request.
|
79
|
+
# @return [String]
|
80
|
+
#
|
81
|
+
def pr_title
|
82
|
+
@bs.pr_json[:title].to_s
|
83
|
+
end
|
84
|
+
|
85
|
+
# @!group PR Metadata
|
86
|
+
# The body text of the Pull Request.
|
87
|
+
# @return [String]
|
88
|
+
#
|
89
|
+
def pr_description
|
90
|
+
@bs.pr_json[:description].to_s
|
91
|
+
end
|
92
|
+
alias pr_body pr_description
|
93
|
+
|
94
|
+
# @!group PR Metadata
|
95
|
+
# The username of the author of the Pull Request.
|
96
|
+
# @return [String]
|
97
|
+
#
|
98
|
+
def pr_author
|
99
|
+
@bs.pr_json[:author][:user][:slug].to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
# @!group PR Commit Metadata
|
103
|
+
# The branch to which the PR is going to be merged into.
|
104
|
+
# @return [String]
|
105
|
+
#
|
106
|
+
def branch_for_base
|
107
|
+
@bs.pr_json[:toRef][:displayId].to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
# @!group PR Commit Metadata
|
111
|
+
# A href that represents the current PR
|
112
|
+
# @return [String]
|
113
|
+
#
|
114
|
+
def pr_link
|
115
|
+
@bs.pr_json[:links][:self].flat_map { |l| l[:href] }.first.to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
# @!group PR Commit Metadata
|
119
|
+
# The branch to which the PR is going to be merged from.
|
120
|
+
# @return [String]
|
121
|
+
#
|
122
|
+
def branch_for_head
|
123
|
+
@bs.pr_json[:fromRef][:displayId].to_s
|
124
|
+
end
|
125
|
+
|
126
|
+
# @!group PR Commit Metadata
|
127
|
+
# The base commit to which the PR is going to be merged as a parent.
|
128
|
+
# @return [String]
|
129
|
+
#
|
130
|
+
def base_commit
|
131
|
+
@bs.pr_json[:toRef][:latestCommit].to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
# @!group PR Commit Metadata
|
135
|
+
# The head commit to which the PR is requesting to be merged from.
|
136
|
+
# @return [String]
|
137
|
+
#
|
138
|
+
def head_commit
|
139
|
+
@bs.pr_json[:fromRef][:latestCommit].to_s
|
140
|
+
end
|
141
|
+
|
142
|
+
# @!group Bitbucket Cloud Misc
|
143
|
+
# Returns a list of HTML anchors for a file, or files in the head repository.
|
144
|
+
# It returns a string of multiple anchors if passed an array.
|
145
|
+
# @param [String or Array<String>] paths
|
146
|
+
# A list of strings to convert to github anchors
|
147
|
+
# @param [Bool] full_path
|
148
|
+
# Shows the full path as the link's text, defaults to `true`.
|
149
|
+
#
|
150
|
+
# @return [String]
|
151
|
+
#
|
152
|
+
def html_link(paths, full_path: true)
|
153
|
+
create_link(paths, full_path) { |href, text| create_html_link(href, text) }
|
154
|
+
end
|
155
|
+
|
156
|
+
# @!group Bitbucket Cloud Misc
|
157
|
+
# Returns a list of Markdown links for a file, or files in the head repository.
|
158
|
+
# It returns a string of multiple links if passed an array.
|
159
|
+
# @param [String or Array<String>] paths
|
160
|
+
# A list of strings to convert to Markdown links
|
161
|
+
# @param [Bool] full_path
|
162
|
+
# Shows the full path as the link's text, defaults to `true`.
|
163
|
+
#
|
164
|
+
# @return [String]
|
165
|
+
#
|
166
|
+
def markdown_link(paths, full_path: true)
|
167
|
+
create_link(paths, full_path) { |href, text| create_markdown_link(href, text) }
|
168
|
+
end
|
169
|
+
|
170
|
+
private
|
171
|
+
|
172
|
+
def create_link(paths, full_path)
|
173
|
+
paths = [paths] unless paths.kind_of?(Array)
|
174
|
+
commit = head_commit
|
175
|
+
repo = pr_json[:fromRef][:repository][:links][:self].flat_map { |l| l[:href] }.first
|
176
|
+
|
177
|
+
paths = paths.map do |path|
|
178
|
+
path, line = path.split("#")
|
179
|
+
url_path = path.start_with?("/") ? path : "/#{path}"
|
180
|
+
text = full_path ? path : File.basename(path)
|
181
|
+
url_path.gsub!(" ", "%20")
|
182
|
+
line_ref = line ? "##{line}" : ""
|
183
|
+
yield("#{repo}#{url_path}?at=#{commit}#{line_ref}", text)
|
184
|
+
end
|
185
|
+
|
186
|
+
return paths.first if paths.count < 2
|
187
|
+
paths.first(paths.count - 1).join(", ") + " & " + paths.last
|
188
|
+
end
|
189
|
+
|
190
|
+
def create_html_link(href, text)
|
191
|
+
"<a href='#{href}'>#{text}</a>"
|
192
|
+
end
|
193
|
+
|
194
|
+
def create_markdown_link(href, text)
|
195
|
+
"[#{text}](#{href})"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -114,5 +114,21 @@ module Danger
|
|
114
114
|
def diff_for_file(file)
|
115
115
|
modified_files.include?(file) ? @git.diff[file] : nil
|
116
116
|
end
|
117
|
+
|
118
|
+
# @!group Git Metadata
|
119
|
+
# Statistics for a specific file in this diff
|
120
|
+
# @return [Hash] with keys `:insertions`, `:deletions` giving line counts, and `:before`, `:after` giving file contents, or nil if the file has no changes or does not exist
|
121
|
+
#
|
122
|
+
def info_for_file(file)
|
123
|
+
return nil unless modified_files.include?(file)
|
124
|
+
stats = @git.diff.stats[:files][file]
|
125
|
+
diff = @git.diff[file]
|
126
|
+
{
|
127
|
+
insertions: stats[:insertions],
|
128
|
+
deletions: stats[:deletions],
|
129
|
+
before: diff.blob(:src).contents,
|
130
|
+
after: diff.blob(:dst).contents
|
131
|
+
}
|
132
|
+
end
|
117
133
|
end
|
118
134
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Danger
|
2
|
+
class Comment
|
3
|
+
attr_reader :id, :body
|
4
|
+
|
5
|
+
def initialize(id, body)
|
6
|
+
@id = id
|
7
|
+
@body = body
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.from_github(comment)
|
11
|
+
self.new(comment[:id], comment[:body])
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_gitlab(comment)
|
15
|
+
self.new(comment.id, comment.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def generated_by_danger?(danger_id)
|
19
|
+
body.include?("generated_by_#{danger_id}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -180,27 +180,6 @@ module Danger
|
|
180
180
|
|
181
181
|
return NEW_REGEX.match(table)
|
182
182
|
end
|
183
|
-
|
184
|
-
class Comment
|
185
|
-
attr_reader :id, :body
|
186
|
-
|
187
|
-
def initialize(id, body)
|
188
|
-
@id = id
|
189
|
-
@body = body
|
190
|
-
end
|
191
|
-
|
192
|
-
def self.from_github(comment)
|
193
|
-
self.new(comment[:id], comment[:body])
|
194
|
-
end
|
195
|
-
|
196
|
-
def self.from_gitlab(comment)
|
197
|
-
self.new(comment.id, comment.body)
|
198
|
-
end
|
199
|
-
|
200
|
-
def generated_by_danger?(danger_id)
|
201
|
-
body.include?("generated_by_#{danger_id}")
|
202
|
-
end
|
203
|
-
end
|
204
183
|
end
|
205
184
|
end
|
206
185
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "danger/helpers/comments_helper"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
module RequestSources
|
6
|
+
class BitbucketCloud < RequestSource
|
7
|
+
include Danger::Helpers::CommentsHelper
|
8
|
+
attr_accessor :pr_json
|
9
|
+
|
10
|
+
def initialize(ci_source, environment)
|
11
|
+
self.ci_source = ci_source
|
12
|
+
self.environment = environment
|
13
|
+
|
14
|
+
project, slug = ci_source.repo_slug.split("/")
|
15
|
+
@api = BitbucketCloudAPI.new(project, slug, ci_source.pull_request_id, environment)
|
16
|
+
end
|
17
|
+
|
18
|
+
def validates_as_ci?
|
19
|
+
# TODO: ???
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def validates_as_api_source?
|
24
|
+
@api.credentials_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def scm
|
28
|
+
@scm ||= GitRepo.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def host
|
32
|
+
@host ||= @api.host
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_details
|
36
|
+
self.pr_json = @api.fetch_pr_json
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup_danger_branches
|
40
|
+
base_commit = self.pr_json[:destination][:commit][:hash]
|
41
|
+
head_commit = self.pr_json[:source][:commit][:hash]
|
42
|
+
|
43
|
+
# Next, we want to ensure that we have a version of the current branch at a known location
|
44
|
+
self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
|
45
|
+
|
46
|
+
# OK, so we want to ensure that we have a known head branch, this will always represent
|
47
|
+
# the head of the PR ( e.g. the most recent commit that will be merged. )
|
48
|
+
self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def organisation
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger")
|
56
|
+
delete_old_comments(danger_id: danger_id)
|
57
|
+
|
58
|
+
comment = generate_description(warnings: warnings, errors: errors)
|
59
|
+
comment += "\n\n"
|
60
|
+
comment += generate_comment(warnings: warnings,
|
61
|
+
errors: errors,
|
62
|
+
messages: messages,
|
63
|
+
markdowns: markdowns,
|
64
|
+
previous_violations: {},
|
65
|
+
danger_id: danger_id,
|
66
|
+
template: "bitbucket_server")
|
67
|
+
|
68
|
+
@api.post_comment(comment)
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete_old_comments(danger_id: "danger")
|
72
|
+
@api.fetch_last_comments.each do |c|
|
73
|
+
@api.delete_comment(c[:id]) if c[:content][:raw] =~ /generated_by_#{danger_id}/
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "danger/helpers/comments_helper"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
module RequestSources
|
6
|
+
class BitbucketCloudAPI
|
7
|
+
attr_accessor :host, :pr_api_endpoint, :pr_api_endpoint_v1
|
8
|
+
|
9
|
+
def initialize(project, slug, pull_request_id, environment)
|
10
|
+
@username = environment["DANGER_BITBUCKETCLOUD_USERNAME"]
|
11
|
+
@password = environment["DANGER_BITBUCKETCLOUD_PASSWORD"]
|
12
|
+
self.pr_api_endpoint = "https://api.bitbucket.org/2.0/repositories/#{project}/#{slug}/pullrequests/#{pull_request_id}"
|
13
|
+
self.pr_api_endpoint_v1 = "https://api.bitbucket.org/1.0/repositories/#{project}/#{slug}/pullrequests/#{pull_request_id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
inspected = super
|
18
|
+
|
19
|
+
if @password
|
20
|
+
inspected = inspected.sub! @password, "********".freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
inspected
|
24
|
+
end
|
25
|
+
|
26
|
+
def credentials_given?
|
27
|
+
@username && !@username.empty? && @password && !@password.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch_pr_json
|
31
|
+
uri = URI(pr_api_endpoint)
|
32
|
+
fetch_json(uri)
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_last_comments
|
36
|
+
uri = URI("#{pr_api_endpoint}/activity?limit=1000")
|
37
|
+
fetch_json(uri)[:values].select { |v| v[:comment] }.map { |v| v[:comment] }
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_comment(id)
|
41
|
+
uri = URI("#{pr_api_endpoint_v1}/comments/#{id}")
|
42
|
+
delete(uri)
|
43
|
+
end
|
44
|
+
|
45
|
+
def post_comment(text)
|
46
|
+
uri = URI("#{pr_api_endpoint_v1}/comments")
|
47
|
+
body = { content: text }.to_json
|
48
|
+
post(uri, body)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def fetch_json(uri)
|
54
|
+
req = Net::HTTP::Get.new(uri.request_uri, { "Content-Type" => "application/json" })
|
55
|
+
req.basic_auth @username, @password
|
56
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
57
|
+
http.request(req)
|
58
|
+
end
|
59
|
+
JSON.parse(res.body, symbolize_names: true)
|
60
|
+
end
|
61
|
+
|
62
|
+
def post(uri, body)
|
63
|
+
req = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
|
64
|
+
req.basic_auth @username, @password
|
65
|
+
req.body = body
|
66
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
67
|
+
http.request(req)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete(uri)
|
72
|
+
req = Net::HTTP::Delete.new(uri.request_uri, { "Content-Type" => "application/json" })
|
73
|
+
req.basic_auth @username, @password
|
74
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
75
|
+
http.request(req)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
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: 3.
|
4
|
+
version: 3.3.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: 2016-09-
|
12
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -398,6 +398,7 @@ files:
|
|
398
398
|
- lib/danger/danger_core/executor.rb
|
399
399
|
- lib/danger/danger_core/messages/markdown.rb
|
400
400
|
- lib/danger/danger_core/messages/violation.rb
|
401
|
+
- lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb
|
401
402
|
- lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb
|
402
403
|
- lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb
|
403
404
|
- lib/danger/danger_core/plugins/dangerfile_git_plugin.rb
|
@@ -405,6 +406,7 @@ files:
|
|
405
406
|
- lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb
|
406
407
|
- lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb
|
407
408
|
- lib/danger/danger_core/standard_error.rb
|
409
|
+
- lib/danger/helpers/comment.rb
|
408
410
|
- lib/danger/helpers/comments_helper.rb
|
409
411
|
- lib/danger/helpers/comments_parsing_helper.rb
|
410
412
|
- lib/danger/plugin_support/plugin.rb
|
@@ -412,6 +414,8 @@ files:
|
|
412
414
|
- lib/danger/plugin_support/plugin_linter.rb
|
413
415
|
- lib/danger/plugin_support/plugin_parser.rb
|
414
416
|
- lib/danger/plugin_support/templates/readme_table.html.erb
|
417
|
+
- lib/danger/request_source/bitbucket_cloud.rb
|
418
|
+
- lib/danger/request_source/bitbucket_cloud_api.rb
|
415
419
|
- lib/danger/request_source/bitbucket_server.rb
|
416
420
|
- lib/danger/request_source/bitbucket_server_api.rb
|
417
421
|
- lib/danger/request_source/github.rb
|