danger 6.0.9 → 6.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/azure_pipelines.rb +44 -0
- data/lib/danger/ci_source/circle_api.rb +1 -1
- data/lib/danger/ci_source/codefresh.rb +53 -0
- data/lib/danger/ci_source/vsts.rb +1 -1
- data/lib/danger/commands/dangerfile/init.rb +1 -1
- data/lib/danger/core_ext/file_list.rb +3 -1
- data/lib/danger/danger_core/environment_manager.rb +3 -2
- data/lib/danger/danger_core/executor.rb +2 -2
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +14 -0
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +4 -4
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +13 -0
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +1 -1
- data/lib/danger/helpers/comments_helper.rb +1 -1
- data/lib/danger/plugin_support/plugin_parser.rb +1 -1
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +7 -7
- data/lib/danger/request_sources/bitbucket_server.rb +9 -0
- data/lib/danger/request_sources/bitbucket_server_api.rb +18 -1
- data/lib/danger/request_sources/github/github.rb +1 -1
- data/lib/danger/request_sources/gitlab.rb +1 -1
- data/lib/danger/request_sources/request_source.rb +4 -0
- data/lib/danger/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c67b44470cd2e591a3308ff21397f02ca56c39df0777856bdb124336b8f34d8
|
4
|
+
data.tar.gz: cb10a0fbe36d92be5346930a12dda0d20f33d093968a8bc60e821894752fe4e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636bd57417f223be9410e682d687eb109a93de82c2836884cc30d378261545f8c3ab1da15c278a893ffd2fcbf024bfadb4ad13f57d15c07bfd9386ac6ede8d59
|
7
|
+
data.tar.gz: 95bd7f1b50c46cb8d62033e72d75c7aab04161590d244ab539c6e96879961f337f165ac9c061514c0c7596812c0d12578d06cb870aac123afc930114cb7e9b38
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
|
2
|
+
require "uri"
|
3
|
+
require "danger/request_sources/github/github"
|
4
|
+
|
5
|
+
module Danger
|
6
|
+
# ### CI Setup
|
7
|
+
#
|
8
|
+
# Add a script step:
|
9
|
+
#
|
10
|
+
# ``` shell
|
11
|
+
# #!/usr/bin/env bash
|
12
|
+
# bundle install
|
13
|
+
# bundle exec danger
|
14
|
+
# ```
|
15
|
+
#
|
16
|
+
# ### Token Setup
|
17
|
+
#
|
18
|
+
# Add the `DANGER_GITHUB_API_TOKEN` to your environment variables.
|
19
|
+
#
|
20
|
+
class AzurePipelines < CI
|
21
|
+
def self.validates_as_ci?(env)
|
22
|
+
env.key? "AGENT_ID"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.validates_as_pr?(env)
|
26
|
+
return env["BUILD_REASON"] == "PullRequest"
|
27
|
+
end
|
28
|
+
|
29
|
+
def supported_request_sources
|
30
|
+
@supported_request_sources ||= [
|
31
|
+
Danger::RequestSources::GitHub,
|
32
|
+
Danger::RequestSources::GitLab,
|
33
|
+
Danger::RequestSources::BitbucketServer,
|
34
|
+
Danger::RequestSources::BitbucketCloud
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(env)
|
39
|
+
self.pull_request_id = env["SYSTEM_PULLREQUEST_PULLREQUESTID"]
|
40
|
+
self.repo_url = env["BUILD_REPOSITORY_URI"]
|
41
|
+
self.repo_slug = env["BUILD_REPOSITORY_NAME"]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -35,7 +35,7 @@ module Danger
|
|
35
35
|
def fetch_pull_request_url(repo_slug, build_number, token)
|
36
36
|
build_json = fetch_build(repo_slug, build_number, token)
|
37
37
|
pull_requests = build_json[:pull_requests]
|
38
|
-
return nil unless pull_requests.first
|
38
|
+
return nil unless pull_requests && pull_requests.first
|
39
39
|
pull_requests.first[:url]
|
40
40
|
end
|
41
41
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# https://semaphoreci.com/docs/available-environment-variables.html
|
2
|
+
require "danger/request_sources/github/github"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
# ### CI Setup
|
6
|
+
#
|
7
|
+
# To set up Danger on Codefresh, create a freestyle step in your Codefresh yaml configuration:
|
8
|
+
#
|
9
|
+
# ```yml
|
10
|
+
# Danger:
|
11
|
+
# title: Run Danger
|
12
|
+
# image: alpine/bundle
|
13
|
+
# working_directory: ${{main_clone}}
|
14
|
+
# commands:
|
15
|
+
# - bundle install --deployment
|
16
|
+
# - bundle exec danger --verbose
|
17
|
+
# ```
|
18
|
+
#
|
19
|
+
# Don't forget to add the `DANGER_GITHUB_API_TOKEN` variable to your pipeline settings so that Danger can properly post comments to your pull request.
|
20
|
+
#
|
21
|
+
class Codefresh < CI
|
22
|
+
def self.validates_as_ci?(env)
|
23
|
+
env.key?("CF_BUILD_ID") && env.key?("CF_BUILD_URL")
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.validates_as_pr?(env)
|
27
|
+
return !env["CF_PULL_REQUEST_NUMBER"].to_s.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def supported_request_sources
|
31
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
32
|
+
end
|
33
|
+
|
34
|
+
def repo_slug
|
35
|
+
return "" if @env["CF_REPO_OWNER"].to_s.empty?
|
36
|
+
return "" if @env["CF_REPO_NAME"].to_s.empty?
|
37
|
+
"#{@env['CF_REPO_OWNER']}/#{@env['CF_REPO_NAME']}".downcase!
|
38
|
+
end
|
39
|
+
|
40
|
+
def repo_url
|
41
|
+
return "" if @env["CF_COMMIT_URL"].to_s.empty?
|
42
|
+
@env["CF_COMMIT_URL"].gsub(/\/commit.+$/, "")
|
43
|
+
end
|
44
|
+
|
45
|
+
def pull_request_id
|
46
|
+
@env["CF_PULL_REQUEST_NUMBER"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def initialize(env)
|
50
|
+
@env = env
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -4,7 +4,7 @@ require "danger/request_sources/vsts"
|
|
4
4
|
module Danger
|
5
5
|
# ### CI Setup
|
6
6
|
#
|
7
|
-
# You need to go to your project's build
|
7
|
+
# You need to go to your project's build definition. Then add a "Command Line" Task with the "Tool" field set to "bundle"
|
8
8
|
# and the "Arguments" field set to "exec danger".
|
9
9
|
#
|
10
10
|
# ### Token Setup
|
@@ -8,7 +8,9 @@ module Danger
|
|
8
8
|
# e.g. "**/something.*" for any file called something with any extension
|
9
9
|
def include?(pattern)
|
10
10
|
self.each do |current|
|
11
|
-
|
11
|
+
unless current.nil?
|
12
|
+
return true if File.fnmatch(pattern, current) || pattern == current
|
13
|
+
end
|
12
14
|
end
|
13
15
|
return false
|
14
16
|
end
|
@@ -3,7 +3,7 @@ require "danger/request_sources/request_source"
|
|
3
3
|
|
4
4
|
module Danger
|
5
5
|
class EnvironmentManager
|
6
|
-
attr_accessor :ci_source, :request_source, :scm, :ui
|
6
|
+
attr_accessor :ci_source, :request_source, :scm, :ui, :danger_id
|
7
7
|
|
8
8
|
# Finds a Danger::CI class based on the ENV
|
9
9
|
def self.local_ci_source(env)
|
@@ -25,10 +25,11 @@ module Danger
|
|
25
25
|
"danger_base".freeze
|
26
26
|
end
|
27
27
|
|
28
|
-
def initialize(env, ui = nil)
|
28
|
+
def initialize(env, ui = nil, danger_id = "danger")
|
29
29
|
ci_klass = self.class.local_ci_source(env)
|
30
30
|
self.ci_source = ci_klass.new(env)
|
31
31
|
self.ui = ui || Cork::Board.new(silent: false, verbose: false)
|
32
|
+
self.danger_id = danger_id
|
32
33
|
|
33
34
|
RequestSources::RequestSource.available_request_sources.each do |klass|
|
34
35
|
next unless self.ci_source.supports?(klass)
|
@@ -21,8 +21,8 @@ module Danger
|
|
21
21
|
# Run some validations
|
22
22
|
validate!(cork, fail_if_no_pr: fail_if_no_pr)
|
23
23
|
|
24
|
-
# OK, we now know that Danger can run in this
|
25
|
-
env ||= EnvironmentManager.new(system_env, cork)
|
24
|
+
# OK, we now know that Danger can run in this environment
|
25
|
+
env ||= EnvironmentManager.new(system_env, cork, danger_id)
|
26
26
|
dm ||= Dangerfile.new(env, cork)
|
27
27
|
|
28
28
|
ran_status = begin
|
@@ -169,6 +169,20 @@ module Danger
|
|
169
169
|
def markdown_link(paths, full_path: true)
|
170
170
|
create_link(paths, full_path) { |href, text| create_markdown_link(href, text) }
|
171
171
|
end
|
172
|
+
|
173
|
+
# @!group Bitbucket Server Misc
|
174
|
+
# Updates the PR with build status and build server job link.
|
175
|
+
# @param [String] status
|
176
|
+
# SUCCESSFUL, FAILED and INPROGRESS
|
177
|
+
# @param [String] build_job_link
|
178
|
+
# Build server job link
|
179
|
+
# @param [String] description
|
180
|
+
# Build status description
|
181
|
+
# @return [String]
|
182
|
+
#
|
183
|
+
def update_pr_build_status(status, build_job_link, description)
|
184
|
+
@bs.update_pr_build_status(status, build_job_link, description)
|
185
|
+
end
|
172
186
|
|
173
187
|
private
|
174
188
|
|
@@ -2,7 +2,7 @@ require "danger/plugin_support/plugin"
|
|
2
2
|
|
3
3
|
module Danger
|
4
4
|
# A way to interact with Danger herself. Offering APIs to import plugins,
|
5
|
-
# and Dangerfiles from
|
5
|
+
# and Dangerfiles from multiple sources.
|
6
6
|
#
|
7
7
|
# @example Import a plugin available over HTTP
|
8
8
|
#
|
@@ -27,7 +27,7 @@ module Danger
|
|
27
27
|
#
|
28
28
|
# @example Run a Dangerfile from inside a repo
|
29
29
|
#
|
30
|
-
# danger.import_dangerfile(
|
30
|
+
# danger.import_dangerfile(gitlab_project_id: 1345)
|
31
31
|
#
|
32
32
|
# @example Run a Dangerfile from inside a repo branch and path
|
33
33
|
#
|
@@ -85,10 +85,10 @@ module Danger
|
|
85
85
|
elsif opts.key?(:gem)
|
86
86
|
import_dangerfile_from_gem(opts[:gem])
|
87
87
|
else
|
88
|
-
raise "`import` requires a Hash with either :github or :
|
88
|
+
raise "`import` requires a Hash with either :github, :gitlab, :gem, or :path"
|
89
89
|
end
|
90
90
|
else
|
91
|
-
raise "`import` requires a Hash"
|
91
|
+
raise "`import` requires a Hash"
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -53,6 +53,19 @@ module Danger
|
|
53
53
|
#
|
54
54
|
# warn "#{gitlab.html_link("Package.json")} was edited." if git.modified_files.include? "Package.json"
|
55
55
|
#
|
56
|
+
# @example Select a random group member as assignee if no assignee is selected
|
57
|
+
#
|
58
|
+
# if gitlab.mr_json["assignee"].nil?
|
59
|
+
# reviewer = gitlab.api.group_members(gitlab.api.merge_request_approvals(project_id, mr_id).to_hash["approver_groups"].first["group"]["id"]).sample
|
60
|
+
# if gitlab.api.group_members(gitlab.api.merge_request_approvals(project_id, mr_id).to_hash["approver_groups"].first["group"]["id"]).length > 1
|
61
|
+
# while reviewer.to_hash["id"] == gitlab.mr_json["author"]["id"] do
|
62
|
+
# reviewer = gitlab.api.group_members(gitlab.api.merge_request_approvals(project_id, mr_id).to_hash["approver_groups"].first["group"]["id"]).sample
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
# message "Reviewer roulete rolled for: #{reviewer.to_hash['name']} (@#{reviewer.to_hash['username']})"
|
66
|
+
# gitlab.api.update_merge_request(project_id, mr_id, { assignee_id: reviewer.to_hash["id"] })
|
67
|
+
# end
|
68
|
+
#
|
56
69
|
#
|
57
70
|
# @see danger/danger
|
58
71
|
# @tags core, gitlab
|
@@ -34,7 +34,7 @@ module Danger
|
|
34
34
|
# @example Failing a build
|
35
35
|
#
|
36
36
|
# failure "This build didn't pass tests"
|
37
|
-
# failure "Ooops!", "Something bad
|
37
|
+
# failure "Ooops!", "Something bad happened"
|
38
38
|
# failure ["This is example", "with array"]
|
39
39
|
#
|
40
40
|
# @example Failing a build, and note that on subsequent runs
|
@@ -34,7 +34,7 @@ module Danger
|
|
34
34
|
# request_source implementations are invited to override this method.
|
35
35
|
# This is mostly here to enable sources to detect when inlines change only in their
|
36
36
|
# commit hash and not in content per-se. since the link is implementation dependant
|
37
|
-
# so should be the
|
37
|
+
# so should be the comparison.
|
38
38
|
#
|
39
39
|
# @param [Violation or Markdown] m1
|
40
40
|
# @param [Violation or Markdown] m2
|
@@ -45,13 +45,17 @@ module Danger
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def delete_comment(id)
|
48
|
-
uri = URI("#{
|
48
|
+
uri = URI("#{pr_api_endpoint}/comments/#{id}")
|
49
49
|
delete(uri)
|
50
50
|
end
|
51
51
|
|
52
52
|
def post_comment(text)
|
53
|
-
uri = URI("#{
|
54
|
-
body = {
|
53
|
+
uri = URI("#{pr_api_endpoint}/comments")
|
54
|
+
body = {
|
55
|
+
content: {
|
56
|
+
raw: text
|
57
|
+
}
|
58
|
+
}.to_json
|
55
59
|
post(uri, body)
|
56
60
|
end
|
57
61
|
|
@@ -65,10 +69,6 @@ module Danger
|
|
65
69
|
"#{base_url(2)}/#{pull_request_id}"
|
66
70
|
end
|
67
71
|
|
68
|
-
def pr_api_endpoint_v1
|
69
|
-
"#{base_url(1)}/#{pull_request_id}"
|
70
|
-
end
|
71
|
-
|
72
72
|
def prs_api_endpoint(branch_name)
|
73
73
|
"#{base_url(2)}?q=source.branch.name=\"#{branch_name}\""
|
74
74
|
end
|
@@ -91,6 +91,15 @@ module Danger
|
|
91
91
|
@api.delete_comment(c[:id], c[:version]) if c[:text] =~ /generated_by_#{danger_id}/
|
92
92
|
end
|
93
93
|
end
|
94
|
+
|
95
|
+
def update_pr_build_status(status, build_job_link, description)
|
96
|
+
changeset = self.pr_json[:fromRef][:latestCommit]
|
97
|
+
# Support for older versions of Bitbucket Server
|
98
|
+
changeset = self.pr_json[:fromRef][:latestChangeset] if self.pr_json[:fromRef].key? :latestChangeset
|
99
|
+
puts "Changeset: " + changeset
|
100
|
+
puts self.pr_json.to_json
|
101
|
+
@api.update_pr_build_status(status, changeset, build_job_link, description)
|
102
|
+
end
|
94
103
|
end
|
95
104
|
end
|
96
105
|
end
|
@@ -5,7 +5,7 @@ require "danger/helpers/comments_helper"
|
|
5
5
|
module Danger
|
6
6
|
module RequestSources
|
7
7
|
class BitbucketServerAPI
|
8
|
-
attr_accessor :host, :pr_api_endpoint
|
8
|
+
attr_accessor :host, :pr_api_endpoint, :key, :project
|
9
9
|
|
10
10
|
def initialize(project, slug, pull_request_id, environment)
|
11
11
|
@username = environment["DANGER_BITBUCKETSERVER_USERNAME"]
|
@@ -14,6 +14,8 @@ module Danger
|
|
14
14
|
if self.host && !(self.host.include? "http://") && !(self.host.include? "https://")
|
15
15
|
self.host = "https://" + self.host
|
16
16
|
end
|
17
|
+
self.key = slug
|
18
|
+
self.project = project
|
17
19
|
self.pr_api_endpoint = "#{host}/rest/api/1.0/projects/#{project}/repos/#{slug}/pull-requests/#{pull_request_id}"
|
18
20
|
end
|
19
21
|
|
@@ -55,6 +57,12 @@ module Danger
|
|
55
57
|
body = { text: text }.to_json
|
56
58
|
post(uri, body)
|
57
59
|
end
|
60
|
+
|
61
|
+
def update_pr_build_status(status, changeset, build_job_link, description)
|
62
|
+
uri = URI("#{self.host}/rest/build-status/1.0/commits/#{changeset}")
|
63
|
+
body = build_status_body(status, build_job_link, description)
|
64
|
+
post(uri, body)
|
65
|
+
end
|
58
66
|
|
59
67
|
private
|
60
68
|
|
@@ -95,6 +103,15 @@ module Danger
|
|
95
103
|
http.request(req)
|
96
104
|
end
|
97
105
|
end
|
106
|
+
|
107
|
+
def build_status_body(status, build_job_link, description)
|
108
|
+
body = Hash.new
|
109
|
+
body["state"] = status
|
110
|
+
body["key"] = self.key
|
111
|
+
body["url"] = build_job_link
|
112
|
+
body["description"] = description if description
|
113
|
+
return body.to_json
|
114
|
+
end
|
98
115
|
end
|
99
116
|
end
|
100
117
|
end
|
@@ -276,7 +276,7 @@ module Danger
|
|
276
276
|
else
|
277
277
|
# We remove non-sticky violations that have no replies
|
278
278
|
# Since there's no direct concept of a reply in GH, we simply consider
|
279
|
-
# the
|
279
|
+
# the existence of non-danger comments in that line as replies
|
280
280
|
replies = non_danger_comments.select do |potential|
|
281
281
|
potential["path"] == comment["path"] &&
|
282
282
|
potential["position"] == comment["position"] &&
|
@@ -360,7 +360,7 @@ module Danger
|
|
360
360
|
else
|
361
361
|
# We remove non-sticky violations that have no replies
|
362
362
|
# Since there's no direct concept of a reply in GH, we simply consider
|
363
|
-
# the
|
363
|
+
# the existence of non-danger comments in that line as replies
|
364
364
|
replies = non_danger_comments.select do |potential|
|
365
365
|
potential["path"] == comment["path"] &&
|
366
366
|
potential["position"] == comment["position"] &&
|
@@ -76,6 +76,10 @@ module Danger
|
|
76
76
|
def file_url(_organisation: nil, _repository: nil, _branch: "master", _path: nil)
|
77
77
|
raise "Subclass and overwrite file_url"
|
78
78
|
end
|
79
|
+
|
80
|
+
def update_build_status(status)
|
81
|
+
raise "Subclass and overwrite update_build_status"
|
82
|
+
end
|
79
83
|
end
|
80
84
|
end
|
81
85
|
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: 6.0
|
4
|
+
version: 6.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: 2019-
|
12
|
+
date: 2019-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- lib/danger.rb
|
196
196
|
- lib/danger/ci_source/appcenter.rb
|
197
197
|
- lib/danger/ci_source/appveyor.rb
|
198
|
+
- lib/danger/ci_source/azure_pipelines.rb
|
198
199
|
- lib/danger/ci_source/bitbucket_pipelines.rb
|
199
200
|
- lib/danger/ci_source/bitrise.rb
|
200
201
|
- lib/danger/ci_source/buddybuild.rb
|
@@ -204,6 +205,7 @@ files:
|
|
204
205
|
- lib/danger/ci_source/circle_api.rb
|
205
206
|
- lib/danger/ci_source/cirrus.rb
|
206
207
|
- lib/danger/ci_source/code_build.rb
|
208
|
+
- lib/danger/ci_source/codefresh.rb
|
207
209
|
- lib/danger/ci_source/codeship.rb
|
208
210
|
- lib/danger/ci_source/dotci.rb
|
209
211
|
- lib/danger/ci_source/drone.rb
|