danger 8.2.1 → 8.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/danger/ci_source/azure_pipelines.rb +5 -1
- data/lib/danger/ci_source/buildkite.rb +1 -1
- data/lib/danger/ci_source/codefresh.rb +7 -13
- data/lib/danger/ci_source/codemagic.rb +58 -0
- data/lib/danger/ci_source/gitlab_ci.rb +18 -17
- data/lib/danger/ci_source/jenkins.rb +1 -1
- data/lib/danger/ci_source/local_git_repo.rb +29 -37
- data/lib/danger/ci_source/local_only_git_repo.rb +4 -8
- data/lib/danger/ci_source/support/commits.rb +14 -12
- data/lib/danger/ci_source/support/pull_request_finder.rb +43 -40
- data/lib/danger/ci_source/xcode_cloud.rb +38 -0
- data/lib/danger/commands/dangerfile/init.rb +1 -1
- data/lib/danger/commands/pr.rb +2 -1
- data/lib/danger/comment_generators/gitlab_inline.md.erb +2 -7
- data/lib/danger/comment_generators/vsts_inline.md.erb +17 -0
- data/lib/danger/danger_core/dangerfile.rb +15 -8
- data/lib/danger/danger_core/environment_manager.rb +2 -0
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +1 -1
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +8 -0
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +16 -0
- data/lib/danger/helpers/array_subclass.rb +2 -2
- data/lib/danger/helpers/comments_helper.rb +4 -3
- data/lib/danger/helpers/emoji_mapper.rb +1 -1
- data/lib/danger/plugin_support/plugin.rb +6 -2
- data/lib/danger/request_sources/bitbucket_cloud.rb +0 -1
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +7 -6
- data/lib/danger/request_sources/bitbucket_server.rb +20 -16
- data/lib/danger/request_sources/bitbucket_server_api.rb +17 -9
- data/lib/danger/request_sources/code_insights_api.rb +2 -3
- data/lib/danger/request_sources/github/github.rb +30 -26
- data/lib/danger/request_sources/gitlab.rb +24 -24
- data/lib/danger/request_sources/local_only.rb +1 -2
- data/lib/danger/request_sources/request_source.rb +16 -4
- data/lib/danger/request_sources/vsts.rb +171 -9
- data/lib/danger/request_sources/vsts_api.rb +34 -3
- data/lib/danger/scm_source/git_repo.rb +2 -1
- data/lib/danger/version.rb +1 -1
- metadata +17 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 691f7a26ea0a29f107e6f848bdf7450d2043dc15f5c385c136c1a9d818120c3f
|
4
|
+
data.tar.gz: d5f84a85ec8419dbbfbdcb742ffb15b5fe075d3bf1f676859152a0bb7b466633
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b712f8566113397b952ebd93e33d1d42b38d1b1a9d04e678971c35feb46a5bfb057236b0ccffc250560df6b1da001fe31f848024de318850c93ecb6af6eb0994
|
7
|
+
data.tar.gz: c89ab31d3afe5d668046629643d65858d6eeeea3d5f67006170af38e9a8c31673789de472501d37ff923c41fb538193cce767ae9567ef4a9a474aca96cf4aad4
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ I'd strongly recommend using `bundle exec guard` to run your tests as you work.
|
|
76
76
|
|
77
77
|
#### Debugging
|
78
78
|
|
79
|
-
Ruby is super dynamic. One of the best ways to debug Ruby code is by using [pry](
|
79
|
+
Ruby is super dynamic. One of the best ways to debug Ruby code is by using [pry](https://pry.github.io/). We include pry for developers: when you have a problem, copy these two lines just before your problem and follow the instructions from "[I Want To Be A Danger Wizard](https://danger.systems/guides/troubleshooting.html#i-want-to-be-a-danger-wizard)."
|
80
80
|
|
81
81
|
```ruby
|
82
82
|
require 'pry'
|
@@ -19,7 +19,11 @@ module Danger
|
|
19
19
|
#
|
20
20
|
class AzurePipelines < CI
|
21
21
|
def self.validates_as_ci?(env)
|
22
|
-
|
22
|
+
# AGENT_ID is being used by AppCenter as well, so checking here to make sure AppCenter CI doesn't get a false positive for AzurePipelines
|
23
|
+
# Anyone working with AzurePipelines could provide a better/truly unique env key to avoid checking for AppCenter
|
24
|
+
!Danger::Appcenter::validates_as_ci?(env) &&
|
25
|
+
env.key?("AGENT_ID") &&
|
26
|
+
env["BUILD_REPOSITORY_PROVIDER"] != "TfsGit"
|
23
27
|
end
|
24
28
|
|
25
29
|
def self.validates_as_pr?(env)
|
@@ -45,7 +45,7 @@ module Danger
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def supported_request_sources
|
48
|
-
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]
|
48
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab, Danger::RequestSources::BitbucketServer]
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -31,23 +31,17 @@ module Danger
|
|
31
31
|
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
return "" if
|
36
|
-
return "" if
|
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
|
34
|
+
def self.slug_from(env)
|
35
|
+
return "" if env["CF_REPO_OWNER"].to_s.empty?
|
36
|
+
return "" if env["CF_REPO_NAME"].to_s.empty?
|
44
37
|
|
45
|
-
|
46
|
-
@env["CF_PULL_REQUEST_NUMBER"]
|
38
|
+
"#{env['CF_REPO_OWNER']}/#{env['CF_REPO_NAME']}".downcase!
|
47
39
|
end
|
48
40
|
|
49
41
|
def initialize(env)
|
50
|
-
|
42
|
+
self.repo_url = env["CF_COMMIT_URL"].to_s.gsub(/\/commit.+$/, "")
|
43
|
+
self.repo_slug = self.class.slug_from(env)
|
44
|
+
self.pull_request_id = env["CF_PULL_REQUEST_NUMBER"]
|
51
45
|
end
|
52
46
|
end
|
53
47
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# https://docs.codemagic.io/building/environment-variables/
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
# ### CI Setup
|
5
|
+
#
|
6
|
+
# Add a script step to your workflow:
|
7
|
+
#
|
8
|
+
# ```
|
9
|
+
# - name: Running Danger
|
10
|
+
# script: |
|
11
|
+
# bundle install
|
12
|
+
# bundle exec danger
|
13
|
+
# ```
|
14
|
+
#
|
15
|
+
# ### Token Setup
|
16
|
+
#
|
17
|
+
# Add the following environment variables to your workflow's environment configuration.
|
18
|
+
# https://docs.codemagic.io/getting-started/yaml/
|
19
|
+
#
|
20
|
+
# #### GitHub
|
21
|
+
# Add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV.
|
22
|
+
#
|
23
|
+
# #### GitLab
|
24
|
+
# Add the `DANGER_GITLAB_API_TOKEN` to your build user's ENV.
|
25
|
+
#
|
26
|
+
# #### Bitbucket Cloud
|
27
|
+
# Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
|
28
|
+
# to your build user's ENV.
|
29
|
+
#
|
30
|
+
# #### Bitbucket server
|
31
|
+
# Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
|
32
|
+
# and `DANGER_BITBUCKETSERVER_HOST` to your build user's ENV.
|
33
|
+
#
|
34
|
+
class Codemagic < CI
|
35
|
+
def self.validates_as_ci?(env)
|
36
|
+
env.key? "FCI_PROJECT_ID"
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.validates_as_pr?(env)
|
40
|
+
return !env["FCI_PULL_REQUEST_NUMBER"].to_s.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
def supported_request_sources
|
44
|
+
@supported_request_sources ||= [
|
45
|
+
Danger::RequestSources::GitHub,
|
46
|
+
Danger::RequestSources::GitLab,
|
47
|
+
Danger::RequestSources::BitbucketServer,
|
48
|
+
Danger::RequestSources::BitbucketCloud
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(env)
|
53
|
+
self.pull_request_id = env["FCI_PULL_REQUEST_NUMBER"]
|
54
|
+
self.repo_slug = env["FCI_REPO_SLUG"]
|
55
|
+
self.repo_url = GitRepo.new.origins # Codemagic doesn't provide a repo url env variable for n
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -46,10 +46,17 @@ module Danger
|
|
46
46
|
base_commit = env["CI_COMMIT_SHA"]
|
47
47
|
client = RequestSources::GitLab.new(nil, env).client
|
48
48
|
|
49
|
-
|
49
|
+
client_version = Gem::Version.new(client.version.version)
|
50
|
+
if (client_version >= Gem::Version.new("10.7"))
|
50
51
|
#Use the 'list merge requests associated with a commit' API, for speeed
|
51
52
|
# (GET /projects/:id/repository/commits/:sha/merge_requests) available for GitLab >= 10.7
|
52
53
|
merge_request = client.commit_merge_requests(project_path, base_commit, state: :opened).first
|
54
|
+
if (client_version >= Gem::Version.new("13.8"))
|
55
|
+
# Gitlab 13.8.0 started returning merge requests for merge commits and squashed commits
|
56
|
+
# By checking for merge_request.state, we can ensure danger only comments on MRs which are open
|
57
|
+
return 0 if merge_request.nil?
|
58
|
+
return 0 unless merge_request.state == "opened"
|
59
|
+
end
|
53
60
|
else
|
54
61
|
merge_requests = client.merge_requests(project_path, state: :opened)
|
55
62
|
merge_request = merge_requests.auto_paginate.find do |mr|
|
@@ -59,9 +66,17 @@ module Danger
|
|
59
66
|
merge_request.nil? ? 0 : merge_request.iid
|
60
67
|
end
|
61
68
|
|
69
|
+
def self.slug_from(env)
|
70
|
+
if env["DANGER_PROJECT_REPO_URL"]
|
71
|
+
env["DANGER_PROJECT_REPO_URL"].split('/').last(2).join('/')
|
72
|
+
else
|
73
|
+
env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
62
77
|
def initialize(env)
|
63
|
-
|
64
|
-
|
78
|
+
self.repo_slug = self.class.slug_from(env)
|
79
|
+
self.pull_request_id = self.class.determine_pull_or_merge_request_id(env)
|
65
80
|
end
|
66
81
|
|
67
82
|
def supported_request_sources
|
@@ -70,19 +85,5 @@ module Danger
|
|
70
85
|
Danger::RequestSources::GitLab
|
71
86
|
]
|
72
87
|
end
|
73
|
-
|
74
|
-
def pull_request_id
|
75
|
-
@pull_request_id ||= self.class.determine_pull_or_merge_request_id(@env)
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def slug_from(env)
|
81
|
-
if env["DANGER_PROJECT_REPO_URL"]
|
82
|
-
env["DANGER_PROJECT_REPO_URL"].split('/').last(2).join('/')
|
83
|
-
else
|
84
|
-
env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
|
85
|
-
end
|
86
|
-
end
|
87
88
|
end
|
88
89
|
end
|
@@ -133,7 +133,7 @@ module Danger
|
|
133
133
|
matches = change_url.match(%r{(.+)\/pull\/[0-9]+})
|
134
134
|
matches[1] unless matches.nil?
|
135
135
|
when %r{\/merge_requests\/} # GitLab
|
136
|
-
matches = change_url.match(%r{(
|
136
|
+
matches = change_url.match(%r{(.+?)(\/-)?\/merge_requests\/[0-9]+})
|
137
137
|
matches[1] unless matches.nil?
|
138
138
|
when %r{\/pull-requests\/} # Bitbucket
|
139
139
|
matches = change_url.match(%r{(.+)\/pull-requests\/[0-9]+})
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# For more info see: https://github.com/schacon/ruby-git
|
2
3
|
|
3
4
|
require "git"
|
@@ -37,8 +38,8 @@ module Danger
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def initialize(env = {})
|
40
|
-
@
|
41
|
-
|
41
|
+
@remote_info = find_remote_info(env)
|
42
|
+
@found_pull_request = find_pull_request(env)
|
42
43
|
self.repo_slug = remote_info.slug
|
43
44
|
raise_error_for_missing_remote if remote_info.kind_of?(NoRepoInfo)
|
44
45
|
|
@@ -55,7 +56,7 @@ module Danger
|
|
55
56
|
|
56
57
|
private
|
57
58
|
|
58
|
-
attr_reader :
|
59
|
+
attr_reader :remote_info, :found_pull_request
|
59
60
|
|
60
61
|
def raise_error_for_missing_remote
|
61
62
|
raise missing_remote_error_message
|
@@ -66,45 +67,36 @@ module Danger
|
|
66
67
|
"And the repository must host on GitHub.com or GitHub Enterprise."
|
67
68
|
end
|
68
69
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
).call
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
remote_info || NoRepoInfo.new
|
83
|
-
end
|
70
|
+
def find_remote_info(env)
|
71
|
+
if given_pull_request_url?(env)
|
72
|
+
FindRepoInfoFromURL.new(env["LOCAL_GIT_PR_URL"]).call
|
73
|
+
else
|
74
|
+
FindRepoInfoFromLogs.new(
|
75
|
+
env["DANGER_GITHUB_HOST"] || "github.com",
|
76
|
+
run_git("remote show origin -n")
|
77
|
+
).call
|
78
|
+
end || NoRepoInfo.new
|
84
79
|
end
|
85
80
|
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
git_logs: run_git("log --oneline -1000000".freeze)
|
102
|
-
).call
|
103
|
-
end
|
81
|
+
def find_pull_request(env)
|
82
|
+
if given_pull_request_url?(env)
|
83
|
+
PullRequestFinder.new(
|
84
|
+
remote_info.id,
|
85
|
+
remote_info.slug,
|
86
|
+
remote: true,
|
87
|
+
remote_url: env["LOCAL_GIT_PR_URL"]
|
88
|
+
).call(env: env)
|
89
|
+
else
|
90
|
+
PullRequestFinder.new(
|
91
|
+
env.fetch("LOCAL_GIT_PR_ID") { "" },
|
92
|
+
remote_info.slug,
|
93
|
+
remote: false,
|
94
|
+
git_logs: run_git("log --oneline -1000000")
|
95
|
+
).call(env: env)
|
104
96
|
end
|
105
97
|
end
|
106
98
|
|
107
|
-
def given_pull_request_url?
|
99
|
+
def given_pull_request_url?(env)
|
108
100
|
env["LOCAL_GIT_PR_URL"] && !env["LOCAL_GIT_PR_URL"].empty?
|
109
101
|
end
|
110
102
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "git"
|
2
4
|
require "danger/request_sources/local_only"
|
3
5
|
|
@@ -9,8 +11,8 @@ module Danger
|
|
9
11
|
#
|
10
12
|
class LocalOnlyGitRepo < CI
|
11
13
|
attr_accessor :base_commit, :head_commit
|
12
|
-
HEAD_VAR = "DANGER_LOCAL_HEAD"
|
13
|
-
BASE_VAR = "DANGER_LOCAL_BASE"
|
14
|
+
HEAD_VAR = "DANGER_LOCAL_HEAD"
|
15
|
+
BASE_VAR = "DANGER_LOCAL_BASE"
|
14
16
|
|
15
17
|
def self.validates_as_ci?(env)
|
16
18
|
env.key? "DANGER_USE_LOCAL_ONLY_GIT"
|
@@ -33,15 +35,9 @@ module Danger
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def initialize(env = {})
|
36
|
-
@env = env
|
37
|
-
|
38
38
|
# expects --base/--head specified OR origin/master to be base and HEAD head
|
39
39
|
self.base_commit = env[BASE_VAR] || run_git("rev-parse --abbrev-ref origin/master")
|
40
40
|
self.head_commit = env[HEAD_VAR] || run_git("rev-parse --abbrev-ref HEAD")
|
41
41
|
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
attr_reader :env
|
46
42
|
end
|
47
43
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Danger
|
2
|
+
class Commits
|
3
|
+
def initialize(base_head)
|
4
|
+
@base_head = base_head.strip.split(" ".freeze)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def base
|
8
|
+
base_head.first
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def head
|
12
|
+
base_head.last
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
private
|
15
16
|
|
16
|
-
|
17
|
+
attr_reader :base_head
|
18
|
+
end
|
17
19
|
end
|
@@ -1,67 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "danger/ci_source/support/local_pull_request"
|
2
4
|
require "danger/ci_source/support/remote_pull_request"
|
3
5
|
require "danger/ci_source/support/no_pull_request"
|
4
6
|
|
5
7
|
module Danger
|
6
8
|
class PullRequestFinder
|
7
|
-
def initialize(specific_pull_request_id, repo_slug = nil, remote: false, git_logs: "", remote_url: ""
|
9
|
+
def initialize(specific_pull_request_id, repo_slug = nil, remote: false, git_logs: "", remote_url: "")
|
8
10
|
@specific_pull_request_id = specific_pull_request_id
|
9
11
|
@git_logs = git_logs
|
10
12
|
@repo_slug = repo_slug
|
11
13
|
@remote = to_boolean(remote)
|
12
14
|
@remote_url = remote_url
|
13
|
-
@env = env
|
14
15
|
end
|
15
16
|
|
16
|
-
def call
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def call(env: nil)
|
18
|
+
find_pull_request(env).tap do |pull_request|
|
19
|
+
raise_pull_request_not_found!(pull_request) unless pull_request.valid?
|
20
|
+
end
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
attr_reader :specific_pull_request_id, :git_logs, :repo_slug, :remote, :remote_url
|
25
|
+
attr_reader :specific_pull_request_id, :git_logs, :repo_slug, :remote, :remote_url
|
25
26
|
|
26
27
|
def to_boolean(maybe_string)
|
27
28
|
["true", "1", "yes", "y", true].include?(maybe_string)
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
raise "No recent Pull Requests found for this repo, danger requires at least one Pull Request for the local mode.".freeze
|
36
|
-
end
|
31
|
+
def raise_pull_request_not_found!(pull_request)
|
32
|
+
if specific_pull_request_id.empty?
|
33
|
+
raise "No recent Pull Requests found for this repo, danger requires at least one Pull Request for the local mode."
|
34
|
+
else
|
35
|
+
raise "Could not find the Pull Request (#{specific_pull_request_id}) inside the git history for this repo."
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
39
|
# @return [String] Log line of most recent merged Pull Request
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
40
|
+
def find_pull_request(env)
|
41
|
+
return if pull_request_ref.empty?
|
42
|
+
|
43
|
+
if both_present?
|
44
|
+
LocalPullRequest.new(pick_the_most_recent_one_from_two_matches)
|
45
|
+
elsif only_merged_pull_request_present?
|
46
|
+
LocalPullRequest.new(most_recent_merged_pull_request)
|
47
|
+
elsif only_squash_and_merged_pull_request_present?
|
48
|
+
LocalPullRequest.new(most_recent_squash_and_merged_pull_request)
|
49
|
+
elsif remote
|
50
|
+
remote_pull_request = find_remote_pull_request(env)
|
51
|
+
remote_pull_request ? generate_remote_pull_request(remote_pull_request) : NoPullRequest.new
|
52
|
+
else
|
53
|
+
NoPullRequest.new
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
# @return [String] "#42"
|
60
58
|
def pull_request_ref
|
61
|
-
!specific_pull_request_id.empty? ? "##{specific_pull_request_id}" : "#\\d+"
|
59
|
+
!specific_pull_request_id.empty? ? "##{specific_pull_request_id}" : "#\\d+"
|
62
60
|
end
|
63
61
|
|
64
|
-
def generate_remote_pull_request
|
62
|
+
def generate_remote_pull_request(remote_pull_request)
|
65
63
|
scm_provider = find_scm_provider(remote_url)
|
66
64
|
|
67
65
|
case scm_provider
|
@@ -88,10 +86,8 @@ module Danger
|
|
88
86
|
end
|
89
87
|
end
|
90
88
|
|
91
|
-
def
|
92
|
-
|
93
|
-
client.pull_request(repo_slug, specific_pull_request_id)
|
94
|
-
end
|
89
|
+
def find_remote_pull_request(env)
|
90
|
+
client(env).pull_request(repo_slug, specific_pull_request_id)
|
95
91
|
end
|
96
92
|
|
97
93
|
def both_present?
|
@@ -135,9 +131,9 @@ module Danger
|
|
135
131
|
!most_recent_squash_and_merged_pull_request.nil? && !most_recent_squash_and_merged_pull_request.empty?
|
136
132
|
end
|
137
133
|
|
138
|
-
def client
|
134
|
+
def client(env)
|
139
135
|
scm_provider = find_scm_provider(remote_url)
|
140
|
-
|
136
|
+
|
141
137
|
case scm_provider
|
142
138
|
when :bitbucket_cloud
|
143
139
|
require "danger/request_sources/bitbucket_cloud_api"
|
@@ -151,8 +147,15 @@ module Danger
|
|
151
147
|
|
152
148
|
when :github
|
153
149
|
require "octokit"
|
154
|
-
|
155
|
-
|
150
|
+
access_token = ENV["DANGER_GITHUB_API_TOKEN"]
|
151
|
+
bearer_token = ENV["DANGER_GITHUB_BEARER_TOKEN"]
|
152
|
+
if bearer_token && !bearer_token.empty?
|
153
|
+
Octokit::Client.new(bearer_token: bearer_token, api_endpoint: api_url)
|
154
|
+
elsif access_token && !access_token.empty?
|
155
|
+
Octokit::Client.new(access_token: access_token, api_endpoint: api_url)
|
156
|
+
else
|
157
|
+
raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN` or `DANGER_GITHUB_BEARER_TOKEN`"
|
158
|
+
end
|
156
159
|
else
|
157
160
|
raise "SCM provider not supported: #{scm_provider}"
|
158
161
|
end
|
@@ -161,7 +164,7 @@ module Danger
|
|
161
164
|
def api_url
|
162
165
|
ENV.fetch("DANGER_GITHUB_API_HOST") do
|
163
166
|
ENV.fetch("DANGER_GITHUB_API_BASE_URL") do
|
164
|
-
"https://api.github.com/"
|
167
|
+
"https://api.github.com/"
|
165
168
|
end
|
166
169
|
end
|
167
170
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Danger
|
2
|
+
# ### CI Setup
|
3
|
+
#
|
4
|
+
# In order to work with Xcode Cloud and Danger, you will need to add `bundle exec danger` to
|
5
|
+
# the `ci_scripts/ci_post_xcodebuild.sh` (Xcode Cloud's expected filename for a post-action build script).
|
6
|
+
# More details and documentation on Xcode Cloud configuration can be found [here](https://developer.apple.com/documentation/xcode/writing-custom-build-scripts).
|
7
|
+
#
|
8
|
+
# ### Token Setup
|
9
|
+
#
|
10
|
+
# You will need to add the `DANGER_GITHUB_API_TOKEN` to your build environment.
|
11
|
+
# If running on GitHub Enterprise, make sure you also set the expected values for
|
12
|
+
# both `DANGER_GITHUB_API_HOST` and `DANGER_GITHUB_HOST`.
|
13
|
+
#
|
14
|
+
class XcodeCloud < CI
|
15
|
+
def self.validates_as_ci?(env)
|
16
|
+
env.key? "CI_XCODEBUILD_ACTION"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.validates_as_pr?(env)
|
20
|
+
env.key? "CI_PULL_REQUEST_NUMBER"
|
21
|
+
end
|
22
|
+
|
23
|
+
def supported_request_sources
|
24
|
+
@supported_request_sources ||= [
|
25
|
+
Danger::RequestSources::GitHub,
|
26
|
+
Danger::RequestSources::GitLab,
|
27
|
+
Danger::RequestSources::BitbucketCloud,
|
28
|
+
Danger::RequestSources::BitbucketServer
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(env)
|
33
|
+
self.repo_slug = env["CI_PULL_REQUEST_SOURCE_REPO"]
|
34
|
+
self.pull_request_id = env["CI_PULL_REQUEST_NUMBER"]
|
35
|
+
self.repo_url = env["CI_PULL_REQUEST_HTML_URL"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -4,7 +4,7 @@ require "danger/danger_core/dangerfile_generator"
|
|
4
4
|
|
5
5
|
module Danger
|
6
6
|
class DangerfileCommand < Runner
|
7
|
-
self.summary = "Easily create
|
7
|
+
self.summary = "Easily create your Dangerfiles."
|
8
8
|
self.command = "dangerfile"
|
9
9
|
|
10
10
|
self.abstract_command = true
|
data/lib/danger/commands/pr.rb
CHANGED
@@ -17,10 +17,5 @@
|
|
17
17
|
<%= current %>
|
18
18
|
<%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
|
19
19
|
<%- end -%>
|
20
|
-
<%#
|
21
|
-
|
22
|
-
<%- if @markdowns.count > 0 -%>
|
23
|
-
<p align="right" data-meta="generated_by_<%= @danger_id %>">
|
24
|
-
Generated by :no_entry_sign: <a href="http://danger.systems/">Danger</a>
|
25
|
-
</p>
|
26
|
-
<%- end -%>
|
20
|
+
<%# Add the generated_by_ as a html coment to identify comments from danger. %>
|
21
|
+
<!-- "generated_by_<%= @danger_id %>" -->
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%- @tables.each do |table| -%>
|
2
|
+
<%- if table[:content].any? || table[:resolved].any? -%>
|
3
|
+
| | |
|
4
|
+
|---|---|
|
5
|
+
<%- table[:content].each do |violation| -%>
|
6
|
+
| <%= @emoji_mapper.map(table[:emoji]) %> | <%= "~~" if table[:resolved] %><%= violation.message %><%= "~~" if table[:resolved] %> |
|
7
|
+
<%- end -%>
|
8
|
+
|
9
|
+
<%- end -%>
|
10
|
+
<%- end -%>
|
11
|
+
|
12
|
+
<%- @markdowns.each do |current| -%>
|
13
|
+
<%= current %>
|
14
|
+
<%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
|
15
|
+
<%- end -%>
|
16
|
+
|
17
|
+
Generated by :no_entry_sign: [Danger](https://danger.systems/ "generated_by_<%= @danger_id %>")
|