danger-additional-logging 0.0.1

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.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +93 -0
  4. data/bin/danger +5 -0
  5. data/lib/assets/DangerfileTemplate +13 -0
  6. data/lib/danger/ci_source/appcenter.rb +55 -0
  7. data/lib/danger/ci_source/appcircle.rb +83 -0
  8. data/lib/danger/ci_source/appveyor.rb +64 -0
  9. data/lib/danger/ci_source/azure_pipelines.rb +61 -0
  10. data/lib/danger/ci_source/bamboo.rb +41 -0
  11. data/lib/danger/ci_source/bitbucket_pipelines.rb +37 -0
  12. data/lib/danger/ci_source/bitrise.rb +78 -0
  13. data/lib/danger/ci_source/buddybuild.rb +62 -0
  14. data/lib/danger/ci_source/buildkite.rb +51 -0
  15. data/lib/danger/ci_source/ci_source.rb +37 -0
  16. data/lib/danger/ci_source/circle.rb +94 -0
  17. data/lib/danger/ci_source/circle_api.rb +51 -0
  18. data/lib/danger/ci_source/cirrus.rb +31 -0
  19. data/lib/danger/ci_source/code_build.rb +71 -0
  20. data/lib/danger/ci_source/codefresh.rb +47 -0
  21. data/lib/danger/ci_source/codemagic.rb +58 -0
  22. data/lib/danger/ci_source/codeship.rb +44 -0
  23. data/lib/danger/ci_source/concourse.rb +60 -0
  24. data/lib/danger/ci_source/custom_ci_with_github.rb +49 -0
  25. data/lib/danger/ci_source/dotci.rb +50 -0
  26. data/lib/danger/ci_source/drone.rb +71 -0
  27. data/lib/danger/ci_source/github_actions.rb +44 -0
  28. data/lib/danger/ci_source/gitlab_ci.rb +89 -0
  29. data/lib/danger/ci_source/jenkins.rb +148 -0
  30. data/lib/danger/ci_source/local_git_repo.rb +117 -0
  31. data/lib/danger/ci_source/local_only_git_repo.rb +44 -0
  32. data/lib/danger/ci_source/screwdriver.rb +48 -0
  33. data/lib/danger/ci_source/semaphore.rb +37 -0
  34. data/lib/danger/ci_source/support/commits.rb +19 -0
  35. data/lib/danger/ci_source/support/find_repo_info_from_logs.rb +35 -0
  36. data/lib/danger/ci_source/support/find_repo_info_from_url.rb +43 -0
  37. data/lib/danger/ci_source/support/local_pull_request.rb +14 -0
  38. data/lib/danger/ci_source/support/no_pull_request.rb +7 -0
  39. data/lib/danger/ci_source/support/no_repo_info.rb +5 -0
  40. data/lib/danger/ci_source/support/pull_request_finder.rb +190 -0
  41. data/lib/danger/ci_source/support/remote_pull_request.rb +15 -0
  42. data/lib/danger/ci_source/support/repo_info.rb +10 -0
  43. data/lib/danger/ci_source/surf.rb +37 -0
  44. data/lib/danger/ci_source/teamcity.rb +163 -0
  45. data/lib/danger/ci_source/travis.rb +51 -0
  46. data/lib/danger/ci_source/xcode_cloud.rb +38 -0
  47. data/lib/danger/ci_source/xcode_server.rb +48 -0
  48. data/lib/danger/clients/rubygems_client.rb +14 -0
  49. data/lib/danger/commands/dangerfile/gem.rb +43 -0
  50. data/lib/danger/commands/dangerfile/init.rb +30 -0
  51. data/lib/danger/commands/dry_run.rb +54 -0
  52. data/lib/danger/commands/init.rb +297 -0
  53. data/lib/danger/commands/init_helpers/interviewer.rb +92 -0
  54. data/lib/danger/commands/local.rb +83 -0
  55. data/lib/danger/commands/local_helpers/http_cache.rb +38 -0
  56. data/lib/danger/commands/local_helpers/local_setup.rb +48 -0
  57. data/lib/danger/commands/local_helpers/pry_setup.rb +32 -0
  58. data/lib/danger/commands/plugins/plugin_json.rb +44 -0
  59. data/lib/danger/commands/plugins/plugin_lint.rb +52 -0
  60. data/lib/danger/commands/plugins/plugin_readme.rb +42 -0
  61. data/lib/danger/commands/pr.rb +93 -0
  62. data/lib/danger/commands/runner.rb +94 -0
  63. data/lib/danger/commands/staging.rb +53 -0
  64. data/lib/danger/commands/systems.rb +41 -0
  65. data/lib/danger/comment_generators/bitbucket_server.md.erb +20 -0
  66. data/lib/danger/comment_generators/bitbucket_server_inline.md.erb +15 -0
  67. data/lib/danger/comment_generators/bitbucket_server_message_group.md.erb +12 -0
  68. data/lib/danger/comment_generators/github.md.erb +55 -0
  69. data/lib/danger/comment_generators/github_inline.md.erb +26 -0
  70. data/lib/danger/comment_generators/gitlab.md.erb +40 -0
  71. data/lib/danger/comment_generators/gitlab_inline.md.erb +21 -0
  72. data/lib/danger/comment_generators/vsts.md.erb +20 -0
  73. data/lib/danger/comment_generators/vsts_inline.md.erb +17 -0
  74. data/lib/danger/core_ext/file_list.rb +18 -0
  75. data/lib/danger/core_ext/string.rb +20 -0
  76. data/lib/danger/danger_core/dangerfile.rb +348 -0
  77. data/lib/danger/danger_core/dangerfile_dsl.rb +29 -0
  78. data/lib/danger/danger_core/dangerfile_generator.rb +11 -0
  79. data/lib/danger/danger_core/environment_manager.rb +126 -0
  80. data/lib/danger/danger_core/executor.rb +91 -0
  81. data/lib/danger/danger_core/message_aggregator.rb +50 -0
  82. data/lib/danger/danger_core/message_group.rb +68 -0
  83. data/lib/danger/danger_core/messages/base.rb +57 -0
  84. data/lib/danger/danger_core/messages/markdown.rb +41 -0
  85. data/lib/danger/danger_core/messages/violation.rb +53 -0
  86. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +142 -0
  87. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +211 -0
  88. data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +274 -0
  89. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +159 -0
  90. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +264 -0
  91. data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +275 -0
  92. data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +43 -0
  93. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +220 -0
  94. data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +191 -0
  95. data/lib/danger/danger_core/standard_error.rb +142 -0
  96. data/lib/danger/helpers/array_subclass.rb +61 -0
  97. data/lib/danger/helpers/comment.rb +32 -0
  98. data/lib/danger/helpers/comments_helper.rb +179 -0
  99. data/lib/danger/helpers/comments_parsing_helper.rb +71 -0
  100. data/lib/danger/helpers/emoji_mapper.rb +41 -0
  101. data/lib/danger/helpers/find_max_num_violations.rb +31 -0
  102. data/lib/danger/helpers/message_groups_array_helper.rb +31 -0
  103. data/lib/danger/plugin_support/gems_resolver.rb +77 -0
  104. data/lib/danger/plugin_support/plugin.rb +52 -0
  105. data/lib/danger/plugin_support/plugin_file_resolver.rb +30 -0
  106. data/lib/danger/plugin_support/plugin_linter.rb +162 -0
  107. data/lib/danger/plugin_support/plugin_parser.rb +199 -0
  108. data/lib/danger/plugin_support/templates/readme_table.html.erb +26 -0
  109. data/lib/danger/request_sources/bitbucket_cloud.rb +169 -0
  110. data/lib/danger/request_sources/bitbucket_cloud_api.rb +181 -0
  111. data/lib/danger/request_sources/bitbucket_server.rb +210 -0
  112. data/lib/danger/request_sources/bitbucket_server_api.rb +129 -0
  113. data/lib/danger/request_sources/code_insights_api.rb +142 -0
  114. data/lib/danger/request_sources/github/github.rb +535 -0
  115. data/lib/danger/request_sources/github/github_review.rb +127 -0
  116. data/lib/danger/request_sources/github/github_review_resolver.rb +17 -0
  117. data/lib/danger/request_sources/github/github_review_unsupported.rb +23 -0
  118. data/lib/danger/request_sources/gitlab.rb +557 -0
  119. data/lib/danger/request_sources/local_only.rb +50 -0
  120. data/lib/danger/request_sources/request_source.rb +97 -0
  121. data/lib/danger/request_sources/support/get_ignored_violation.rb +17 -0
  122. data/lib/danger/request_sources/vsts.rb +278 -0
  123. data/lib/danger/request_sources/vsts_api.rb +172 -0
  124. data/lib/danger/scm_source/git_repo.rb +198 -0
  125. data/lib/danger/version.rb +4 -0
  126. data/lib/danger.rb +45 -0
  127. metadata +351 -0
@@ -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, Danger::RequestSources::BitbucketServer]
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" if method(__method__).owner == Danger::CI
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 > Environment 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
+
40
+ pull_requests.first[:url]
41
+ end
42
+
43
+ # Make the API call, and parse the JSON
44
+ def fetch_build(repo_slug, build_number, token)
45
+ url = "project/#{repo_slug}/#{build_number}"
46
+ params = { "circle-token" => token }
47
+ response = client.get url, params, accept: "application/json"
48
+ JSON.parse(response.body, symbolize_names: true)
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,71 @@
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
+ # In CodeBuild with batch builds, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_WEBHOOK_TRIGGER, CODEBUILD_SOURCE_REPO_URL, CODEBUILD_BATCH_BUILD_IDENTIFIER and DANGER_GITHUB_API_TOKEN.
9
+ #
10
+ # ### Token Setup
11
+ #
12
+ # Add your `DANGER_GITHUB_API_TOKEN` to your project. Edit -> Environment -> Additional configuration -> Create a parameter
13
+ #
14
+ class CodeBuild < CI
15
+ def self.validates_as_ci?(env)
16
+ env.key? "CODEBUILD_BUILD_ID"
17
+ end
18
+
19
+ def self.validates_as_pr?(env)
20
+ !!self.extract_pr_url(env)
21
+ end
22
+
23
+ def supported_request_sources
24
+ @supported_request_sources ||= [Danger::RequestSources::GitHub]
25
+ end
26
+
27
+ def initialize(env)
28
+ self.repo_slug = self.class.extract_repo_slug(env)
29
+ if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
30
+ self.pull_request_id = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")[1].to_i
31
+ else
32
+ self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
33
+ end
34
+ self.repo_url = self.class.extract_repo_url(env)
35
+ end
36
+
37
+ def self.extract_repo_slug(env)
38
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
39
+
40
+ gh_host = env["DANGER_GITHUB_HOST"] || "github.com"
41
+
42
+ env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}/(.*?)(\.git)?$}, '\1')
43
+ end
44
+
45
+ def self.extract_repo_url(env)
46
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
47
+
48
+ env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
49
+ end
50
+
51
+ def self.extract_pr_url(env)
52
+ if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
53
+ return nil unless env.key? "CODEBUILD_WEBHOOK_TRIGGER"
54
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
55
+ return nil unless env["CODEBUILD_WEBHOOK_TRIGGER"].split("/").length == 2
56
+
57
+ event_type, pr_number = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")
58
+ return nil unless event_type == "pr"
59
+ else
60
+ return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
61
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
62
+ return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
63
+
64
+ _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
65
+ end
66
+ github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
67
+
68
+ "#{github_repo_url}/pull/#{pr_number}"
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,47 @@
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 self.slug_from(env)
35
+ return "" if env["CF_REPO_OWNER"].to_s.empty?
36
+ return "" if env["CF_REPO_NAME"].to_s.empty?
37
+
38
+ "#{env['CF_REPO_OWNER']}/#{env['CF_REPO_NAME']}".downcase!
39
+ end
40
+
41
+ def initialize(env)
42
+ self.repo_url = env["CF_COMMIT_URL"].to_s.gsub(%r{/commit.+$}, "")
43
+ self.repo_slug = self.class.slug_from(env)
44
+ self.pull_request_id = env["CF_PULL_REQUEST_NUMBER"]
45
+ end
46
+ end
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
@@ -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
@@ -0,0 +1,60 @@
1
+ require "git"
2
+ require "danger/request_sources/local_only"
3
+
4
+ module Danger
5
+ # Concourse CI Integration
6
+ #
7
+ # https://concourse-ci.org/
8
+ #
9
+ # ### CI Setup
10
+ #
11
+ # With Concourse, you run the docker images yourself, so you will want to add `yarn danger ci` within one of your build jobs.
12
+ #
13
+ # ```shell
14
+ # build:
15
+ # image: golang
16
+ # commands:
17
+ # - ...
18
+ # - yarn danger ci
19
+ # ```
20
+ #
21
+ # ### Environment Variable Setup
22
+ #
23
+ # As this is self-hosted, you will need to add the `CONCOURSE` environment variable `export CONCOURSE=true` to your build environment,
24
+ # as well as setting environment variables for `PULL_REQUEST_ID` and `REPO_SLUG`. Assuming you are using the github pull request resource
25
+ # https://github.com/jtarchie/github-pullrequest-resource the id of the PR can be accessed from `git config --get pullrequest.id`.
26
+ #
27
+ # ### Token Setup
28
+ #
29
+ # Once again as this is self-hosted, you will need to add `DANGER_GITHUB_API_TOKEN` environment variable to the build environment.
30
+ # The suggested method of storing the token is within the vault - https://concourse-ci.org/creds.html
31
+
32
+ class Concourse < CI
33
+ def self.validates_as_ci?(env)
34
+ env.key? "CONCOURSE"
35
+ end
36
+
37
+ def self.validates_as_pr?(env)
38
+ exists = ["PULL_REQUEST_ID", "REPO_SLUG"].all? { |x| env[x] && !env[x].empty? }
39
+ exists && env["PULL_REQUEST_ID"].to_i > 0
40
+ end
41
+
42
+ def supported_request_sources
43
+ @supported_request_sources ||= [
44
+ Danger::RequestSources::GitHub,
45
+ Danger::RequestSources::GitLab,
46
+ Danger::RequestSources::BitbucketServer,
47
+ Danger::RequestSources::BitbucketCloud
48
+ ]
49
+ end
50
+
51
+ def initialize(env)
52
+ self.repo_slug = env["REPO_SLUG"]
53
+
54
+ if env["PULL_REQUEST_ID"].to_i > 0
55
+ self.pull_request_id = env["PULL_REQUEST_ID"]
56
+ end
57
+ self.repo_url = GitRepo.new.origins
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "danger/request_sources/github/github"
4
+
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # Custom CI with GitHub
9
+ #
10
+ # This CI source is for custom, most likely internal, CI systems that are use GitHub as source control.
11
+ # An example could be argo-workflows or tekton hosted in your own Kubernetes cluster.
12
+ #
13
+ # The following environment variables are required:
14
+ # - `CUSTOM_CI_WITH_GITHUB` - Set to any value to indicate that this is a custom CI with GitHub
15
+ #
16
+ # ### Token Setup
17
+ #
18
+ # #### GitHub
19
+ # As you own the setup, it's up to you to add the environment variable for the `DANGER_GITHUB_API_TOKEN`.
20
+ #
21
+ class CustomCIWithGithub < CI
22
+ def self.validates_as_ci?(env)
23
+ env.key? "CUSTOM_CI_WITH_GITHUB"
24
+ end
25
+
26
+ def self.validates_as_pr?(env)
27
+ value = env["GITHUB_EVENT_NAME"]
28
+ ["pull_request", "pull_request_target"].include?(value)
29
+ end
30
+
31
+ def supported_request_sources
32
+ @supported_request_sources ||= [Danger::RequestSources::GitHub]
33
+ end
34
+
35
+ def initialize(env)
36
+ super
37
+
38
+ self.repo_slug = env["GITHUB_REPOSITORY"]
39
+ pull_request_event = JSON.parse(File.read(env["GITHUB_EVENT_PATH"]))
40
+ self.pull_request_id = pull_request_event["number"]
41
+ self.repo_url = pull_request_event["repository"]["clone_url"]
42
+
43
+ # if environment variable DANGER_GITHUB_API_TOKEN is not set, use env GITHUB_TOKEN
44
+ if (env.key? "CUSTOM_CI_WITH_GITHUB") && (!env.key? "DANGER_GITHUB_API_TOKEN")
45
+ env["DANGER_GITHUB_API_TOKEN"] = env["GITHUB_TOKEN"]
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ require "danger/request_sources/github/github"
2
+
3
+ module Danger
4
+ # https://groupon.github.io/DotCi
5
+
6
+ # ### CI Setup
7
+ # DotCi is a layer on top of jenkins. So, if you're using DotCi, you're hosting your own environment.
8
+ #
9
+ # ### Token Setup
10
+ #
11
+ # #### GitHub
12
+ # As you own the machine, it's up to you to add the environment variable for the `DANGER_GITHUB_API_TOKEN`.
13
+ #
14
+ class DotCi < CI
15
+ def self.validates_as_ci?(env)
16
+ env.key? "DOTCI"
17
+ end
18
+
19
+ def self.validates_as_pr?(env)
20
+ !env["DOTCI_PULL_REQUEST"].nil? && !env["DOTCI_PULL_REQUEST"].match(/^[0-9]+$/).nil?
21
+ end
22
+
23
+ def supported_request_sources
24
+ @supported_request_sources ||= [
25
+ Danger::RequestSources::GitHub
26
+ ]
27
+ end
28
+
29
+ def initialize(env)
30
+ self.repo_url = self.class.repo_url(env)
31
+ self.pull_request_id = self.class.pull_request_id(env)
32
+ repo_matches = self.repo_url.match(%r{([/:])([^/]+/[^/]+)$})
33
+ self.repo_slug = repo_matches[2].gsub(/\.git$/, "") unless repo_matches.nil?
34
+ end
35
+
36
+ def self.pull_request_id(env)
37
+ env["DOTCI_PULL_REQUEST"]
38
+ end
39
+
40
+ def self.repo_url(env)
41
+ if env["DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL"]
42
+ env["DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL"]
43
+ elsif env["DOTCI_DOCKER_COMPOSE_GIT_CLONE_URL"]
44
+ env["DOTCI_DOCKER_COMPOSE_GIT_CLONE_URL"]
45
+ else
46
+ env["GIT_URL"]
47
+ end
48
+ end
49
+ end
50
+ end