danger 5.6.7 → 5.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: eca39151f7232a27b7fc9f54c06dc434d475bd85
4
- data.tar.gz: 6d135a5b57185143b620273b0f3c39a40e502b51
2
+ SHA256:
3
+ metadata.gz: 56b7ad82d2578dafbf08ae9fec98faecb44d8d7e2ee810745618aac4498b6cf2
4
+ data.tar.gz: 973bdc8b5c6ea1c9ebecd968f298bd17939808d42969eedbe59cff1eae5fe086
5
5
  SHA512:
6
- metadata.gz: 3810e8b529e8b0caa024baa621f9c1539a88364d36ff430c1dc884c6f9053141fb807a1bc6858d6d2bef98c48e9ab87334f4f3da7b25b330946d7b3fd0e6aee1
7
- data.tar.gz: b5b5624c645635af6656598c98a70e250db02e6fd2c5316e22aeb3e15da292e317782f04995106048feeb48e8cd0ab15156df8bfcdad4827e3e495ac1369ce57
6
+ metadata.gz: 71671463fd995498764dff063365285a969decc1243406b5aeb008ffefe7e5b0173fdb6290e4e4dace391713c0d962ecc82cd2c07e1d87909c732b31bbaaf1dc
7
+ data.tar.gz: a33754d7365b25988126056d008ba4de240c5a42204c22fbb1b322f3242b1b99b265dd98bd6c9ba96f16db298335bb1ec974f9323b0ef4e903676218583298fe
data/README.md CHANGED
@@ -24,7 +24,7 @@ Danger runs after your CI, automating your team's conventions surrounding code r
24
24
 
25
25
  This provides another logical step in your process, through this Danger can help lint your rote tasks in daily code review.
26
26
 
27
- You can use Danger to codify your teams norms, leaving humans to think about harder problems.
27
+ You can use Danger to codify your team's norms, leaving humans to think about harder problems.
28
28
 
29
29
  ## For example?
30
30
 
@@ -0,0 +1,47 @@
1
+ require "git"
2
+ require "danger/request_sources/local_only"
3
+
4
+ module Danger
5
+ # ### CI Setup
6
+ #
7
+ # For setting up LocalOnlyGitRepo there is not much needed. Either `--base` and `--head` need to be specified or
8
+ # origin/master is expected for base and HEAD for head
9
+ #
10
+ class LocalOnlyGitRepo < CI
11
+ attr_accessor :base_commit, :head_commit
12
+ HEAD_VAR = "DANGER_LOCAL_HEAD".freeze
13
+ BASE_VAR = "DANGER_LOCAL_BASE".freeze
14
+
15
+ def self.validates_as_ci?(env)
16
+ env.key? "DANGER_USE_LOCAL_ONLY_GIT"
17
+ end
18
+
19
+ def self.validates_as_pr?(_env)
20
+ false
21
+ end
22
+
23
+ def git
24
+ @git ||= GitRepo.new
25
+ end
26
+
27
+ def run_git(command)
28
+ git.exec(command).encode("UTF-8", "binary", invalid: :replace, undef: :replace, replace: "")
29
+ end
30
+
31
+ def supported_request_sources
32
+ @supported_request_sources ||= [Danger::RequestSources::LocalOnly]
33
+ end
34
+
35
+ def initialize(env = {})
36
+ @env = env
37
+
38
+ # expects --base/--head specified OR origin/master to be base and HEAD head
39
+ self.base_commit = env[BASE_VAR] || run_git("rev-parse --abbrev-ref origin/master")
40
+ self.head_commit = env[HEAD_VAR] || run_git("rev-parse --abbrev-ref HEAD")
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :env
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ require "danger/commands/local_helpers/pry_setup"
2
+ require "fileutils"
3
+
4
+ module Danger
5
+ class DryRun < Runner
6
+ self.summary = "Dry-Run the Dangerfile locally, so you could check some violations before sending real PR/MR."
7
+ self.command = "dry_run"
8
+
9
+ def self.options
10
+ [
11
+ ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."]
12
+ ]
13
+ end
14
+
15
+ def initialize(argv)
16
+ show_help = true if argv.arguments == ["-h"]
17
+
18
+ # Currently CLAide doesn't support short option like -h https://github.com/CocoaPods/CLAide/pull/60
19
+ # when user pass in -h, mimic the behavior of passing in --help.
20
+ argv = CLAide::ARGV.new ["--help"] if show_help
21
+
22
+ super
23
+
24
+ if argv.flag?("pry", false)
25
+ @dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path)
26
+ end
27
+ end
28
+
29
+ def validate!
30
+ super
31
+ unless @dangerfile_path
32
+ help! "Could not find a Dangerfile."
33
+ end
34
+ end
35
+
36
+ def run
37
+ ENV["DANGER_USE_LOCAL_ONLY_GIT"] = "YES"
38
+ ENV["DANGER_LOCAL_HEAD"] = @head if @head
39
+ ENV["DANGER_LOCAL_BASE"] = @base if @base
40
+
41
+ env = EnvironmentManager.new(ENV, cork)
42
+ dm = Dangerfile.new(env, cork)
43
+
44
+ exit 1 if dm.run(
45
+ Danger::EnvironmentManager.danger_base_branch,
46
+ Danger::EnvironmentManager.danger_head_branch,
47
+ @dangerfile_path,
48
+ nil,
49
+ nil,
50
+ nil
51
+ )
52
+ end
53
+ end
54
+ end
@@ -2,6 +2,7 @@ module Danger
2
2
  class Runner < CLAide::Command
3
3
  require "danger/commands/init"
4
4
  require "danger/commands/local"
5
+ require "danger/commands/dry_run"
5
6
  require "danger/commands/systems"
6
7
  require "danger/commands/pr"
7
8
 
@@ -11,6 +11,7 @@ require "danger/danger_core/plugins/dangerfile_gitlab_plugin"
11
11
  require "danger/danger_core/plugins/dangerfile_bitbucket_server_plugin"
12
12
  require "danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin"
13
13
  require "danger/danger_core/plugins/dangerfile_vsts_plugin"
14
+ require "danger/danger_core/plugins/dangerfile_local_only_plugin"
14
15
 
15
16
  module Danger
16
17
  class Dangerfile
@@ -38,7 +39,7 @@ module Danger
38
39
 
39
40
  # The ones that everything would break without
40
41
  def self.essential_plugin_classes
41
- [DangerfileMessagingPlugin, DangerfileGitPlugin, DangerfileDangerPlugin, DangerfileGitHubPlugin, DangerfileGitLabPlugin, DangerfileBitbucketServerPlugin, DangerfileBitbucketCloudPlugin, DangerfileVSTSPlugin]
42
+ [DangerfileMessagingPlugin, DangerfileGitPlugin, DangerfileDangerPlugin, DangerfileGitHubPlugin, DangerfileGitLabPlugin, DangerfileBitbucketServerPlugin, DangerfileBitbucketCloudPlugin, DangerfileVSTSPlugin, DangerfileLocalOnlyPlugin]
42
43
  end
43
44
 
44
45
  # Both of these methods exist on all objects
@@ -148,7 +148,7 @@ module Danger
148
148
  # @return [String]
149
149
  #
150
150
  def base_commit
151
- @gitlab.base_commit
151
+ @gitlab.mr_json.diff_refs.base_sha
152
152
  end
153
153
 
154
154
  # @!group MR Commit Metadata
@@ -156,7 +156,7 @@ module Danger
156
156
  # @return [String]
157
157
  #
158
158
  def head_commit
159
- @gitlab.commits_json.first.id
159
+ @gitlab.mr_json.diff_refs.head_sha
160
160
  end
161
161
 
162
162
  # @!group GitLab Misc
@@ -0,0 +1,42 @@
1
+ require "danger/plugin_support/plugin"
2
+
3
+ # Danger
4
+ module Danger
5
+ # Handles interacting with local only plugin inside a Dangerfile.
6
+ # It is support pluggin for dry_run command and does not expose any methods.
7
+ # But you can still use other plugins like git
8
+ #
9
+ # @example Check that added lines contains agreed form of words
10
+ #
11
+ # git.diff.each do |chunk|
12
+ # chunk.patch.lines.grep(/^+/).each do |added_line|
13
+ # if added_line.gsub!(/(?<cancel>cancel)(?<rest>[^l[[:space:]][[:punct:]]]+)/i, '>>\k<cancel>-l-\k<rest><<')
14
+ # fail "Single 'L' for cancellation-alike words in '#{added_line}'"
15
+ # end
16
+ # end
17
+ # end
18
+ #
19
+ # @see danger/danger
20
+ # @tags core, local_only
21
+ #
22
+ class DangerfileLocalOnlyPlugin < Plugin
23
+ # So that this init can fail.
24
+ def self.new(dangerfile)
25
+ return nil if dangerfile.env.request_source.class != Danger::RequestSources::LocalOnly
26
+ super
27
+ end
28
+
29
+ def initialize(dangerfile)
30
+ super(dangerfile)
31
+
32
+ @local_repo = dangerfile.env.request_source
33
+ end
34
+
35
+ # The instance name used in the Dangerfile
36
+ # @return [String]
37
+ #
38
+ def self.instance_name
39
+ "local_repo"
40
+ end
41
+ end
42
+ end
@@ -65,12 +65,7 @@ module Danger
65
65
  end
66
66
 
67
67
  def base_commit
68
- if self.commits_json.last
69
- first_commit_in_branch = self.commits_json.last.id
70
- @base_commit ||= self.scm.exec "rev-parse #{first_commit_in_branch}^1"
71
- else
72
- @base_commit = ""
73
- end
68
+ @base_commit ||= self.mr_json.diff_refs.base_sha
74
69
  end
75
70
 
76
71
  def mr_comments
@@ -89,11 +84,12 @@ module Danger
89
84
  end
90
85
 
91
86
  def setup_danger_branches
92
- raise "Are you running `danger local/pr` against the correct repository? Also this can happen if you run danger on MR without changes" if base_commit.empty?
93
87
  base_branch = self.mr_json.source_branch
94
88
  head_branch = self.mr_json.target_branch
95
89
  head_commit = self.scm.head_commit
96
90
 
91
+ raise "Are you running `danger local/pr` against the correct repository? Also this can happen if you run danger on MR without changes" if base_commit == head_commit
92
+
97
93
  # Next, we want to ensure that we have a version of the current branch at a known location
98
94
  scm.ensure_commitish_exists_on_branch! base_branch, base_commit
99
95
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"
@@ -106,9 +102,6 @@ module Danger
106
102
 
107
103
  def fetch_details
108
104
  self.mr_json = client.merge_request(ci_source.repo_slug, self.ci_source.pull_request_id)
109
- self.commits_json = client.merge_request_commits(
110
- ci_source.repo_slug, self.ci_source.pull_request_id
111
- ).auto_paginate
112
105
  self.ignored_violations = ignored_violations_from_pr
113
106
  end
114
107
 
@@ -172,6 +165,13 @@ module Danger
172
165
  def organisation
173
166
  nil # TODO: Implement this
174
167
  end
168
+
169
+ # @return [String] A URL to the specific file, ready to be downloaded
170
+ def file_url(organisation: nil, repository: nil, branch: nil, path: nil)
171
+ branch ||= 'master'
172
+
173
+ "https://#{host}/#{organisation}/#{repository}/raw/#{branch}/#{path}"
174
+ end
175
175
  end
176
176
  end
177
177
  end
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+
3
+ require "danger/helpers/comments_helper"
4
+ require "danger/helpers/comment"
5
+
6
+ module Danger
7
+ module RequestSources
8
+ class LocalOnly < RequestSource
9
+ include Danger::Helpers::CommentsHelper
10
+ attr_accessor :mr_json, :commits_json
11
+
12
+ def self.env_vars
13
+ ["DANGER_LOCAL_ONLY"]
14
+ end
15
+
16
+ def initialize(ci_source, environment)
17
+ self.ci_source = ci_source
18
+ self.environment = environment
19
+ end
20
+
21
+ def validates_as_ci?
22
+ true
23
+ end
24
+
25
+ def validates_as_api_source?
26
+ true
27
+ end
28
+
29
+ def scm
30
+ @scm ||= GitRepo.new
31
+ end
32
+
33
+ def setup_danger_branches
34
+ # Check that discovered values really exists
35
+ [ci_source.base_commit, ci_source.head_commit].each do |commit|
36
+ raise "Specified commit '#{commit}' not found" if scm.exec("rev-parse --quiet --verify #{commit}").empty?
37
+ end
38
+
39
+ self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{ci_source.base_commit}"
40
+ self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{ci_source.head_commit}"
41
+ end
42
+
43
+ def fetch_details; end
44
+
45
+ def update_pull_request!(_hash_needed); end
46
+
47
+ # @return [String] The organisation name, is nil if it can't be detected
48
+ def organisation
49
+ nil
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "5.6.7".freeze
2
+ VERSION = "5.7.0".freeze
3
3
  DESCRIPTION = "Like Unit Tests, but for your Team Culture.".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.7
4
+ version: 5.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-14 00:00:00.000000000 Z
12
+ date: 2018-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -191,6 +191,7 @@ files:
191
191
  - lib/danger/ci_source/gitlab_ci.rb
192
192
  - lib/danger/ci_source/jenkins.rb
193
193
  - lib/danger/ci_source/local_git_repo.rb
194
+ - lib/danger/ci_source/local_only_git_repo.rb
194
195
  - lib/danger/ci_source/screwdriver.rb
195
196
  - lib/danger/ci_source/semaphore.rb
196
197
  - lib/danger/ci_source/support/commits.rb
@@ -210,6 +211,7 @@ files:
210
211
  - lib/danger/clients/rubygems_client.rb
211
212
  - lib/danger/commands/dangerfile/gem.rb
212
213
  - lib/danger/commands/dangerfile/init.rb
214
+ - lib/danger/commands/dry_run.rb
213
215
  - lib/danger/commands/init.rb
214
216
  - lib/danger/commands/init_helpers/interviewer.rb
215
217
  - lib/danger/commands/local.rb
@@ -242,6 +244,7 @@ files:
242
244
  - lib/danger/danger_core/plugins/dangerfile_git_plugin.rb
243
245
  - lib/danger/danger_core/plugins/dangerfile_github_plugin.rb
244
246
  - lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb
247
+ - lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb
245
248
  - lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb
246
249
  - lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb
247
250
  - lib/danger/danger_core/standard_error.rb
@@ -266,6 +269,7 @@ files:
266
269
  - lib/danger/request_sources/github/github_review_resolver.rb
267
270
  - lib/danger/request_sources/github/github_review_unsupported.rb
268
271
  - lib/danger/request_sources/gitlab.rb
272
+ - lib/danger/request_sources/local_only.rb
269
273
  - lib/danger/request_sources/request_source.rb
270
274
  - lib/danger/request_sources/support/get_ignored_violation.rb
271
275
  - lib/danger/request_sources/vsts.rb
@@ -292,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
296
  version: '0'
293
297
  requirements: []
294
298
  rubyforge_project:
295
- rubygems_version: 2.5.2.3
299
+ rubygems_version: 2.7.6
296
300
  signing_key:
297
301
  specification_version: 4
298
302
  summary: Like Unit Tests, but for your Team Culture.