danger 8.4.5 → 9.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/bin/danger +1 -1
  4. data/lib/danger/ci_source/appcircle.rb +83 -0
  5. data/lib/danger/ci_source/appveyor.rb +1 -0
  6. data/lib/danger/ci_source/azure_pipelines.rb +20 -5
  7. data/lib/danger/ci_source/bamboo.rb +1 -1
  8. data/lib/danger/ci_source/bitbucket_pipelines.rb +1 -2
  9. data/lib/danger/ci_source/bitrise.rb +10 -10
  10. data/lib/danger/ci_source/buildkite.rb +1 -1
  11. data/lib/danger/ci_source/circle.rb +1 -1
  12. data/lib/danger/ci_source/circle_api.rb +2 -2
  13. data/lib/danger/ci_source/code_build.rb +20 -6
  14. data/lib/danger/ci_source/codefresh.rb +1 -1
  15. data/lib/danger/ci_source/concourse.rb +4 -5
  16. data/lib/danger/ci_source/custom_ci_with_github.rb +45 -0
  17. data/lib/danger/ci_source/dotci.rb +4 -6
  18. data/lib/danger/ci_source/github_actions.rb +6 -6
  19. data/lib/danger/ci_source/gitlab_ci.rb +4 -4
  20. data/lib/danger/ci_source/jenkins.rb +22 -23
  21. data/lib/danger/ci_source/local_git_repo.rb +7 -1
  22. data/lib/danger/ci_source/local_only_git_repo.rb +1 -0
  23. data/lib/danger/ci_source/support/find_repo_info_from_url.rb +11 -10
  24. data/lib/danger/ci_source/support/pull_request_finder.rb +15 -7
  25. data/lib/danger/ci_source/teamcity.rb +1 -1
  26. data/lib/danger/ci_source/xcode_cloud.rb +7 -7
  27. data/lib/danger/commands/init.rb +1 -1
  28. data/lib/danger/commands/local.rb +3 -3
  29. data/lib/danger/commands/local_helpers/http_cache.rb +2 -0
  30. data/lib/danger/commands/local_helpers/local_setup.rb +2 -0
  31. data/lib/danger/commands/local_helpers/pry_setup.rb +1 -0
  32. data/lib/danger/commands/plugins/plugin_json.rb +1 -3
  33. data/lib/danger/commands/plugins/plugin_lint.rb +0 -2
  34. data/lib/danger/commands/plugins/plugin_readme.rb +2 -5
  35. data/lib/danger/commands/pr.rb +2 -1
  36. data/lib/danger/commands/runner.rb +1 -1
  37. data/lib/danger/commands/staging.rb +7 -7
  38. data/lib/danger/commands/systems.rb +4 -6
  39. data/lib/danger/comment_generators/gitlab_inline.md.erb +1 -1
  40. data/lib/danger/comment_generators/vsts_inline.md.erb +17 -0
  41. data/lib/danger/core_ext/file_list.rb +2 -2
  42. data/lib/danger/danger_core/dangerfile.rb +16 -16
  43. data/lib/danger/danger_core/environment_manager.rb +2 -1
  44. data/lib/danger/danger_core/executor.rb +10 -11
  45. data/lib/danger/danger_core/message_aggregator.rb +1 -0
  46. data/lib/danger/danger_core/messages/base.rb +1 -0
  47. data/lib/danger/danger_core/messages/markdown.rb +3 -4
  48. data/lib/danger/danger_core/messages/violation.rb +1 -2
  49. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +1 -3
  50. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +4 -4
  51. data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +9 -3
  52. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +4 -3
  53. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +2 -0
  54. data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +3 -1
  55. data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +4 -3
  56. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +3 -1
  57. data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +3 -3
  58. data/lib/danger/danger_core/standard_error.rb +2 -3
  59. data/lib/danger/helpers/comments_helper.rb +8 -7
  60. data/lib/danger/helpers/comments_parsing_helper.rb +3 -2
  61. data/lib/danger/helpers/emoji_mapper.rb +1 -1
  62. data/lib/danger/plugin_support/plugin.rb +0 -1
  63. data/lib/danger/plugin_support/plugin_linter.rb +1 -0
  64. data/lib/danger/request_sources/bitbucket_cloud.rb +17 -14
  65. data/lib/danger/request_sources/bitbucket_cloud_api.rb +2 -4
  66. data/lib/danger/request_sources/bitbucket_server.rb +47 -10
  67. data/lib/danger/request_sources/bitbucket_server_api.rb +14 -10
  68. data/lib/danger/request_sources/code_insights_api.rb +7 -11
  69. data/lib/danger/request_sources/github/github.rb +15 -14
  70. data/lib/danger/request_sources/github/github_review.rb +3 -2
  71. data/lib/danger/request_sources/github/github_review_resolver.rb +0 -2
  72. data/lib/danger/request_sources/github/github_review_unsupported.rb +0 -2
  73. data/lib/danger/request_sources/gitlab.rb +46 -58
  74. data/lib/danger/request_sources/local_only.rb +0 -2
  75. data/lib/danger/request_sources/request_source.rb +4 -4
  76. data/lib/danger/request_sources/support/get_ignored_violation.rb +1 -1
  77. data/lib/danger/request_sources/vsts.rb +175 -14
  78. data/lib/danger/request_sources/vsts_api.rb +39 -4
  79. data/lib/danger/scm_source/git_repo.rb +2 -1
  80. data/lib/danger/version.rb +1 -1
  81. data/lib/danger.rb +1 -0
  82. metadata +42 -40
  83. data/lib/danger/ci_source/vsts.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55ca17556aed4215f86219bcdca5271049b481a1bd349e35211b4f9e509c2b15
4
- data.tar.gz: b2b1fb228f4325ce12ac2ff9c7a753d1b056966f0e8078bdce392a4fb9334b32
3
+ metadata.gz: 28e1b237f9fc7857aca64881f72c1c247ec9f83d0f22985866f7b7b59e407551
4
+ data.tar.gz: b1ffee7037fd3e8bfd25103557ec78f51792c1f24c46f2d5ce624b38c8582761
5
5
  SHA512:
6
- metadata.gz: f2769209f205e40a84f24426e4ce93b3681cbe8f4d57970114b0238d0a3f4c5bb8ff75bbd69936635abb7a8c64f933aaf1e18c4c2a0355ef18630d8365b99c60
7
- data.tar.gz: c260a71c30a49e4b6fad9975986324f795fc07750edd082e0e364f6c4975fc69e68619d7bd083bb48dac24f514f14a102d7cb7b95509de1c1b664608fbc63421
6
+ metadata.gz: 1b196a2f4f291b2a961948bb56518921285142763c8265478d6050992756fb4fef2bcc33fdbfa15187e8384a16f68b20903fd41475ab55578a3dbcd5fea60d75
7
+ data.tar.gz: 81f1adb962e7031baf701487d29e37ccd7daeb499471adbc1c663e1da8db87333c312d1c9875fa6a571acba9a429d6cae3a49fac3cf2ff4270a9c157ff4df469
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019-present Orta, Felix Krause
3
+ Copyright (c) 2015-present Orta, Felix Krause
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/bin/danger CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- $LOAD_PATH.push File.expand_path("../../lib", __FILE__)
2
+ $LOAD_PATH.push File.expand_path("../lib", __dir__)
3
3
 
4
4
  require "danger"
5
5
  Danger::Runner.run ARGV
@@ -0,0 +1,83 @@
1
+ # https://docs.appcircle.io/environment-variables/managing-variables
2
+ # https://docs.appcircle.io/build/build-profile-configuration#environment-variables-configuration
3
+ require "danger/request_sources/github/github"
4
+ require "danger/request_sources/gitlab"
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # Add a Custom Script step to your workflow and set it as a bash:
9
+ #
10
+ # ```shell
11
+ # cd $AC_REPOSITORY_DIR
12
+ # bundle install
13
+ # bundle exec danger
14
+ # ```
15
+ # ### Token Setup
16
+ #
17
+ # Login to Appcircle and select your build profile. Go to your *Config* and
18
+ # choose *Environment Variables*.
19
+ # https://docs.appcircle.io/environment-variables/managing-variables
20
+ #
21
+ # #### GitHub
22
+ # Add the `DANGER_GITHUB_API_TOKEN` to your profile's ENV.
23
+ #
24
+ # #### GitLab
25
+ # Add the `DANGER_GITLAB_API_TOKEN` to your profile's ENV.
26
+ #
27
+ # #### Bitbucket Cloud
28
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
29
+ # to your profile's ENV.
30
+ #
31
+ # #### Bitbucket server
32
+ # Add the `DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD`
33
+ # and `DANGER_BITBUCKETSERVER_HOST` to your profile's ENV.
34
+ #
35
+ class Appcircle < CI
36
+ def self.validates_as_ci?(env)
37
+ env.key? "AC_APPCIRCLE"
38
+ end
39
+
40
+ def self.validates_as_pr?(env)
41
+ return false unless env.key? "AC_PULL_NUMBER"
42
+
43
+ env["AC_PULL_NUMBER"].to_i > 0
44
+ end
45
+
46
+ def supported_request_sources
47
+ @supported_request_sources ||= [
48
+ Danger::RequestSources::GitHub,
49
+ Danger::RequestSources::BitbucketCloud,
50
+ Danger::RequestSources::BitbucketServer,
51
+ Danger::RequestSources::GitLab
52
+ ]
53
+ end
54
+
55
+ def initialize(env)
56
+ self.pull_request_id = env["AC_PULL_NUMBER"]
57
+ self.repo_url = env["AC_GIT_URL"]
58
+ self.repo_slug = repo_slug_from(self.repo_url)
59
+ end
60
+
61
+ def repo_slug_from(url)
62
+ if url =~ URI::DEFAULT_PARSER.make_regexp
63
+ # Try to parse the URL as a valid URI. This should cover the cases of http/https/ssh URLs.
64
+ begin
65
+ uri = URI.parse(url)
66
+ return uri.path.sub(%r{^(/)}, "").sub(/(.git)$/, "")
67
+ rescue URI::InvalidURIError
68
+ # In case URL could not be parsed fallback to git URL parsing.
69
+ repo_slug_asgiturl(url)
70
+ end
71
+ else
72
+ # In case URL could not be parsed fallback to git URL parsing. git@github.com:organization/repo.git
73
+ repo_slug_asgiturl(url)
74
+ end
75
+ end
76
+
77
+ def repo_slug_asgiturl(url)
78
+ matcher_url = url
79
+ repo_matches = matcher_url.match(%r{([/:])(([^/]+/)+[^/]+?)(\.git$|$)})[2]
80
+ return repo_matches unless repo_matches.nil?
81
+ end
82
+ end
83
+ end
@@ -42,6 +42,7 @@ module Danger
42
42
 
43
43
  def self.validates_as_pr?(env)
44
44
  return false unless env.key? "APPVEYOR_PULL_REQUEST_NUMBER"
45
+
45
46
  env["APPVEYOR_PULL_REQUEST_NUMBER"].to_i > 0
46
47
  end
47
48
 
@@ -1,6 +1,7 @@
1
1
  # https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
2
2
  require "uri"
3
3
  require "danger/request_sources/github/github"
4
+ require "danger/request_sources/vsts"
4
5
 
5
6
  module Danger
6
7
  # ### CI Setup
@@ -15,15 +16,28 @@ module Danger
15
16
  #
16
17
  # ### Token Setup
17
18
  #
18
- # Add the `DANGER_GITHUB_API_TOKEN` to your environment variables.
19
+ # #### GitHub
20
+ #
21
+ # You need to add the `DANGER_GITHUB_API_TOKEN` environment variable, to do this, go to your build definition's variables tab.
22
+ # #
23
+ # #### Azure Git
24
+ #
25
+ # You need to add the `DANGER_VSTS_API_TOKEN` and `DANGER_VSTS_HOST` environment variable, to do this,
26
+ # go to your build definition's variables tab. The `DANGER_VSTS_API_TOKEN` is your vsts personal access token.
27
+ # Instructions for creating a personal access token can be found [here](https://www.visualstudio.com/en-us/docs/setup-admin/team-services/use-personal-access-tokens-to-authenticate).
28
+ # For the `DANGER_VSTS_HOST` variable the suggested value is `$(System.TeamFoundationCollectionUri)$(System.TeamProject)`
29
+ # which will automatically get your vsts domain and your project name needed for the vsts api.
19
30
  #
20
31
  class AzurePipelines < CI
32
+
33
+
21
34
  def self.validates_as_ci?(env)
35
+ has_all_variables = ["AGENT_ID", "BUILD_SOURCEBRANCH", "BUILD_REPOSITORY_URI", "BUILD_REASON", "BUILD_REPOSITORY_NAME"].all? { |x| env[x] && !env[x].empty? }
36
+
22
37
  # 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
38
  # 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"
39
+ !Danger::Appcenter.validates_as_ci?(env) &&
40
+ has_all_variables
27
41
  end
28
42
 
29
43
  def self.validates_as_pr?(env)
@@ -35,7 +49,8 @@ module Danger
35
49
  Danger::RequestSources::GitHub,
36
50
  Danger::RequestSources::GitLab,
37
51
  Danger::RequestSources::BitbucketServer,
38
- Danger::RequestSources::BitbucketCloud
52
+ Danger::RequestSources::BitbucketCloud,
53
+ Danger::RequestSources::VSTS
39
54
  ]
40
55
  end
41
56
 
@@ -34,7 +34,7 @@ module Danger
34
34
  def initialize(env)
35
35
  self.repo_url = env["bamboo_planRepository_repositoryUrl"]
36
36
  self.pull_request_id = env["bamboo_repository_pr_key"]
37
- repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+?)(\.git$|$)})
37
+ repo_matches = self.repo_url.match(%r{([/:])([^/]+/[^/]+?)(\.git$|$)})
38
38
  self.repo_slug = repo_matches[2] unless repo_matches.nil?
39
39
  end
40
40
  end
@@ -16,7 +16,6 @@ module Danger
16
16
  # You can find them in Settings > Pipelines > Repository Variables
17
17
 
18
18
  class BitbucketPipelines < CI
19
-
20
19
  def self.validates_as_ci?(env)
21
20
  env.key? "BITBUCKET_BUILD_NUMBER"
22
21
  end
@@ -31,7 +30,7 @@ module Danger
31
30
 
32
31
  def initialize(env)
33
32
  self.repo_url = env["BITBUCKET_GIT_HTTP_ORIGIN"]
34
- self.repo_slug = "#{env["BITBUCKET_REPO_OWNER"]}/#{env["BITBUCKET_REPO_SLUG"]}"
33
+ self.repo_slug = "#{env['BITBUCKET_REPO_OWNER']}/#{env['BITBUCKET_REPO_SLUG']}"
35
34
  self.pull_request_id = env["BITBUCKET_PR_ID"]
36
35
  end
37
36
  end
@@ -19,13 +19,13 @@ module Danger
19
19
  #
20
20
  # Add the `DANGER_GITHUB_API_TOKEN` to your workflow's [Secret App Env Vars](https://blog.bitrise.io/anyone-even-prs-can-have-secrets).
21
21
  #
22
- # ### bitbucket server and bitrsie
22
+ # ### bitbucket server and bitrise
23
23
  #
24
- # Danger will read the environment variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
25
- # finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
26
- # comes from the App Settings tab for your Bitrsie App. If you are manually setting a repo URL in the
27
- # Git Clone Repo step, you may need to set adjust this propery in the settings tab, maybe even fake it.
28
- # The patterns used are `(%r{\.com/(.*)})` and `(%r{\.com:(.*)})` and .split(/\.git$|$/) to remove ".git" if the URL contains it.
24
+ # Danger will read the environment variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
25
+ # finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
26
+ # comes from the App Settings tab for your Bitrise App. If you are manually setting a repo URL in the
27
+ # Git Clone Repo step, you may need to set adjust this property in the settings tab, maybe even fake it.
28
+ # The patterns used are `(%r{\.com/(.*)})` and `(%r{\.com:(.*)})` and .split(/\.git$|$/) to remove ".git" if the URL contains it.
29
29
  #
30
30
  class Bitrise < CI
31
31
  def self.validates_as_ci?(env)
@@ -48,17 +48,17 @@ module Danger
48
48
  def initialize(env)
49
49
  self.pull_request_id = env["BITRISE_PULL_REQUEST"]
50
50
  self.repo_url = env["GIT_REPOSITORY_URL"]
51
-
51
+
52
52
  matcher_url = self.repo_url
53
53
  self.repo_slug = repo_slug_from(self.repo_url)
54
54
  end
55
55
 
56
56
  def repo_slug_from(url)
57
- if url =~ URI::regexp
57
+ if url =~ URI::DEFAULT_PARSER.make_regexp
58
58
  # Try to parse the URL as a valid URI. This should cover the cases of http/https/ssh URLs.
59
59
  begin
60
60
  uri = URI.parse(url)
61
- return uri.path.sub(/^(\/)/,'').sub(/(.git)$/,'')
61
+ return uri.path.sub(%r{^(/)}, "").sub(/(.git)$/, "")
62
62
  rescue URI::InvalidURIError
63
63
  # In case URL could not be parsed fallback to git URL parsing.
64
64
  repo_slug_asgiturl(url)
@@ -71,7 +71,7 @@ module Danger
71
71
 
72
72
  def repo_slug_asgiturl(url)
73
73
  matcher_url = url
74
- repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
74
+ repo_matches = matcher_url.match(%r{([/:])(([^/]+/)+[^/]+?)(\.git$|$)})[2]
75
75
  return repo_matches unless repo_matches.nil?
76
76
  end
77
77
  end
@@ -40,7 +40,7 @@ module Danger
40
40
  self.repo_url = env["BUILDKITE_REPO"]
41
41
  self.pull_request_id = env["BUILDKITE_PULL_REQUEST"]
42
42
 
43
- repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+?)(\.git$|$)})
43
+ repo_matches = self.repo_url.match(%r{([/:])([^/]+/[^/]+?)(\.git$|$)})
44
44
  self.repo_slug = repo_matches[2] unless repo_matches.nil?
45
45
  end
46
46
 
@@ -31,7 +31,7 @@ module Danger
31
31
  # to retrieve PR metadata, which will require an API token.
32
32
  #
33
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.
34
+ # 2. Settings > Environment Variables. Add the token as a CircleCI environment variable, which exposes it to the Danger process.
35
35
  #
36
36
  # There is no difference here for OSS vs Closed, both scenarios will need this environment variable.
37
37
  #
@@ -36,6 +36,7 @@ module Danger
36
36
  build_json = fetch_build(repo_slug, build_number, token)
37
37
  pull_requests = build_json[:pull_requests]
38
38
  return nil unless pull_requests && pull_requests.first
39
+
39
40
  pull_requests.first[:url]
40
41
  end
41
42
 
@@ -44,8 +45,7 @@ module Danger
44
45
  url = "project/#{repo_slug}/#{build_number}"
45
46
  params = { "circle-token" => token }
46
47
  response = client.get url, params, accept: "application/json"
47
- json = JSON.parse(response.body, symbolize_names: true)
48
- json
48
+ JSON.parse(response.body, symbolize_names: true)
49
49
  end
50
50
  end
51
51
  end
@@ -5,6 +5,7 @@ module Danger
5
5
  # ### CI Setup
6
6
  #
7
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.
8
9
  #
9
10
  # ### Token Setup
10
11
  #
@@ -25,7 +26,11 @@ module Danger
25
26
 
26
27
  def initialize(env)
27
28
  self.repo_slug = self.class.extract_repo_slug(env)
28
- self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
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
29
34
  self.repo_url = self.class.extract_repo_url(env)
30
35
  end
31
36
 
@@ -34,7 +39,7 @@ module Danger
34
39
 
35
40
  gh_host = env["DANGER_GITHUB_HOST"] || "github.com"
36
41
 
37
- env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}\/(.*?)(\.git)?$}, '\1')
42
+ env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}/(.*?)(\.git)?$}, '\1')
38
43
  end
39
44
 
40
45
  def self.extract_repo_url(env)
@@ -44,11 +49,20 @@ module Danger
44
49
  end
45
50
 
46
51
  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
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
50
63
 
51
- _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
64
+ _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
65
+ end
52
66
  github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
53
67
 
54
68
  "#{github_repo_url}/pull/#{pr_number}"
@@ -39,7 +39,7 @@ module Danger
39
39
  end
40
40
 
41
41
  def initialize(env)
42
- self.repo_url = env["CF_COMMIT_URL"].to_s.gsub(/\/commit.+$/, "")
42
+ self.repo_url = env["CF_COMMIT_URL"].to_s.gsub(%r{/commit.+$}, "")
43
43
  self.repo_slug = self.class.slug_from(env)
44
44
  self.pull_request_id = env["CF_PULL_REQUEST_NUMBER"]
45
45
  end
@@ -2,10 +2,10 @@ require "git"
2
2
  require "danger/request_sources/local_only"
3
3
 
4
4
  module Danger
5
- # Concourse CI Integration
6
- #
7
- # https://concourse-ci.org/
8
- #
5
+ # Concourse CI Integration
6
+ #
7
+ # https://concourse-ci.org/
8
+ #
9
9
  # ### CI Setup
10
10
  #
11
11
  # With Concourse, you run the docker images yourself, so you will want to add `yarn danger ci` within one of your build jobs.
@@ -56,6 +56,5 @@ module Danger
56
56
  end
57
57
  self.repo_url = GitRepo.new.origins
58
58
  end
59
-
60
59
  end
61
60
  end
@@ -0,0 +1,45 @@
1
+ require "danger/request_sources/github/github"
2
+
3
+ module Danger
4
+ # ### CI Setup
5
+ #
6
+ # Custom CI with GitHub
7
+ #
8
+ # This CI source is for custom, most likely internal, CI systems that are use GitHub as source control.
9
+ # An example could be argo-workflows or tekton hosted in your own Kubernetes cluster.
10
+ #
11
+ # The following environment variables are required:
12
+ # - `CUSTOM_CI_WITH_GITHUB` - Set to any value to indicate that this is a custom CI with GitHub
13
+ #
14
+ # ### Token Setup
15
+ #
16
+ # #### GitHub
17
+ # As you own the setup, it's up to you to add the environment variable for the `DANGER_GITHUB_API_TOKEN`.
18
+ #
19
+ class CustomCIWithGithub < CI
20
+ def self.validates_as_ci?(env)
21
+ env.key? "CUSTOM_CI_WITH_GITHUB"
22
+ end
23
+
24
+ def self.validates_as_pr?(env)
25
+ value = env["GITHUB_EVENT_NAME"]
26
+ ["pull_request", "pull_request_target"].include?(value)
27
+ end
28
+
29
+ def supported_request_sources
30
+ @supported_request_sources ||= [Danger::RequestSources::GitHub]
31
+ end
32
+
33
+ def initialize(env)
34
+ self.repo_slug = env["GITHUB_REPOSITORY"]
35
+ pull_request_event = JSON.parse(File.read(env["GITHUB_EVENT_PATH"]))
36
+ self.pull_request_id = pull_request_event["number"]
37
+ self.repo_url = pull_request_event["repository"]["clone_url"]
38
+
39
+ # if environment variable DANGER_GITHUB_API_TOKEN is not set, use env GITHUB_TOKEN
40
+ if (env.key? "CUSTOM_CI_WITH_GITHUB") && (!env.key? "DANGER_GITHUB_API_TOKEN")
41
+ env["DANGER_GITHUB_API_TOKEN"] = env["GITHUB_TOKEN"]
42
+ end
43
+ end
44
+ end
45
+ end
@@ -21,17 +21,15 @@ module Danger
21
21
  end
22
22
 
23
23
  def supported_request_sources
24
- @supported_request_sources ||= begin
25
- [
26
- Danger::RequestSources::GitHub
27
- ]
28
- end
24
+ @supported_request_sources ||= [
25
+ Danger::RequestSources::GitHub
26
+ ]
29
27
  end
30
28
 
31
29
  def initialize(env)
32
30
  self.repo_url = self.class.repo_url(env)
33
31
  self.pull_request_id = self.class.pull_request_id(env)
34
- repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+)$})
32
+ repo_matches = self.repo_url.match(%r{([/:])([^/]+/[^/]+)$})
35
33
  self.repo_slug = repo_matches[2].gsub(/\.git$/, "") unless repo_matches.nil?
36
34
  end
37
35
 
@@ -9,7 +9,7 @@ module Danger
9
9
  # ```yml
10
10
  # ...
11
11
  # steps:
12
- # - uses: actions/checkout@v1
12
+ # - uses: actions/checkout@v3
13
13
  # - uses: danger/danger@master
14
14
  # env:
15
15
  # DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -22,7 +22,7 @@ module Danger
22
22
 
23
23
  def self.validates_as_pr?(env)
24
24
  value = env["GITHUB_EVENT_NAME"]
25
- value == "pull_request" || value == "pull_request_target"
25
+ ["pull_request", "pull_request_target"].include?(value)
26
26
  end
27
27
 
28
28
  def supported_request_sources
@@ -32,12 +32,12 @@ module Danger
32
32
  def initialize(env)
33
33
  self.repo_slug = env["GITHUB_REPOSITORY"]
34
34
  pull_request_event = JSON.parse(File.read(env["GITHUB_EVENT_PATH"]))
35
- self.pull_request_id = pull_request_event['number']
36
- self.repo_url = pull_request_event['repository']['clone_url']
35
+ self.pull_request_id = pull_request_event["number"]
36
+ self.repo_url = pull_request_event["repository"]["clone_url"]
37
37
 
38
38
  # if environment variable DANGER_GITHUB_API_TOKEN is not set, use env GITHUB_TOKEN
39
- if (env.key? "GITHUB_ACTION") && (!env.key? 'DANGER_GITHUB_API_TOKEN')
40
- env['DANGER_GITHUB_API_TOKEN'] = env['GITHUB_TOKEN']
39
+ if (env.key? "GITHUB_ACTION") && (!env.key? "DANGER_GITHUB_API_TOKEN")
40
+ env["DANGER_GITHUB_API_TOKEN"] = env["GITHUB_TOKEN"]
41
41
  end
42
42
  end
43
43
  end
@@ -47,11 +47,11 @@ module Danger
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"))
51
- #Use the 'list merge requests associated with a commit' API, for speeed
50
+ if client_version >= Gem::Version.new("10.7")
51
+ # Use the 'list merge requests associated with a commit' API, for speed
52
52
  # (GET /projects/:id/repository/commits/:sha/merge_requests) available for GitLab >= 10.7
53
53
  merge_request = client.commit_merge_requests(project_path, base_commit, state: :opened).first
54
- if (client_version >= Gem::Version.new("13.8"))
54
+ if client_version >= Gem::Version.new("13.8")
55
55
  # Gitlab 13.8.0 started returning merge requests for merge commits and squashed commits
56
56
  # By checking for merge_request.state, we can ensure danger only comments on MRs which are open
57
57
  return 0 if merge_request.nil?
@@ -68,7 +68,7 @@ module Danger
68
68
 
69
69
  def self.slug_from(env)
70
70
  if env["DANGER_PROJECT_REPO_URL"]
71
- env["DANGER_PROJECT_REPO_URL"].split('/').last(2).join('/')
71
+ env["DANGER_PROJECT_REPO_URL"].split("/").last(2).join("/")
72
72
  else
73
73
  env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
74
74
  end
@@ -31,7 +31,7 @@ module Danger
31
31
  #
32
32
  # #### General
33
33
  #
34
- # People occasionally see issues with Danger not classing your CI runs as a PR, to give you visibilty
34
+ # People occasionally see issues with Danger not classing your CI runs as a PR, to give you visibility
35
35
  # the Jenkins side of Danger expects to see one of these env vars:
36
36
  # - ghprbPullId
37
37
  # - CHANGE_ID
@@ -48,6 +48,7 @@ module Danger
48
48
  #
49
49
  class Jenkins < CI
50
50
  attr_accessor :project_url
51
+
51
52
  class EnvNotFound < StandardError
52
53
  def initialize
53
54
  super("ENV not found, please check your Jenkins. Related: https://stackoverflow.com/search?q=jenkins+env+null")
@@ -60,18 +61,16 @@ module Danger
60
61
 
61
62
  def self.validates_as_pr?(env)
62
63
  id = pull_request_id(env)
63
- !id.nil? && !id.empty? && !!id.match(%r{^\d+$})
64
+ !id.nil? && !id.empty? && !!id.match(/^\d+$/)
64
65
  end
65
66
 
66
67
  def supported_request_sources
67
- @supported_request_sources ||= begin
68
- [
69
- Danger::RequestSources::GitHub,
70
- Danger::RequestSources::GitLab,
71
- Danger::RequestSources::BitbucketServer,
72
- Danger::RequestSources::BitbucketCloud
73
- ]
74
- end
68
+ @supported_request_sources ||= [
69
+ Danger::RequestSources::GitHub,
70
+ Danger::RequestSources::GitLab,
71
+ Danger::RequestSources::BitbucketServer,
72
+ Danger::RequestSources::BitbucketCloud
73
+ ]
75
74
  end
76
75
 
77
76
  def initialize(env)
@@ -85,29 +84,29 @@ module Danger
85
84
 
86
85
  def self.repo_slug(repo_url)
87
86
  slug = self.slug_ssh(repo_url)
88
- slug = self.slug_http(repo_url) unless slug
89
- slug = self.slug_bitbucket(repo_url) unless slug
90
- slug = self.slug_fallback(repo_url) unless slug
87
+ slug ||= self.slug_http(repo_url)
88
+ slug ||= self.slug_bitbucket(repo_url)
89
+ slug ||= self.slug_fallback(repo_url)
91
90
  return slug.gsub(/\.git$/, "") unless slug.nil?
92
91
  end
93
92
 
94
93
  def self.slug_bitbucket(repo_url)
95
- repo_matches = repo_url.match(%r{(?:[\/:])projects\/([^\/.]+)\/repos\/([^\/.]+)})
94
+ repo_matches = repo_url.match(%r{(?:[/:])projects/([^/.]+)/repos/([^/.]+)})
96
95
  return "#{repo_matches[1]}/#{repo_matches[2]}" if repo_matches
97
96
  end
98
97
 
99
98
  def self.slug_ssh(repo_url)
100
- repo_matches = repo_url.match(%r{^git@.+:(.+)})
99
+ repo_matches = repo_url.match(/^git@.+:(.+)/)
101
100
  return repo_matches[1] if repo_matches
102
101
  end
103
102
 
104
103
  def self.slug_http(repo_url)
105
- repo_matches = repo_url.match(%r{^https?.+(?>\.\w*\d*\/)(.+.git$)})
104
+ repo_matches = repo_url.match(%r{^https?.+(?>\.\w*\d*/)(.+.git$)})
106
105
  return repo_matches[1] if repo_matches
107
106
  end
108
107
 
109
108
  def self.slug_fallback(repo_url)
110
- repo_matches = repo_url.match(%r{([\/:])([^\/]+\/[^\/]+)$})
109
+ repo_matches = repo_url.match(%r{([/:])([^/]+/[^/]+)$})
111
110
  return repo_matches[2]
112
111
  end
113
112
 
@@ -129,14 +128,14 @@ module Danger
129
128
  elsif env["CHANGE_URL"]
130
129
  change_url = env["CHANGE_URL"]
131
130
  case change_url
132
- when %r{\/pull\/} # GitHub
133
- matches = change_url.match(%r{(.+)\/pull\/[0-9]+})
131
+ when %r{/pull/} # GitHub
132
+ matches = change_url.match(%r{(.+)/pull/[0-9]+})
134
133
  matches[1] unless matches.nil?
135
- when %r{\/merge_requests\/} # GitLab
136
- matches = change_url.match(%r{(.+?)(\/-)?\/merge_requests\/[0-9]+})
134
+ when %r{/merge_requests/} # GitLab
135
+ matches = change_url.match(%r{(.+?)(/-)?/merge_requests/[0-9]+})
137
136
  matches[1] unless matches.nil?
138
- when %r{\/pull-requests\/} # Bitbucket
139
- matches = change_url.match(%r{(.+)\/pull-requests\/[0-9]+})
137
+ when %r{/pull-requests/} # Bitbucket
138
+ matches = change_url.match(%r{(.+)/pull-requests/[0-9]+})
140
139
  matches[1] unless matches.nil?
141
140
  else
142
141
  change_url
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # For more info see: https://github.com/schacon/ruby-git
3
4
 
4
5
  require "git"
@@ -34,7 +35,12 @@ module Danger
34
35
  end
35
36
 
36
37
  def supported_request_sources
37
- @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::BitbucketServer, Danger::RequestSources::BitbucketCloud]
38
+ @supported_request_sources ||= [
39
+ Danger::RequestSources::GitHub,
40
+ Danger::RequestSources::BitbucketServer,
41
+ Danger::RequestSources::BitbucketCloud,
42
+ Danger::RequestSources::VSTS
43
+ ]
38
44
  end
39
45
 
40
46
  def initialize(env = {})
@@ -11,6 +11,7 @@ module Danger
11
11
  #
12
12
  class LocalOnlyGitRepo < CI
13
13
  attr_accessor :base_commit, :head_commit
14
+
14
15
  HEAD_VAR = "DANGER_LOCAL_HEAD"
15
16
  BASE_VAR = "DANGER_LOCAL_BASE"
16
17