danger 9.1.0 → 9.2.0

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/bin/danger +1 -1
  3. data/lib/danger/ci_source/appcircle.rb +71 -71
  4. data/lib/danger/ci_source/appveyor.rb +1 -0
  5. data/lib/danger/ci_source/azure_pipelines.rb +20 -5
  6. data/lib/danger/ci_source/bamboo.rb +1 -1
  7. data/lib/danger/ci_source/bitbucket_pipelines.rb +1 -2
  8. data/lib/danger/ci_source/bitrise.rb +3 -3
  9. data/lib/danger/ci_source/buildkite.rb +1 -1
  10. data/lib/danger/ci_source/circle_api.rb +2 -2
  11. data/lib/danger/ci_source/code_build.rb +1 -1
  12. data/lib/danger/ci_source/codefresh.rb +1 -1
  13. data/lib/danger/ci_source/concourse.rb +4 -5
  14. data/lib/danger/ci_source/dotci.rb +4 -6
  15. data/lib/danger/ci_source/github_actions.rb +6 -6
  16. data/lib/danger/ci_source/gitlab_ci.rb +4 -4
  17. data/lib/danger/ci_source/jenkins.rb +21 -22
  18. data/lib/danger/ci_source/local_git_repo.rb +7 -1
  19. data/lib/danger/ci_source/local_only_git_repo.rb +1 -0
  20. data/lib/danger/ci_source/support/find_repo_info_from_url.rb +11 -10
  21. data/lib/danger/ci_source/support/pull_request_finder.rb +15 -7
  22. data/lib/danger/ci_source/teamcity.rb +1 -1
  23. data/lib/danger/ci_source/xcode_cloud.rb +7 -7
  24. data/lib/danger/commands/init.rb +1 -1
  25. data/lib/danger/commands/local.rb +1 -1
  26. data/lib/danger/commands/local_helpers/http_cache.rb +2 -0
  27. data/lib/danger/commands/local_helpers/local_setup.rb +2 -0
  28. data/lib/danger/commands/local_helpers/pry_setup.rb +1 -0
  29. data/lib/danger/commands/plugins/plugin_json.rb +1 -3
  30. data/lib/danger/commands/plugins/plugin_lint.rb +0 -2
  31. data/lib/danger/commands/plugins/plugin_readme.rb +2 -5
  32. data/lib/danger/commands/runner.rb +1 -1
  33. data/lib/danger/commands/staging.rb +7 -7
  34. data/lib/danger/commands/systems.rb +4 -6
  35. data/lib/danger/core_ext/file_list.rb +2 -2
  36. data/lib/danger/danger_core/dangerfile.rb +13 -13
  37. data/lib/danger/danger_core/environment_manager.rb +2 -1
  38. data/lib/danger/danger_core/executor.rb +10 -11
  39. data/lib/danger/danger_core/message_aggregator.rb +1 -0
  40. data/lib/danger/danger_core/messages/base.rb +1 -0
  41. data/lib/danger/danger_core/messages/markdown.rb +3 -4
  42. data/lib/danger/danger_core/messages/violation.rb +1 -2
  43. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +1 -3
  44. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +4 -4
  45. data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +8 -2
  46. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +3 -2
  47. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +2 -0
  48. data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +3 -1
  49. data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +3 -2
  50. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +3 -1
  51. data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +3 -3
  52. data/lib/danger/danger_core/standard_error.rb +2 -3
  53. data/lib/danger/helpers/comments_helper.rb +5 -5
  54. data/lib/danger/helpers/comments_parsing_helper.rb +3 -2
  55. data/lib/danger/helpers/emoji_mapper.rb +1 -1
  56. data/lib/danger/plugin_support/plugin.rb +0 -1
  57. data/lib/danger/plugin_support/plugin_linter.rb +1 -0
  58. data/lib/danger/request_sources/bitbucket_cloud.rb +3 -5
  59. data/lib/danger/request_sources/bitbucket_cloud_api.rb +2 -4
  60. data/lib/danger/request_sources/bitbucket_server.rb +10 -13
  61. data/lib/danger/request_sources/bitbucket_server_api.rb +9 -10
  62. data/lib/danger/request_sources/code_insights_api.rb +7 -11
  63. data/lib/danger/request_sources/github/github.rb +15 -14
  64. data/lib/danger/request_sources/github/github_review.rb +3 -2
  65. data/lib/danger/request_sources/github/github_review_resolver.rb +0 -2
  66. data/lib/danger/request_sources/github/github_review_unsupported.rb +0 -2
  67. data/lib/danger/request_sources/gitlab.rb +46 -58
  68. data/lib/danger/request_sources/local_only.rb +0 -2
  69. data/lib/danger/request_sources/request_source.rb +4 -4
  70. data/lib/danger/request_sources/support/get_ignored_violation.rb +1 -1
  71. data/lib/danger/request_sources/vsts.rb +8 -10
  72. data/lib/danger/request_sources/vsts_api.rb +5 -2
  73. data/lib/danger/version.rb +1 -1
  74. data/lib/danger.rb +1 -0
  75. metadata +34 -35
  76. data/lib/danger/ci_source/vsts.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fc4bd35f1d805c6e3ef5b0467cd59281f0251c10b0580ebb138002e3b370e62
4
- data.tar.gz: 29df2722f598ead34bee294304b60b3f6343c6147cce87054772aac2b40f1f2b
3
+ metadata.gz: 9ad61c252b1b62b1fb4e7aa07c2ef21727ada06dcfdd66e23ce70840ab37fcff
4
+ data.tar.gz: a1e98cfa27d937448822f2ece399fc157b5f30358ed675f976ccc7c20b7bfb5f
5
5
  SHA512:
6
- metadata.gz: 304581c49ae31baa62f135883e006536e993a824a6cea8a920a37d58b232ea3118eccf773ffc760281c8a49b70446b51b955c952379e9d41e12e9d9e9842a4d7
7
- data.tar.gz: d68b392bcb4075b852cc988fdaa3e9e2fd3df080417dd31d1cb314bf9ec1a4f3af5fdf759f7f106e5071b60e48ae4affb78750ae58a43ecadb94d533d9e80d83
6
+ metadata.gz: f4531b7f35bccbfdc0df07dedae51b009e1a9a0bcf00d566293d28c143c1a00e29f3ef8f7e47421a6ff32e48cd8b2b640866392aab161d0e95d16d9eff6ad1b6
7
+ data.tar.gz: fcce02992e6488c454ca914e4a81be0d397cbd19b9f3e63cf058c05068606376020281b552cb489b9d88bf8d0958b6a99b442093d62123a095c3d4418955a1c1
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
@@ -3,81 +3,81 @@
3
3
  require "danger/request_sources/github/github"
4
4
  require "danger/request_sources/gitlab"
5
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
- env["AC_PULL_NUMBER"].to_i > 0
43
- end
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
44
39
 
45
- def supported_request_sources
46
- @supported_request_sources ||= [
47
- Danger::RequestSources::GitHub,
48
- Danger::RequestSources::BitbucketCloud,
49
- Danger::RequestSources::BitbucketServer,
50
- Danger::RequestSources::GitLab
51
- ]
52
- end
40
+ def self.validates_as_pr?(env)
41
+ return false unless env.key? "AC_PULL_NUMBER"
53
42
 
54
- def initialize(env)
55
- self.pull_request_id = env["AC_PULL_NUMBER"]
56
- self.repo_url = env["AC_GIT_URL"]
57
- self.repo_slug = repo_slug_from(self.repo_url)
58
- end
59
-
60
- def repo_slug_from(url)
61
- if url =~ URI::regexp
62
- # Try to parse the URL as a valid URI. This should cover the cases of http/https/ssh URLs.
63
- begin
64
- uri = URI.parse(url)
65
- return uri.path.sub(/^(\/)/,'').sub(/(.git)$/,'')
66
- rescue URI::InvalidURIError
67
- # In case URL could not be parsed fallback to git URL parsing.
68
- repo_slug_asgiturl(url)
69
- end
70
- else
71
- # In case URL could not be parsed fallback to git URL parsing. git@github.com:organization/repo.git
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.
72
69
  repo_slug_asgiturl(url)
73
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
74
  end
75
-
76
- def repo_slug_asgiturl(url)
77
- matcher_url = url
78
- repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
79
- return repo_matches unless repo_matches.nil?
80
- 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
81
  end
82
82
  end
83
-
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
@@ -54,11 +54,11 @@ module Danger
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
 
@@ -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
@@ -39,7 +39,7 @@ module Danger
39
39
 
40
40
  gh_host = env["DANGER_GITHUB_HOST"] || "github.com"
41
41
 
42
- 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')
43
43
  end
44
44
 
45
45
  def self.extract_repo_url(env)
@@ -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
@@ -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 speed
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
@@ -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
 
@@ -4,19 +4,20 @@ module Danger
4
4
  class FindRepoInfoFromURL
5
5
  REGEXP = %r{
6
6
  ://[^/]+/
7
- (?<slug>[^/]+(/[^/]+){1,2})
8
- (/(pull|merge_requests|pull-requests)/)
7
+ (([^/]+/){1,2}_git/)?
8
+ (?<slug>[^/]+(/[^/]+){0,2})
9
+ (/(pull|pullrequest|merge_requests|pull-requests)/)
9
10
  (?<id>\d+)
10
- }x
11
-
11
+ }x.freeze
12
+
12
13
  # Regex used to extract info from Bitbucket server URLs, as they use a quite different format
13
14
  REGEXPBB = %r{
14
- (?:[\/:])projects
15
- \/([^\/.]+)
16
- \/repos\/([^\/.]+)
17
- \/pull-requests
18
- \/(\d+)
19
- }x
15
+ (?:[/:])projects
16
+ /([^/.]+)
17
+ /repos/([^/.]+)
18
+ /pull-requests
19
+ /(\d+)
20
+ }x.freeze
20
21
 
21
22
  def initialize(url)
22
23
  @url = url
@@ -28,7 +28,7 @@ module Danger
28
28
  ["true", "1", "yes", "y", true].include?(maybe_string)
29
29
  end
30
30
 
31
- def raise_pull_request_not_found!(pull_request)
31
+ def raise_pull_request_not_found!(_pull_request)
32
32
  if specific_pull_request_id.empty?
33
33
  raise "No recent Pull Requests found for this repo, danger requires at least one Pull Request for the local mode."
34
34
  else
@@ -81,6 +81,12 @@ module Danger
81
81
  remote_pull_request.head.sha,
82
82
  remote_pull_request.base.sha
83
83
  )
84
+ when :vsts
85
+ RemotePullRequest.new(
86
+ remote_pull_request[:pullRequestId].to_s,
87
+ remote_pull_request[:lastMergeSourceCommit][:commitId],
88
+ remote_pull_request[:lastMergeTargetCommit][:commitId]
89
+ )
84
90
  else
85
91
  raise "SCM provider not supported: #{scm_provider}"
86
92
  end
@@ -96,16 +102,12 @@ module Danger
96
102
 
97
103
  # @return [String] Log line of format: "Merge pull request #42"
98
104
  def most_recent_merged_pull_request
99
- @most_recent_merged_pull_request ||= begin
100
- git_logs.lines.grep(/Merge pull request #{pull_request_ref} from/)[0]
101
- end
105
+ @most_recent_merged_pull_request ||= git_logs.lines.grep(/Merge pull request #{pull_request_ref} from/)[0]
102
106
  end
103
107
 
104
108
  # @return [String] Log line of format: "description (#42)"
105
109
  def most_recent_squash_and_merged_pull_request
106
- @most_recent_squash_and_merged_pull_request ||= begin
107
- git_logs.lines.grep(/\(#{pull_request_ref}\)/)[0]
108
- end
110
+ @most_recent_squash_and_merged_pull_request ||= git_logs.lines.grep(/\(#{pull_request_ref}\)/)[0]
109
111
  end
110
112
 
111
113
  def pick_the_most_recent_one_from_two_matches
@@ -144,6 +146,10 @@ module Danger
144
146
  require "danger/request_sources/bitbucket_server_api"
145
147
  project, slug = repo_slug.split("/")
146
148
  RequestSources::BitbucketServerAPI.new(project, slug, specific_pull_request_id, env)
149
+
150
+ when :vsts
151
+ require "danger/request_sources/vsts_api"
152
+ RequestSources::VSTSAPI.new(repo_slug, specific_pull_request_id, env)
147
153
 
148
154
  when :github
149
155
  require "octokit"
@@ -174,6 +180,8 @@ module Danger
174
180
  :bitbucket_cloud
175
181
  elsif remote_url =~ %r{/pull-requests/}
176
182
  :bitbucket_server
183
+ elsif remote_url =~ /\.visualstudio\.com/i || remote_url =~ /dev\.azure\.com/i
184
+ :vsts
177
185
  else
178
186
  :github
179
187
  end