danger 8.4.2 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +1 -1
  4. data/bin/danger +1 -1
  5. data/lib/danger/ci_source/appcircle.rb +83 -0
  6. data/lib/danger/ci_source/appveyor.rb +1 -0
  7. data/lib/danger/ci_source/azure_pipelines.rb +20 -5
  8. data/lib/danger/ci_source/bamboo.rb +1 -1
  9. data/lib/danger/ci_source/bitbucket_pipelines.rb +1 -2
  10. data/lib/danger/ci_source/bitrise.rb +10 -10
  11. data/lib/danger/ci_source/buildkite.rb +1 -1
  12. data/lib/danger/ci_source/circle.rb +1 -1
  13. data/lib/danger/ci_source/circle_api.rb +2 -2
  14. data/lib/danger/ci_source/code_build.rb +20 -6
  15. data/lib/danger/ci_source/codefresh.rb +7 -13
  16. data/lib/danger/ci_source/concourse.rb +4 -5
  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 +13 -19
  20. data/lib/danger/ci_source/jenkins.rb +22 -23
  21. data/lib/danger/ci_source/local_git_repo.rb +36 -38
  22. data/lib/danger/ci_source/local_only_git_repo.rb +5 -8
  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 +47 -43
  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 +1 -1
  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 +19 -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 +3 -1
  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/array_subclass.rb +2 -2
  60. data/lib/danger/helpers/comments_helper.rb +8 -7
  61. data/lib/danger/helpers/comments_parsing_helper.rb +3 -2
  62. data/lib/danger/helpers/emoji_mapper.rb +1 -1
  63. data/lib/danger/plugin_support/plugin.rb +0 -1
  64. data/lib/danger/plugin_support/plugin_linter.rb +1 -0
  65. data/lib/danger/request_sources/bitbucket_cloud.rb +3 -6
  66. data/lib/danger/request_sources/bitbucket_cloud_api.rb +5 -7
  67. data/lib/danger/request_sources/bitbucket_server.rb +47 -11
  68. data/lib/danger/request_sources/bitbucket_server_api.rb +17 -14
  69. data/lib/danger/request_sources/code_insights_api.rb +9 -14
  70. data/lib/danger/request_sources/github/github.rb +30 -38
  71. data/lib/danger/request_sources/github/github_review.rb +3 -2
  72. data/lib/danger/request_sources/github/github_review_resolver.rb +0 -2
  73. data/lib/danger/request_sources/github/github_review_unsupported.rb +0 -2
  74. data/lib/danger/request_sources/gitlab.rb +53 -75
  75. data/lib/danger/request_sources/local_only.rb +1 -4
  76. data/lib/danger/request_sources/request_source.rb +20 -8
  77. data/lib/danger/request_sources/support/get_ignored_violation.rb +1 -1
  78. data/lib/danger/request_sources/vsts.rb +175 -15
  79. data/lib/danger/request_sources/vsts_api.rb +41 -7
  80. data/lib/danger/scm_source/git_repo.rb +2 -1
  81. data/lib/danger/version.rb +1 -1
  82. data/lib/danger.rb +1 -0
  83. metadata +39 -37
  84. data/lib/danger/ci_source/vsts.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 423862c4ae06fbd90dbc52ae126b171c3af53da1867f6051db5e1e00cd1cb09e
4
- data.tar.gz: 45d13ff59705d33a756f8a221ef597f8c29f534511a9cd310241d2730b118e59
3
+ metadata.gz: 9ad61c252b1b62b1fb4e7aa07c2ef21727ada06dcfdd66e23ce70840ab37fcff
4
+ data.tar.gz: a1e98cfa27d937448822f2ece399fc157b5f30358ed675f976ccc7c20b7bfb5f
5
5
  SHA512:
6
- metadata.gz: 3a1e23473e3012edb47a6860ca50a4e0e12512ade5c2796b79720c71ba049c034060893505a5264df3ee36439ae702dffe1cc9472da4e6357d2cef7ba81e24b8
7
- data.tar.gz: 4e186a0412277f4d3add84821f39529900c9faec5439ccd62329bc24e6a753c19feafe68208f9ff3b7fe8b12e64ba8b31379b7af5273f24dfa230ec804f12648
6
+ metadata.gz: f4531b7f35bccbfdc0df07dedae51b009e1a9a0bcf00d566293d28c143c1a00e29f3ef8f7e47421a6ff32e48cd8b2b640866392aab161d0e95d16d9eff6ad1b6
7
+ data.tar.gz: fcce02992e6488c454ca914e4a81be0d397cbd19b9f3e63cf058c05068606376020281b552cb489b9d88bf8d0958b6a99b442093d62123a095c3d4418955a1c1
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/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](http://pryrepl.org/). 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)."
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'
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}"
@@ -31,23 +31,17 @@ module Danger
31
31
  @supported_request_sources ||= [Danger::RequestSources::GitHub]
32
32
  end
33
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
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
- def pull_request_id
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
- @env = 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"]
51
45
  end
52
46
  end
53
47
  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
@@ -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?
@@ -66,9 +66,17 @@ module Danger
66
66
  merge_request.nil? ? 0 : merge_request.iid
67
67
  end
68
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
+
69
77
  def initialize(env)
70
- @env = env
71
- @repo_slug = slug_from(env)
78
+ self.repo_slug = self.class.slug_from(env)
79
+ self.pull_request_id = self.class.determine_pull_or_merge_request_id(env)
72
80
  end
73
81
 
74
82
  def supported_request_sources
@@ -77,19 +85,5 @@ module Danger
77
85
  Danger::RequestSources::GitLab
78
86
  ]
79
87
  end
80
-
81
- def pull_request_id
82
- @pull_request_id ||= self.class.determine_pull_or_merge_request_id(@env)
83
- end
84
-
85
- private
86
-
87
- def slug_from(env)
88
- if env["DANGER_PROJECT_REPO_URL"]
89
- env["DANGER_PROJECT_REPO_URL"].split('/').last(2).join('/')
90
- else
91
- env["CI_MERGE_REQUEST_PROJECT_PATH"] || env["CI_PROJECT_PATH"]
92
- end
93
- end
94
88
  end
95
89
  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