danger 8.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +94 -0
- data/bin/danger +5 -0
- data/lib/assets/DangerfileTemplate +13 -0
- data/lib/danger.rb +44 -0
- data/lib/danger/ci_source/appcenter.rb +55 -0
- data/lib/danger/ci_source/appveyor.rb +60 -0
- data/lib/danger/ci_source/azure_pipelines.rb +44 -0
- data/lib/danger/ci_source/bamboo.rb +41 -0
- data/lib/danger/ci_source/bitbucket_pipelines.rb +37 -0
- data/lib/danger/ci_source/bitrise.rb +65 -0
- data/lib/danger/ci_source/buddybuild.rb +62 -0
- data/lib/danger/ci_source/buildkite.rb +51 -0
- data/lib/danger/ci_source/ci_source.rb +37 -0
- data/lib/danger/ci_source/circle.rb +94 -0
- data/lib/danger/ci_source/circle_api.rb +51 -0
- data/lib/danger/ci_source/cirrus.rb +31 -0
- data/lib/danger/ci_source/code_build.rb +57 -0
- data/lib/danger/ci_source/codefresh.rb +53 -0
- data/lib/danger/ci_source/codeship.rb +44 -0
- data/lib/danger/ci_source/dotci.rb +52 -0
- data/lib/danger/ci_source/drone.rb +71 -0
- data/lib/danger/ci_source/github_actions.rb +43 -0
- data/lib/danger/ci_source/gitlab_ci.rb +86 -0
- data/lib/danger/ci_source/jenkins.rb +149 -0
- data/lib/danger/ci_source/local_git_repo.rb +119 -0
- data/lib/danger/ci_source/local_only_git_repo.rb +47 -0
- data/lib/danger/ci_source/screwdriver.rb +47 -0
- data/lib/danger/ci_source/semaphore.rb +37 -0
- data/lib/danger/ci_source/support/commits.rb +17 -0
- data/lib/danger/ci_source/support/find_repo_info_from_logs.rb +35 -0
- data/lib/danger/ci_source/support/find_repo_info_from_url.rb +42 -0
- data/lib/danger/ci_source/support/local_pull_request.rb +14 -0
- data/lib/danger/ci_source/support/no_pull_request.rb +7 -0
- data/lib/danger/ci_source/support/no_repo_info.rb +5 -0
- data/lib/danger/ci_source/support/pull_request_finder.rb +179 -0
- data/lib/danger/ci_source/support/remote_pull_request.rb +15 -0
- data/lib/danger/ci_source/support/repo_info.rb +10 -0
- data/lib/danger/ci_source/surf.rb +37 -0
- data/lib/danger/ci_source/teamcity.rb +161 -0
- data/lib/danger/ci_source/travis.rb +51 -0
- data/lib/danger/ci_source/vsts.rb +73 -0
- data/lib/danger/ci_source/xcode_server.rb +48 -0
- data/lib/danger/clients/rubygems_client.rb +14 -0
- data/lib/danger/commands/dangerfile/gem.rb +43 -0
- data/lib/danger/commands/dangerfile/init.rb +30 -0
- data/lib/danger/commands/dry_run.rb +54 -0
- data/lib/danger/commands/init.rb +297 -0
- data/lib/danger/commands/init_helpers/interviewer.rb +92 -0
- data/lib/danger/commands/local.rb +83 -0
- data/lib/danger/commands/local_helpers/http_cache.rb +36 -0
- data/lib/danger/commands/local_helpers/local_setup.rb +46 -0
- data/lib/danger/commands/local_helpers/pry_setup.rb +31 -0
- data/lib/danger/commands/plugins/plugin_json.rb +46 -0
- data/lib/danger/commands/plugins/plugin_lint.rb +54 -0
- data/lib/danger/commands/plugins/plugin_readme.rb +45 -0
- data/lib/danger/commands/pr.rb +92 -0
- data/lib/danger/commands/runner.rb +94 -0
- data/lib/danger/commands/staging.rb +53 -0
- data/lib/danger/commands/systems.rb +43 -0
- data/lib/danger/comment_generators/bitbucket_server.md.erb +20 -0
- data/lib/danger/comment_generators/bitbucket_server_inline.md.erb +15 -0
- data/lib/danger/comment_generators/bitbucket_server_message_group.md.erb +12 -0
- data/lib/danger/comment_generators/github.md.erb +55 -0
- data/lib/danger/comment_generators/github_inline.md.erb +26 -0
- data/lib/danger/comment_generators/gitlab.md.erb +40 -0
- data/lib/danger/comment_generators/gitlab_inline.md.erb +26 -0
- data/lib/danger/comment_generators/vsts.md.erb +20 -0
- data/lib/danger/core_ext/file_list.rb +18 -0
- data/lib/danger/core_ext/string.rb +20 -0
- data/lib/danger/danger_core/dangerfile.rb +341 -0
- data/lib/danger/danger_core/dangerfile_dsl.rb +29 -0
- data/lib/danger/danger_core/dangerfile_generator.rb +11 -0
- data/lib/danger/danger_core/environment_manager.rb +123 -0
- data/lib/danger/danger_core/executor.rb +92 -0
- data/lib/danger/danger_core/message_aggregator.rb +49 -0
- data/lib/danger/danger_core/message_group.rb +68 -0
- data/lib/danger/danger_core/messages/base.rb +56 -0
- data/lib/danger/danger_core/messages/markdown.rb +42 -0
- data/lib/danger/danger_core/messages/violation.rb +54 -0
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +144 -0
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +211 -0
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +248 -0
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +158 -0
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +254 -0
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +240 -0
- data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +42 -0
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +218 -0
- data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +191 -0
- data/lib/danger/danger_core/standard_error.rb +143 -0
- data/lib/danger/helpers/array_subclass.rb +61 -0
- data/lib/danger/helpers/comment.rb +32 -0
- data/lib/danger/helpers/comments_helper.rb +178 -0
- data/lib/danger/helpers/comments_parsing_helper.rb +70 -0
- data/lib/danger/helpers/emoji_mapper.rb +41 -0
- data/lib/danger/helpers/find_max_num_violations.rb +31 -0
- data/lib/danger/helpers/message_groups_array_helper.rb +31 -0
- data/lib/danger/plugin_support/gems_resolver.rb +77 -0
- data/lib/danger/plugin_support/plugin.rb +49 -0
- data/lib/danger/plugin_support/plugin_file_resolver.rb +30 -0
- data/lib/danger/plugin_support/plugin_linter.rb +161 -0
- data/lib/danger/plugin_support/plugin_parser.rb +199 -0
- data/lib/danger/plugin_support/templates/readme_table.html.erb +26 -0
- data/lib/danger/request_sources/bitbucket_cloud.rb +171 -0
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +181 -0
- data/lib/danger/request_sources/bitbucket_server.rb +105 -0
- data/lib/danger/request_sources/bitbucket_server_api.rb +117 -0
- data/lib/danger/request_sources/github/github.rb +530 -0
- data/lib/danger/request_sources/github/github_review.rb +126 -0
- data/lib/danger/request_sources/github/github_review_resolver.rb +19 -0
- data/lib/danger/request_sources/github/github_review_unsupported.rb +25 -0
- data/lib/danger/request_sources/gitlab.rb +525 -0
- data/lib/danger/request_sources/local_only.rb +53 -0
- data/lib/danger/request_sources/request_source.rb +85 -0
- data/lib/danger/request_sources/support/get_ignored_violation.rb +17 -0
- data/lib/danger/request_sources/vsts.rb +118 -0
- data/lib/danger/request_sources/vsts_api.rb +138 -0
- data/lib/danger/scm_source/git_repo.rb +181 -0
- data/lib/danger/version.rb +4 -0
- metadata +339 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
module Danger
|
2
|
+
# ### CI Setup
|
3
|
+
#
|
4
|
+
# Read how you can setup Danger on the buddybuild blog:
|
5
|
+
# https://www.buddybuild.com/blog/using-danger-with-buddybuild/
|
6
|
+
#
|
7
|
+
# ### Token Setup
|
8
|
+
#
|
9
|
+
# Login to buddybuild and select your app. Go to your *App Settings* and
|
10
|
+
# in the *Build Settings* menu on the left, choose *Environment Variables*.
|
11
|
+
# http://docs.buddybuild.com/docs/environment-variables
|
12
|
+
#
|
13
|
+
# #### GitHub
|
14
|
+
# Add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV.
|
15
|
+
#
|
16
|
+
# #### GitLab
|
17
|
+
# Add the `DANGER_GITLAB_API_TOKEN` to your build user's ENV.
|
18
|
+
#
|
19
|
+
# #### Bitbucket Cloud
|
20
|
+
# Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
|
21
|
+
# to your build user's ENV.
|
22
|
+
#
|
23
|
+
# #### Bitbucket server
|
24
|
+
# Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
|
25
|
+
# and `DANGER_BITBUCKETSERVER_HOST` to your build user's ENV.
|
26
|
+
#
|
27
|
+
# ### Running Danger
|
28
|
+
#
|
29
|
+
# Once the environment variables are all available, create a custom build step
|
30
|
+
# to run Danger as part of your build process:
|
31
|
+
# http://docs.buddybuild.com/docs/custom-prebuild-and-postbuild-steps
|
32
|
+
class Buddybuild < CI
|
33
|
+
#######################################################################
|
34
|
+
def self.validates_as_ci?(env)
|
35
|
+
value = env["BUDDYBUILD_BUILD_ID"]
|
36
|
+
return !value.nil? && !env["BUDDYBUILD_BUILD_ID"].empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
#######################################################################
|
40
|
+
def self.validates_as_pr?(env)
|
41
|
+
value = env["BUDDYBUILD_PULL_REQUEST"]
|
42
|
+
return !value.nil? && !env["BUDDYBUILD_PULL_REQUEST"].empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
#######################################################################
|
46
|
+
def supported_request_sources
|
47
|
+
@supported_request_sources ||= [
|
48
|
+
Danger::RequestSources::GitHub,
|
49
|
+
Danger::RequestSources::GitLab,
|
50
|
+
Danger::RequestSources::BitbucketServer,
|
51
|
+
Danger::RequestSources::BitbucketCloud
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
#######################################################################
|
56
|
+
def initialize(env)
|
57
|
+
self.repo_slug = env["BUDDYBUILD_REPO_SLUG"]
|
58
|
+
self.pull_request_id = env["BUDDYBUILD_PULL_REQUEST"]
|
59
|
+
self.repo_url = GitRepo.new.origins # Buddybuild doesn't provide a repo url env variable for now
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# https://buildkite.com/docs/agent/osx
|
2
|
+
# https://buildkite.com/docs/guides/environment-variables
|
3
|
+
require "danger/request_sources/github/github"
|
4
|
+
require "danger/request_sources/gitlab"
|
5
|
+
|
6
|
+
module Danger
|
7
|
+
# ### CI Setup
|
8
|
+
#
|
9
|
+
# With BuildKite you run the server yourself, so you will want to run it as a part of your build process.
|
10
|
+
# It is common to have build steps, so we would recommend adding this to your scrip:
|
11
|
+
#
|
12
|
+
# ``` shell
|
13
|
+
# echo "--- Running Danger"
|
14
|
+
# bundle exec danger
|
15
|
+
# ```
|
16
|
+
#
|
17
|
+
# ### Token Setup
|
18
|
+
#
|
19
|
+
# #### GitHub
|
20
|
+
#
|
21
|
+
# As this is self-hosted, you will need to add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV. The alternative
|
22
|
+
# is to pass in the token as a prefix to the command `DANGER_GITHUB_API_TOKEN="123" bundle exec danger`.
|
23
|
+
#
|
24
|
+
# #### GitLab
|
25
|
+
#
|
26
|
+
# As this is self-hosted, you will need to add the `DANGER_GITLAB_API_TOKEN` to your build user's ENV. The alternative
|
27
|
+
# is to pass in the token as a prefix to the command `DANGER_GITLAB_API_TOKEN="123" bundle exec danger`.
|
28
|
+
#
|
29
|
+
class Buildkite < CI
|
30
|
+
def self.validates_as_ci?(env)
|
31
|
+
env.key? "BUILDKITE"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.validates_as_pr?(env)
|
35
|
+
exists = ["BUILDKITE_PULL_REQUEST_REPO", "BUILDKITE_PULL_REQUEST"].all? { |x| env[x] }
|
36
|
+
exists && !env["BUILDKITE_PULL_REQUEST_REPO"].empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(env)
|
40
|
+
self.repo_url = env["BUILDKITE_REPO"]
|
41
|
+
self.pull_request_id = env["BUILDKITE_PULL_REQUEST"]
|
42
|
+
|
43
|
+
repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+?)(\.git$|$)})
|
44
|
+
self.repo_slug = repo_matches[2] unless repo_matches.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
def supported_request_sources
|
48
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
# "abstract" CI class
|
5
|
+
class CI
|
6
|
+
attr_accessor :repo_slug, :pull_request_id, :repo_url, :supported_request_sources
|
7
|
+
|
8
|
+
def self.inherited(child_class)
|
9
|
+
available_ci_sources.add child_class
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.available_ci_sources
|
14
|
+
@available_ci_sources ||= Set.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def supported_request_sources
|
18
|
+
raise "CISource subclass must specify the supported request sources"
|
19
|
+
end
|
20
|
+
|
21
|
+
def supports?(request_source)
|
22
|
+
supported_request_sources.include?(request_source)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.validates_as_ci?(_env)
|
26
|
+
abort "You need to include a function for #{self} for validates_as_ci?"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.validates_as_pr?(_env)
|
30
|
+
abort "You need to include a function for #{self} for validates_as_pr?"
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(_env)
|
34
|
+
raise "Subclass and overwrite initialize"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# https://circleci.com/docs/environment-variables
|
2
|
+
require "uri"
|
3
|
+
require "danger/ci_source/circle_api"
|
4
|
+
require "danger/request_sources/github/github"
|
5
|
+
|
6
|
+
module Danger
|
7
|
+
# ### CI Setup
|
8
|
+
#
|
9
|
+
# For setting up CircleCI, we recommend turning on "Only build pull requests" in "Advanced Settings." Without this enabled,
|
10
|
+
# it's trickier for Danger to determine whether you're in a pull request or not, as the environment metadata
|
11
|
+
# isn't as reliable.
|
12
|
+
#
|
13
|
+
# A common scenario is when CircleCI begins building a commit before the commit becomes associated with a PR
|
14
|
+
# (e.g. a developer pushes their branch to the remote repo for the first time. CircleCI spins up and begins building.
|
15
|
+
# Moments later the developer creates a PR on GitHub. Since the build process started before the PR existed,
|
16
|
+
# Danger won't be able to use the Circle-provided environment variables to retrieve PR metadata.)
|
17
|
+
#
|
18
|
+
# With "Only build pull requests" enabled, you can add `bundle exec danger` to your `config.yml` (Circle 2.0).
|
19
|
+
#
|
20
|
+
# e.g.
|
21
|
+
#
|
22
|
+
# ``` yaml
|
23
|
+
# - run: bundle exec danger --verbose
|
24
|
+
# ```
|
25
|
+
#
|
26
|
+
# And that should be it!
|
27
|
+
#
|
28
|
+
# ### Token Setup
|
29
|
+
#
|
30
|
+
# If "Only build pull requests" can't be enabled for your project, Danger _can_ still work by relying on CircleCI's API
|
31
|
+
# to retrieve PR metadata, which will require an API token.
|
32
|
+
#
|
33
|
+
# 1. Go to your project > Settings > API Permissions. Create a token with scope "view-builds" and a label like "DANGER_CIRCLE_CI_API_TOKEN".
|
34
|
+
# 2. Settings > Environement Variables. Add the token as a CircleCI environment variable, which exposes it to the Danger process.
|
35
|
+
#
|
36
|
+
# There is no difference here for OSS vs Closed, both scenarios will need this environment variable.
|
37
|
+
#
|
38
|
+
# With these pieces in place, Danger should be able to work as expected.
|
39
|
+
#
|
40
|
+
class CircleCI < CI
|
41
|
+
# Side note: CircleCI is complicated. The env vars for PRs are not guaranteed to exist
|
42
|
+
# if the build was triggered from a commit, to look at examples of the different types
|
43
|
+
# of CI states, see this repo: https://github.com/orta/show_circle_env
|
44
|
+
|
45
|
+
def self.validates_as_ci?(env)
|
46
|
+
env.key? "CIRCLE_BUILD_NUM"
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.validates_as_pr?(env)
|
50
|
+
# This will get used if it's available, instead of the API faffing.
|
51
|
+
return true if env["CI_PULL_REQUEST"] && !env["CI_PULL_REQUEST"].empty?
|
52
|
+
return true if env["CIRCLE_PULL_REQUEST"] && !env["CIRCLE_PULL_REQUEST"].empty?
|
53
|
+
|
54
|
+
# Real-world talk, it should be worrying if none of these are in the environment
|
55
|
+
return false unless ["DANGER_CIRCLE_CI_API_TOKEN", "CIRCLE_PROJECT_USERNAME", "CIRCLE_PROJECT_REPONAME", "CIRCLE_BUILD_NUM"].all? { |x| env[x] && !env[x].empty? }
|
56
|
+
|
57
|
+
# Uses the Circle API to determine if it's a PR otherwise
|
58
|
+
api = CircleAPI.new
|
59
|
+
api.pull_request?(env)
|
60
|
+
end
|
61
|
+
|
62
|
+
def supported_request_sources
|
63
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::BitbucketCloud]
|
64
|
+
end
|
65
|
+
|
66
|
+
def initialize(env)
|
67
|
+
self.repo_url = env["CIRCLE_REPOSITORY_URL"]
|
68
|
+
pr_url = env["CI_PULL_REQUEST"] || env["CIRCLE_PULL_REQUEST"]
|
69
|
+
|
70
|
+
# If it's not a real URL, use the Circle API
|
71
|
+
unless pr_url && URI.parse(pr_url).kind_of?(URI::HTTP)
|
72
|
+
api = CircleAPI.new
|
73
|
+
pr_url = api.pull_request_url(env)
|
74
|
+
end
|
75
|
+
|
76
|
+
# We should either have got it via the API, or
|
77
|
+
# an ENV var.
|
78
|
+
pr_path = URI.parse(pr_url).path.split("/")
|
79
|
+
if pr_path.count == 5
|
80
|
+
# The first one is an extra slash, ignore it
|
81
|
+
self.repo_slug = pr_path[1] + "/" + pr_path[2]
|
82
|
+
self.pull_request_id = pr_path[4]
|
83
|
+
|
84
|
+
else
|
85
|
+
message = "Danger::Circle.rb considers this a PR, " \
|
86
|
+
"but did not get enough information to get a repo slug" \
|
87
|
+
"and PR id.\n\n" \
|
88
|
+
"PR path: #{pr_url}\n" \
|
89
|
+
"Keys: #{env.keys}"
|
90
|
+
raise message.red
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
class CircleAPI
|
5
|
+
# Determine if there's a PR attached to this commit,
|
6
|
+
# and return a bool
|
7
|
+
def pull_request?(env)
|
8
|
+
url = pull_request_url(env)
|
9
|
+
return !url.nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
# Determine if there's a PR attached to this commit,
|
13
|
+
# and return the url if so
|
14
|
+
def pull_request_url(env)
|
15
|
+
url = env["CI_PULL_REQUEST"]
|
16
|
+
|
17
|
+
if url.nil? && !env["CIRCLE_PROJECT_USERNAME"].nil? && !env["CIRCLE_PROJECT_REPONAME"].nil?
|
18
|
+
repo_slug = env["CIRCLE_PROJECT_USERNAME"] + "/" + env["CIRCLE_PROJECT_REPONAME"]
|
19
|
+
if !env["CIRCLE_PR_NUMBER"].nil?
|
20
|
+
host = env["DANGER_GITHUB_HOST"] || "github.com"
|
21
|
+
url = "https://" + host + "/" + repo_slug + "/pull/" + env["CIRCLE_PR_NUMBER"]
|
22
|
+
else
|
23
|
+
token = env["DANGER_CIRCLE_CI_API_TOKEN"]
|
24
|
+
url = fetch_pull_request_url(repo_slug, env["CIRCLE_BUILD_NUM"], token)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
url
|
28
|
+
end
|
29
|
+
|
30
|
+
def client
|
31
|
+
@client ||= Faraday.new(url: "https://circleci.com/api/v1")
|
32
|
+
end
|
33
|
+
|
34
|
+
# Ask the API if the commit is inside a PR
|
35
|
+
def fetch_pull_request_url(repo_slug, build_number, token)
|
36
|
+
build_json = fetch_build(repo_slug, build_number, token)
|
37
|
+
pull_requests = build_json[:pull_requests]
|
38
|
+
return nil unless pull_requests && pull_requests.first
|
39
|
+
pull_requests.first[:url]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Make the API call, and parse the JSON
|
43
|
+
def fetch_build(repo_slug, build_number, token)
|
44
|
+
url = "project/#{repo_slug}/#{build_number}"
|
45
|
+
params = { "circle-token" => token }
|
46
|
+
response = client.get url, params, accept: "application/json"
|
47
|
+
json = JSON.parse(response.body, symbolize_names: true)
|
48
|
+
json
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "danger/request_sources/github/github"
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
# ### CI Setup
|
5
|
+
# You need to edit your `.cirrus.yml` to include `bundler exec danger`.
|
6
|
+
#
|
7
|
+
# Adding this to your `.cirrus.yml` allows Danger to fail your build, both on the Cirrus CI website and within your Pull Request.
|
8
|
+
# With that set up, you can edit your task to add `bundler exec danger` in any script instruction.
|
9
|
+
class Cirrus < CI
|
10
|
+
def self.validates_as_ci?(env)
|
11
|
+
env.key? "CIRRUS_CI"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.validates_as_pr?(env)
|
15
|
+
exists = ["CIRRUS_PR", "CIRRUS_REPO_FULL_NAME"].all? { |x| env[x] && !env[x].empty? }
|
16
|
+
exists && env["CIRRUS_PR"].to_i > 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def supported_request_sources
|
20
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(env)
|
24
|
+
self.repo_slug = env["CIRRUS_REPO_FULL_NAME"]
|
25
|
+
if env["CIRRUS_PR"].to_i > 0
|
26
|
+
self.pull_request_id = env["CIRRUS_PR"]
|
27
|
+
end
|
28
|
+
self.repo_url = env["CIRRUS_GIT_CLONE_URL"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
|
2
|
+
require "danger/request_sources/github/github"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
# ### CI Setup
|
6
|
+
#
|
7
|
+
# In CodeBuild, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_SOURCE_VERSION, CODEBUILD_SOURCE_REPO_URL and DANGER_GITHUB_API_TOKEN.
|
8
|
+
#
|
9
|
+
# ### Token Setup
|
10
|
+
#
|
11
|
+
# Add your `DANGER_GITHUB_API_TOKEN` to your project. Edit -> Environment -> Additional configuration -> Create a parameter
|
12
|
+
#
|
13
|
+
class CodeBuild < CI
|
14
|
+
def self.validates_as_ci?(env)
|
15
|
+
env.key? "CODEBUILD_BUILD_ID"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.validates_as_pr?(env)
|
19
|
+
!!self.extract_pr_url(env)
|
20
|
+
end
|
21
|
+
|
22
|
+
def supported_request_sources
|
23
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(env)
|
27
|
+
self.repo_slug = self.class.extract_repo_slug(env)
|
28
|
+
self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
|
29
|
+
self.repo_url = self.class.extract_repo_url(env)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.extract_repo_slug(env)
|
33
|
+
return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
|
34
|
+
|
35
|
+
gh_host = env["DANGER_GITHUB_HOST"] || "github.com"
|
36
|
+
|
37
|
+
env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}\/(.*?)(\.git)?$}, '\1')
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.extract_repo_url(env)
|
41
|
+
return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
|
42
|
+
|
43
|
+
env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.extract_pr_url(env)
|
47
|
+
return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
|
48
|
+
return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
|
49
|
+
return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
|
50
|
+
|
51
|
+
_source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
|
52
|
+
github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
|
53
|
+
|
54
|
+
"#{github_repo_url}/pull/#{pr_number}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -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
|
@@ -0,0 +1,44 @@
|
|
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
|
+
# In Codeship, go to your "Project Settings", then add `bundle exec danger` as a test step inside
|
8
|
+
# one of your pipelines.
|
9
|
+
#
|
10
|
+
# ### Token Setup
|
11
|
+
#
|
12
|
+
# Add your `DANGER_GITHUB_API_TOKEN` to "Environment" section in "Project Settings".
|
13
|
+
#
|
14
|
+
class Codeship < CI
|
15
|
+
def self.validates_as_ci?(env)
|
16
|
+
env["CI_NAME"] == "codeship"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.validates_as_pr?(env)
|
20
|
+
return false unless env["CI_BRANCH"] && !env["CI_BRANCH"].empty?
|
21
|
+
|
22
|
+
!pr_from_env(env).nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.owner_for_github(env)
|
26
|
+
env["CI_REPO_NAME"].split("/").first
|
27
|
+
end
|
28
|
+
|
29
|
+
# this is fairly hacky, see https://github.com/danger/danger/pull/892#issuecomment-329030616 for why
|
30
|
+
def self.pr_from_env(env)
|
31
|
+
Danger::RequestSources::GitHub.new(nil, env).get_pr_from_branch(env["CI_REPO_NAME"], env["CI_BRANCH"], owner_for_github(env))
|
32
|
+
end
|
33
|
+
|
34
|
+
def supported_request_sources
|
35
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(env)
|
39
|
+
self.repo_slug = env["CI_REPO_NAME"]
|
40
|
+
self.pull_request_id = self.class.pr_from_env(env)
|
41
|
+
self.repo_url = GitRepo.new.origins
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|