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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # For more info see: https://github.com/schacon/ruby-git
2
4
 
3
5
  require "git"
@@ -33,12 +35,17 @@ module Danger
33
35
  end
34
36
 
35
37
  def supported_request_sources
36
- @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
+ ]
37
44
  end
38
45
 
39
46
  def initialize(env = {})
40
- @env = env
41
-
47
+ @remote_info = find_remote_info(env)
48
+ @found_pull_request = find_pull_request(env)
42
49
  self.repo_slug = remote_info.slug
43
50
  raise_error_for_missing_remote if remote_info.kind_of?(NoRepoInfo)
44
51
 
@@ -55,7 +62,7 @@ module Danger
55
62
 
56
63
  private
57
64
 
58
- attr_reader :env
65
+ attr_reader :remote_info, :found_pull_request
59
66
 
60
67
  def raise_error_for_missing_remote
61
68
  raise missing_remote_error_message
@@ -66,45 +73,36 @@ module Danger
66
73
  "And the repository must host on GitHub.com or GitHub Enterprise."
67
74
  end
68
75
 
69
- def remote_info
70
- @_remote_info ||= begin
71
- remote_info = begin
72
- if given_pull_request_url?
73
- FindRepoInfoFromURL.new(env["LOCAL_GIT_PR_URL"]).call
74
- else
75
- FindRepoInfoFromLogs.new(
76
- env["DANGER_GITHUB_HOST"] || "github.com".freeze,
77
- run_git("remote show origin -n".freeze)
78
- ).call
79
- end
80
- end
81
-
82
- remote_info || NoRepoInfo.new
83
- end
76
+ def find_remote_info(env)
77
+ if given_pull_request_url?(env)
78
+ FindRepoInfoFromURL.new(env["LOCAL_GIT_PR_URL"]).call
79
+ else
80
+ FindRepoInfoFromLogs.new(
81
+ env["DANGER_GITHUB_HOST"] || "github.com",
82
+ run_git("remote show origin -n")
83
+ ).call
84
+ end || NoRepoInfo.new
84
85
  end
85
86
 
86
- def found_pull_request
87
- @_found_pull_request ||= begin
88
- if given_pull_request_url?
89
- PullRequestFinder.new(
90
- remote_info.id,
91
- remote_info.slug,
92
- remote: true,
93
- remote_url: env["LOCAL_GIT_PR_URL"],
94
- env: env
95
- ).call
96
- else
97
- PullRequestFinder.new(
98
- env.fetch("LOCAL_GIT_PR_ID") { "".freeze },
99
- remote_info.slug,
100
- remote: false,
101
- git_logs: run_git("log --oneline -1000000".freeze)
102
- ).call
103
- end
87
+ def find_pull_request(env)
88
+ if given_pull_request_url?(env)
89
+ PullRequestFinder.new(
90
+ remote_info.id,
91
+ remote_info.slug,
92
+ remote: true,
93
+ remote_url: env["LOCAL_GIT_PR_URL"]
94
+ ).call(env: env)
95
+ else
96
+ PullRequestFinder.new(
97
+ env.fetch("LOCAL_GIT_PR_ID") { "" },
98
+ remote_info.slug,
99
+ remote: false,
100
+ git_logs: run_git("log --oneline -1000000")
101
+ ).call(env: env)
104
102
  end
105
103
  end
106
104
 
107
- def given_pull_request_url?
105
+ def given_pull_request_url?(env)
108
106
  env["LOCAL_GIT_PR_URL"] && !env["LOCAL_GIT_PR_URL"].empty?
109
107
  end
110
108
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "git"
2
4
  require "danger/request_sources/local_only"
3
5
 
@@ -9,8 +11,9 @@ module Danger
9
11
  #
10
12
  class LocalOnlyGitRepo < CI
11
13
  attr_accessor :base_commit, :head_commit
12
- HEAD_VAR = "DANGER_LOCAL_HEAD".freeze
13
- BASE_VAR = "DANGER_LOCAL_BASE".freeze
14
+
15
+ HEAD_VAR = "DANGER_LOCAL_HEAD"
16
+ BASE_VAR = "DANGER_LOCAL_BASE"
14
17
 
15
18
  def self.validates_as_ci?(env)
16
19
  env.key? "DANGER_USE_LOCAL_ONLY_GIT"
@@ -33,15 +36,9 @@ module Danger
33
36
  end
34
37
 
35
38
  def initialize(env = {})
36
- @env = env
37
-
38
39
  # expects --base/--head specified OR origin/master to be base and HEAD head
39
40
  self.base_commit = env[BASE_VAR] || run_git("rev-parse --abbrev-ref origin/master")
40
41
  self.head_commit = env[HEAD_VAR] || run_git("rev-parse --abbrev-ref HEAD")
41
42
  end
42
-
43
- private
44
-
45
- attr_reader :env
46
43
  end
47
44
  end
@@ -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
@@ -1,67 +1,65 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "danger/ci_source/support/local_pull_request"
2
4
  require "danger/ci_source/support/remote_pull_request"
3
5
  require "danger/ci_source/support/no_pull_request"
4
6
 
5
7
  module Danger
6
8
  class PullRequestFinder
7
- def initialize(specific_pull_request_id, repo_slug = nil, remote: false, git_logs: "", remote_url: "", env: nil)
9
+ def initialize(specific_pull_request_id, repo_slug = nil, remote: false, git_logs: "", remote_url: "")
8
10
  @specific_pull_request_id = specific_pull_request_id
9
11
  @git_logs = git_logs
10
12
  @repo_slug = repo_slug
11
13
  @remote = to_boolean(remote)
12
14
  @remote_url = remote_url
13
- @env = env
14
15
  end
15
16
 
16
- def call
17
- check_if_any_pull_request!
18
-
19
- pull_request
17
+ def call(env: nil)
18
+ find_pull_request(env).tap do |pull_request|
19
+ raise_pull_request_not_found!(pull_request) unless pull_request.valid?
20
+ end
20
21
  end
21
22
 
22
23
  private
23
24
 
24
- attr_reader :specific_pull_request_id, :git_logs, :repo_slug, :remote, :remote_url, :env
25
+ attr_reader :specific_pull_request_id, :git_logs, :repo_slug, :remote, :remote_url
25
26
 
26
27
  def to_boolean(maybe_string)
27
28
  ["true", "1", "yes", "y", true].include?(maybe_string)
28
29
  end
29
30
 
30
- def check_if_any_pull_request!
31
- unless pull_request.valid?
32
- if !specific_pull_request_id.empty?
33
- raise "Could not find the Pull Request (#{specific_pull_request_id}) inside the git history for this repo."
34
- else
35
- raise "No recent Pull Requests found for this repo, danger requires at least one Pull Request for the local mode.".freeze
36
- end
31
+ def raise_pull_request_not_found!(_pull_request)
32
+ if specific_pull_request_id.empty?
33
+ raise "No recent Pull Requests found for this repo, danger requires at least one Pull Request for the local mode."
34
+ else
35
+ raise "Could not find the Pull Request (#{specific_pull_request_id}) inside the git history for this repo."
37
36
  end
38
37
  end
39
38
 
40
39
  # @return [String] Log line of most recent merged Pull Request
41
- def pull_request
42
- @pull_request ||= begin
43
- return if pull_request_ref.empty?
44
-
45
- if both_present?
46
- LocalPullRequest.new(pick_the_most_recent_one_from_two_matches)
47
- elsif only_merged_pull_request_present?
48
- LocalPullRequest.new(most_recent_merged_pull_request)
49
- elsif only_squash_and_merged_pull_request_present?
50
- LocalPullRequest.new(most_recent_squash_and_merged_pull_request)
51
- elsif remote && remote_pull_request
52
- generate_remote_pull_request
53
- else
54
- NoPullRequest.new
55
- end
40
+ def find_pull_request(env)
41
+ return if pull_request_ref.empty?
42
+
43
+ if both_present?
44
+ LocalPullRequest.new(pick_the_most_recent_one_from_two_matches)
45
+ elsif only_merged_pull_request_present?
46
+ LocalPullRequest.new(most_recent_merged_pull_request)
47
+ elsif only_squash_and_merged_pull_request_present?
48
+ LocalPullRequest.new(most_recent_squash_and_merged_pull_request)
49
+ elsif remote
50
+ remote_pull_request = find_remote_pull_request(env)
51
+ remote_pull_request ? generate_remote_pull_request(remote_pull_request) : NoPullRequest.new
52
+ else
53
+ NoPullRequest.new
56
54
  end
57
55
  end
58
56
 
59
57
  # @return [String] "#42"
60
58
  def pull_request_ref
61
- !specific_pull_request_id.empty? ? "##{specific_pull_request_id}" : "#\\d+".freeze
59
+ !specific_pull_request_id.empty? ? "##{specific_pull_request_id}" : "#\\d+"
62
60
  end
63
61
 
64
- def generate_remote_pull_request
62
+ def generate_remote_pull_request(remote_pull_request)
65
63
  scm_provider = find_scm_provider(remote_url)
66
64
 
67
65
  case scm_provider
@@ -83,15 +81,19 @@ module Danger
83
81
  remote_pull_request.head.sha,
84
82
  remote_pull_request.base.sha
85
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
+ )
86
90
  else
87
91
  raise "SCM provider not supported: #{scm_provider}"
88
92
  end
89
93
  end
90
94
 
91
- def remote_pull_request
92
- @_remote_pull_request ||= begin
93
- client.pull_request(repo_slug, specific_pull_request_id)
94
- end
95
+ def find_remote_pull_request(env)
96
+ client(env).pull_request(repo_slug, specific_pull_request_id)
95
97
  end
96
98
 
97
99
  def both_present?
@@ -100,16 +102,12 @@ module Danger
100
102
 
101
103
  # @return [String] Log line of format: "Merge pull request #42"
102
104
  def most_recent_merged_pull_request
103
- @most_recent_merged_pull_request ||= begin
104
- git_logs.lines.grep(/Merge pull request #{pull_request_ref} from/)[0]
105
- end
105
+ @most_recent_merged_pull_request ||= git_logs.lines.grep(/Merge pull request #{pull_request_ref} from/)[0]
106
106
  end
107
107
 
108
108
  # @return [String] Log line of format: "description (#42)"
109
109
  def most_recent_squash_and_merged_pull_request
110
- @most_recent_squash_and_merged_pull_request ||= begin
111
- git_logs.lines.grep(/\(#{pull_request_ref}\)/)[0]
112
- end
110
+ @most_recent_squash_and_merged_pull_request ||= git_logs.lines.grep(/\(#{pull_request_ref}\)/)[0]
113
111
  end
114
112
 
115
113
  def pick_the_most_recent_one_from_two_matches
@@ -135,7 +133,7 @@ module Danger
135
133
  !most_recent_squash_and_merged_pull_request.nil? && !most_recent_squash_and_merged_pull_request.empty?
136
134
  end
137
135
 
138
- def client
136
+ def client(env)
139
137
  scm_provider = find_scm_provider(remote_url)
140
138
 
141
139
  case scm_provider
@@ -148,6 +146,10 @@ module Danger
148
146
  require "danger/request_sources/bitbucket_server_api"
149
147
  project, slug = repo_slug.split("/")
150
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)
151
153
 
152
154
  when :github
153
155
  require "octokit"
@@ -168,7 +170,7 @@ module Danger
168
170
  def api_url
169
171
  ENV.fetch("DANGER_GITHUB_API_HOST") do
170
172
  ENV.fetch("DANGER_GITHUB_API_BASE_URL") do
171
- "https://api.github.com/".freeze
173
+ "https://api.github.com/"
172
174
  end
173
175
  end
174
176
  end
@@ -178,6 +180,8 @@ module Danger
178
180
  :bitbucket_cloud
179
181
  elsif remote_url =~ %r{/pull-requests/}
180
182
  :bitbucket_server
183
+ elsif remote_url =~ /\.visualstudio\.com/i || remote_url =~ /dev\.azure\.com/i
184
+ :vsts
181
185
  else
182
186
  :github
183
187
  end
@@ -155,7 +155,7 @@ module Danger
155
155
  repo_slug = env["BITBUCKET_REPO_SLUG"]
156
156
  begin
157
157
  Danger::RequestSources::BitbucketCloudAPI.new(repo_slug, nil, branch_name, env).pull_request_id
158
- rescue
158
+ rescue StandardError
159
159
  raise "Failed to find a pull request for branch \"#{branch_name}\" on Bitbucket."
160
160
  end
161
161
  end
@@ -1,16 +1,16 @@
1
1
  module Danger
2
2
  # ### CI Setup
3
3
  #
4
- # In order to work with Xcode Cloud and Danger, you will need to add `bundle exec danger` to
4
+ # In order to work with Xcode Cloud and Danger, you will need to add `bundle exec danger` to
5
5
  # the `ci_scripts/ci_post_xcodebuild.sh` (Xcode Cloud's expected filename for a post-action build script).
6
6
  # More details and documentation on Xcode Cloud configuration can be found [here](https://developer.apple.com/documentation/xcode/writing-custom-build-scripts).
7
- #
7
+ #
8
8
  # ### Token Setup
9
9
  #
10
- # You will need to add the `DANGER_GITHUB_API_TOKEN` to your build environment.
11
- # If running on GitHub Enterprise, make sure you also set the expected values for
10
+ # You will need to add the `DANGER_GITHUB_API_TOKEN` to your build environment.
11
+ # If running on GitHub Enterprise, make sure you also set the expected values for
12
12
  # both `DANGER_GITHUB_API_HOST` and `DANGER_GITHUB_HOST`.
13
- #
13
+ #
14
14
  class XcodeCloud < CI
15
15
  def self.validates_as_ci?(env)
16
16
  env.key? "CI_XCODEBUILD_ACTION"
@@ -23,8 +23,8 @@ module Danger
23
23
  def supported_request_sources
24
24
  @supported_request_sources ||= [
25
25
  Danger::RequestSources::GitHub,
26
- Danger::RequestSources::GitLab,
27
- Danger::RequestSources::BitbucketCloud,
26
+ Danger::RequestSources::GitLab,
27
+ Danger::RequestSources::BitbucketCloud,
28
28
  Danger::RequestSources::BitbucketServer
29
29
  ]
30
30
  end
@@ -145,7 +145,7 @@ module Danger
145
145
  def current_repo_slug
146
146
  git = GitRepo.new
147
147
 
148
- author_repo_regexp = %r{(?:[\/:])([^\/]+\/[^\/]+)(?:.git)?$}
148
+ author_repo_regexp = %r{(?:[/:])([^/]+/[^/]+)(?:.git)?$}
149
149
  last_git_regexp = /.git$/
150
150
 
151
151
  matches = git.origins.match(author_repo_regexp)
@@ -66,7 +66,7 @@ module Danger
66
66
 
67
67
  private
68
68
 
69
- # this method is a duplicate of Commands::PR#configure_octokit
69
+ #  this method is a duplicate of Commands::PR#configure_octokit
70
70
  # - worth a refactor sometime?
71
71
  def configure_octokit(cache_dir)
72
72
  # setup caching for Github calls to hitting the API rate limit too quickly
@@ -3,6 +3,7 @@ require "pstore"
3
3
  module Danger
4
4
  class HTTPCache
5
5
  attr_reader :expires_in
6
+
6
7
  def initialize(cache_file = nil, options = {})
7
8
  File.delete(cache_file) if options[:clear_cache]
8
9
  @store = PStore.new(cache_file)
@@ -14,6 +15,7 @@ module Danger
14
15
  entry = @store[key]
15
16
  return nil unless entry
16
17
  return entry[:value] unless entry_has_expired(entry, @expires_in)
18
+
17
19
  @store.delete key
18
20
  return nil
19
21
  end
@@ -22,6 +22,8 @@ module Danger
22
22
 
23
23
  if gh.instance_of? Danger::RequestSources::BitbucketServer
24
24
  cork.puts "Running your Dangerfile against this PR - #{gh.host}/projects/#{source.repo_slug.split('/').first}/repos/#{source.repo_slug.split('/').last}/pull-requests/#{source.pull_request_id}"
25
+ elsif gh.instance_of? Danger::RequestSources::VSTS
26
+ cork.puts "Running your Dangerfile against this PR - #{gh.client.pr_api_endpoint}"
25
27
  else
26
28
  cork.puts "Running your Dangerfile against this PR - https://#{gh.host}/#{source.repo_slug}/pull/#{source.pull_request_id}"
27
29
  end
@@ -6,6 +6,7 @@ module Danger
6
6
 
7
7
  def setup_pry(dangerfile_path, command)
8
8
  return dangerfile_path if dangerfile_path.empty?
9
+
9
10
  validate_pry_available(command)
10
11
  FileUtils.cp dangerfile_path, DANGERFILE_COPY
11
12
  File.open(DANGERFILE_COPY, "a") do |f|
@@ -3,7 +3,7 @@ require "danger/plugin_support/plugin_file_resolver"
3
3
 
4
4
  module Danger
5
5
  class PluginJSON < CLAide::Command::Plugins
6
- self.summary = "Prints the JSON documentation representing a plugin"
6
+ self.summary = "Lint plugins from files, gems or the current folder. Outputs JSON array representation of Plugins on success."
7
7
  self.command = "json"
8
8
 
9
9
  attr_accessor :cork
@@ -15,8 +15,6 @@ module Danger
15
15
  super
16
16
  end
17
17
 
18
- self.summary = "Lint plugins from files, gems or the current folder. Outputs JSON array representation of Plugins on success."
19
-
20
18
  self.description = <<-DESC
21
19
  Converts a collection of file paths of Danger plugins into a JSON format.
22
20
  DESC
@@ -17,8 +17,6 @@ module Danger
17
17
  super
18
18
  end
19
19
 
20
- self.summary = "Lint plugins from files, gems or the current folder. Outputs JSON array representation of Plugins on success."
21
-
22
20
  self.description = <<-DESC
23
21
  Converts a collection of file paths of Danger plugins into a JSON format.
24
22
  Note: Before 1.0, it will also parse the represented JSON to validate whether https://danger.systems would
@@ -8,7 +8,7 @@ module Danger
8
8
  self.summary = "Generates a README from a set of plugins"
9
9
  self.command = "readme"
10
10
 
11
- attr_accessor :cork, :json
11
+ attr_accessor :cork, :json, :markdown
12
12
 
13
13
  def initialize(argv)
14
14
  @refs = argv.arguments! unless argv.arguments.empty?
@@ -17,8 +17,6 @@ module Danger
17
17
  super
18
18
  end
19
19
 
20
- self.summary = "Lint plugins from files, gems or the current folder. Outputs JSON array representation of Plugins on success."
21
-
22
20
  self.description = <<-DESC
23
21
  Converts a collection of file paths of Danger plugins into a format usable in a README.
24
22
  This is useful for Danger itself, but also for any plugins wanting to showcase their API.
@@ -28,7 +26,6 @@ module Danger
28
26
  CLAide::Argument.new("Paths, Gems or Nothing", false, true)
29
27
  ]
30
28
 
31
- attr_accessor :json, :markdown
32
29
  def run
33
30
  file_resolver = PluginFileResolver.new(@refs)
34
31
  data = file_resolver.resolve
@@ -39,7 +36,7 @@ module Danger
39
36
  self.json = JSON.parse(parser.to_json_string)
40
37
 
41
38
  template = File.join(Danger.gem_path, "lib/danger/plugin_support/templates/readme_table.html.erb")
42
- cork.puts ERB.new(File.read(template), 0, "-").result(binding)
39
+ cork.puts ERB.new(File.read(template), trim_mode: "-").result(binding)
43
40
  end
44
41
  end
45
42
  end
@@ -67,7 +67,8 @@ module Danger
67
67
  @dangerfile_path,
68
68
  nil,
69
69
  nil,
70
- nil
70
+ nil,
71
+ false
71
72
  )
72
73
  end
73
74
  end
@@ -51,7 +51,7 @@ module Danger
51
51
 
52
52
  def validate!
53
53
  super
54
- if self.class == Runner && !@dangerfile_path
54
+ if self.instance_of?(Runner) && !@dangerfile_path
55
55
  help!("Could not find a Dangerfile.")
56
56
  end
57
57
  end
@@ -9,7 +9,7 @@ module Danger
9
9
 
10
10
  def self.options
11
11
  [
12
- ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."]
12
+ ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."]
13
13
  ]
14
14
  end
15
15
 
@@ -41,12 +41,12 @@ module Danger
41
41
  dm = Dangerfile.new(env, cork)
42
42
 
43
43
  dm.run(
44
- Danger::EnvironmentManager.danger_base_branch,
45
- Danger::EnvironmentManager.danger_head_branch,
46
- @dangerfile_path,
47
- nil,
48
- nil,
49
- nil
44
+ Danger::EnvironmentManager.danger_base_branch,
45
+ Danger::EnvironmentManager.danger_head_branch,
46
+ @dangerfile_path,
47
+ nil,
48
+ nil,
49
+ nil
50
50
  )
51
51
  end
52
52
  end
@@ -16,12 +16,10 @@ module Danger
16
16
  require "yard"
17
17
  # Pull out all the Danger::CI subclasses docs
18
18
  registry = YARD::Registry.load(ci_source_paths, true)
19
- ci_sources = begin
20
- registry.all(:class)
21
- .select { |klass| klass.inheritance_tree.map(&:name).include? :CI }
22
- .reject { |source| source.name == :CI }
23
- .reject { |source| source.name == :LocalGitRepo }
24
- end
19
+ ci_sources = registry.all(:class)
20
+ .select { |klass| klass.inheritance_tree.map(&:name).include? :CI }
21
+ .reject { |source| source.name == :CI }
22
+ .reject { |source| source.name == :LocalGitRepo }
25
23
 
26
24
  # Fail if anything is added and not documented
27
25
  cis_without_docs = ci_sources.select { |source| source.base_docstring.empty? }
@@ -17,5 +17,5 @@
17
17
  <%= current %>
18
18
  <%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
19
19
  <%- end -%>
20
- <%# Add the generated_by_ as a html coment to identify comments from danger. %>
20
+ <%# Add the generated_by_ as a html comment to identify comments from danger. %>
21
21
  <!-- "generated_by_<%= @danger_id %>" -->
@@ -0,0 +1,17 @@
1
+ <%- @tables.each do |table| -%>
2
+ <%- if table[:content].any? || table[:resolved].any? -%>
3
+ | | |
4
+ |---|---|
5
+ <%- table[:content].each do |violation| -%>
6
+ | <%= @emoji_mapper.map(table[:emoji]) %> | <%= "~~" if table[:resolved] %><%= violation.message %><%= "~~" if table[:resolved] %> |
7
+ <%- end -%>
8
+
9
+ <%- end -%>
10
+ <%- end -%>
11
+
12
+ <%- @markdowns.each do |current| -%>
13
+ <%= current %>
14
+ <%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
15
+ <%- end -%>
16
+
17
+ Generated by :no_entry_sign: [Danger](https://danger.systems/ "generated_by_<%= @danger_id %>")
@@ -8,8 +8,8 @@ module Danger
8
8
  # e.g. "**/something.*" for any file called something with any extension
9
9
  def include?(pattern)
10
10
  self.each do |current|
11
- unless current.nil?
12
- return true if File.fnmatch(pattern, current, File::FNM_EXTGLOB) || pattern == current
11
+ if !current.nil? && (File.fnmatch(pattern, current, File::FNM_EXTGLOB) || pattern == current)
12
+ return true
13
13
  end
14
14
  end
15
15
  return false