danger 5.1.1 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 051a1eff59fbb30ef3a90f379783241daaee7aa8
4
- data.tar.gz: 4fdf31bea14978875ae00a72816044a227cb868b
3
+ metadata.gz: 48231f5c4a008b745dd304f7906936fd7891a456
4
+ data.tar.gz: dfce17a735b94f29ee7c25e66929ffe701a95b61
5
5
  SHA512:
6
- metadata.gz: 4ce2b6b94273078e83bdd4dc97677794bff34379bcdf41b9fc95d3f6ed9f8036a743388aec2573582c804f87bd8b57d22de788d973b94000bb86b4a30a2348c3
7
- data.tar.gz: 88cf6322df304ed625c0c60d31ac4939152e6dee19cca469ac14e1333ff39d188fc2ef6ce6d9aa679c8599f9833ff00afb12e489f1f040a2ccb67600bdfa39c2
6
+ metadata.gz: db0bbe283f6ee56778c04c69cbd75de99331d1ad2b63c6f095d72cd0c3ab04177e2623c91d852e196825ef0a656b01369c045db93e878ebf971f87bf52a45648
7
+ data.tar.gz: 6ae09d8f4dfef272f7d2b28983c31f75b11a99436634f8db5ae5e5b41d2fc548ead0835e173e6805df7bdfbf014358c73535d8afe845a2a8c30d29b014de9bf8
@@ -0,0 +1,52 @@
1
+ require "danger/request_sources/github/github"
2
+
3
+ module Danger
4
+ # https://groupon.github.io/DotCi
5
+
6
+ # ### CI Setup
7
+ # DotCi is a layer on top of jenkins. So, if you're using DotCi, you're hosting your own environment.
8
+ #
9
+ # ### Token Setup
10
+ #
11
+ # #### GitHub
12
+ # As you own the machine, it's up to you to add the environment variable for the `DANGER_GITHUB_API_TOKEN`.
13
+ #
14
+ class DotCi < CI
15
+ def self.validates_as_ci?(env)
16
+ env.key? "DOTCI"
17
+ end
18
+
19
+ def self.validates_as_pr?(env)
20
+ !env["DOTCI_PULL_REQUEST"].nil? && !env["DOTCI_PULL_REQUEST"].match(/^[0-9]+$/).nil?
21
+ end
22
+
23
+ def supported_request_sources
24
+ @supported_request_sources ||= begin
25
+ [
26
+ Danger::RequestSources::GitHub
27
+ ]
28
+ end
29
+ end
30
+
31
+ def initialize(env)
32
+ self.repo_url = self.class.repo_url(env)
33
+ self.pull_request_id = self.class.pull_request_id(env)
34
+ repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+)$})
35
+ self.repo_slug = repo_matches[2].gsub(/\.git$/, "") unless repo_matches.nil?
36
+ end
37
+
38
+ def self.pull_request_id(env)
39
+ env["DOTCI_PULL_REQUEST"]
40
+ end
41
+
42
+ def self.repo_url(env)
43
+ if env["DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL"]
44
+ env["DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL"]
45
+ elsif env["DOTCI_DOCKER_COMPOSE_GIT_CLONE_URL"]
46
+ env["DOTCI_DOCKER_COMPOSE_GIT_CLONE_URL"]
47
+ else
48
+ env["GIT_URL"]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -278,6 +278,10 @@ module Danger
278
278
 
279
279
  # Print results in the terminal
280
280
  print_results
281
+ rescue DSLError => ex
282
+ # Push exception to the API and re-raise
283
+ post_exception(ex, danger_id, new_comment) unless danger_id.nil?
284
+ raise
281
285
  ensure
282
286
  # Makes sure that Danger specific git branches are cleaned
283
287
  env.clean_up
@@ -310,5 +314,13 @@ module Danger
310
314
  "#{line}\n"
311
315
  end
312
316
  end
317
+
318
+ def post_exception(ex, danger_id, new_comment)
319
+ env.request_source.update_pull_request!(
320
+ danger_id: danger_id,
321
+ new_comment: new_comment,
322
+ markdowns: [ex.to_markdown]
323
+ )
324
+ end
313
325
  end
314
326
  end
@@ -62,42 +62,69 @@ module Danger
62
62
  #
63
63
  def message
64
64
  @message ||= begin
65
- trace_line, description = parse_line_number_from_description
66
- latest_version = Danger.danger_outdated?
67
-
68
- m = "\n[!] "
69
- m << description
70
- if latest_version
71
- m << upgrade_message(latest_version)
72
- end
73
- m = m.red if m.respond_to?(:red)
74
-
75
- return m unless backtrace && dsl_path && contents
76
-
77
- trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) } || trace_line
78
- return m unless trace_line
79
- line_numer = trace_line.split(":")[1].to_i - 1
80
- return m unless line_numer
81
-
82
- lines = contents.lines
83
- indent = " # "
84
- indicator = indent.tr("#", ">")
85
- first_line = line_numer.zero?
86
- last_line = (line_numer == (lines.count - 1))
87
-
88
- m << "\n"
89
- m << "#{indent}from #{trace_line.gsub(/:in.*$/, '')}\n"
90
- m << "#{indent}-------------------------------------------\n"
91
- m << "#{indent}#{lines[line_numer - 1]}" unless first_line
92
- m << "#{indicator}#{lines[line_numer]}"
93
- m << "#{indent}#{lines[line_numer + 1]}" unless last_line
94
- m << "\n" unless m.end_with?("\n")
95
- m << "#{indent}-------------------------------------------\n"
65
+ description, stacktrace = parse.values_at(:description, :stacktrace)
66
+
67
+ msg = description
68
+ msg = msg.red if msg.respond_to?(:red)
69
+ msg << stacktrace if stacktrace
70
+ msg
71
+ end
72
+ end
73
+
74
+ def to_markdown
75
+ @markdown ||= begin
76
+ description, stacktrace = parse.values_at(:description, :stacktrace)
77
+
78
+ # Highlight failed method in markdown
79
+ description = description.tr("'", "`")
80
+
81
+ # Escape markdown brackets
82
+ description = description.gsub(/<|>/) { |bracket| "\\#{bracket}" }
83
+
84
+ md = "## Danger has errored"
85
+ md << "#{description}\n"
86
+ md << "```#{stacktrace}```" if stacktrace
87
+
88
+ Markdown.new(md, nil, nil)
96
89
  end
97
90
  end
98
91
 
99
92
  private
100
93
 
94
+ def parse
95
+ result = {}
96
+
97
+ trace_line, description = parse_line_number_from_description
98
+ latest_version = Danger.danger_outdated?
99
+
100
+ result[:description] = "\n[!] #{description}"
101
+ result[:description] << upgrade_message(latest_version) if latest_version
102
+
103
+ return result unless backtrace && dsl_path && contents
104
+
105
+ trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) } || trace_line
106
+ return result unless trace_line
107
+ line_numer = trace_line.split(":")[1].to_i - 1
108
+ return result unless line_numer
109
+
110
+ lines = contents.lines
111
+ indent = " # "
112
+ indicator = indent.tr("#", ">")
113
+ first_line = line_numer.zero?
114
+ last_line = (line_numer == (lines.count - 1))
115
+
116
+ result[:stacktrace] = "\n"
117
+ result[:stacktrace] << "#{indent}from #{trace_line.gsub(/:in.*$/, '')}\n"
118
+ result[:stacktrace] << "#{indent}-------------------------------------------\n"
119
+ result[:stacktrace] << "#{indent}#{lines[line_numer - 1]}" unless first_line
120
+ result[:stacktrace] << "#{indicator}#{lines[line_numer]}"
121
+ result[:stacktrace] << "#{indent}#{lines[line_numer + 1]}" unless last_line
122
+ result[:stacktrace] << "\n" unless result[:stacktrace].end_with?("\n")
123
+ result[:stacktrace] << "#{indent}-------------------------------------------\n"
124
+
125
+ result
126
+ end
127
+
101
128
  def parse_line_number_from_description
102
129
  description = self.description
103
130
  if dsl_path && description =~ /((#{Regexp.quote File.expand_path(dsl_path)}|#{Regexp.quote dsl_path.to_s}):\d+)/
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "5.1.1".freeze
2
+ VERSION = "5.2.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.1.1
4
+ version: 5.2.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: 2017-04-27 00:00:00.000000000 Z
12
+ date: 2017-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -367,6 +367,7 @@ files:
367
367
  - lib/danger/ci_source/ci_source.rb
368
368
  - lib/danger/ci_source/circle.rb
369
369
  - lib/danger/ci_source/circle_api.rb
370
+ - lib/danger/ci_source/dotci.rb
370
371
  - lib/danger/ci_source/drone.rb
371
372
  - lib/danger/ci_source/gitlab_ci.rb
372
373
  - lib/danger/ci_source/jenkins.rb