danger 0.1.1 → 0.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: c2df0507da13cc40eb7f1d93256d1c5da4363ee0
4
- data.tar.gz: 89be5c58b12e017286d8d0dedafcd5adc80f05bf
3
+ metadata.gz: 9a534e4b3084cff5f94432c123204a9fac9a4859
4
+ data.tar.gz: dc850675fbd49a0059842c2c5af8fff5c3dbb110
5
5
  SHA512:
6
- metadata.gz: 44a07b2b9aca7eac7d487576fc1efb3332e3e978120c49046428ae623e8b76c5ed965ec44b5482bb3b5024206301490933118537275723ba1acdc8d14fdc6690
7
- data.tar.gz: 10c85b4daeb7feff0c22d8c3b39746aaa14963bba02788b9a83d310334670c857eb4a5d651801e74803b68c4d9c7a92b373fcaa8747d5844a4fcd7653ef259aa
6
+ metadata.gz: 29f4abd20107421d94ff5b0159aceedd2aeb35b940ec11c2deab97c255b5bab22e80c42e1c01954cab01bd8a36ecb3492a5c79c101af10b0f46733fad2a2ccd4
7
+ data.tar.gz: c2840f76f6961a600a9a2b98b7603ee3fa0fbfaf83f43dbee57f0f7c5fa20f603849429d34a9a12baa9f9ad593765f7793651fc6febcb4754609156cca8ec328
data/README.md CHANGED
@@ -55,12 +55,12 @@ You can then create a `Dangerfile` like the following:
55
55
  # Easy checks
56
56
  warn("PR is classed as Work in Progress") if pr_title.include? "[WIP]"
57
57
 
58
- if lines_of_code > 50 && files_modified.include? "CHANGELOG.yml" == false
58
+ if lines_of_code > 50 && files_modified.include?("CHANGELOG.yml") == false
59
59
  fail("No CHANGELOG changes made")
60
60
  end
61
61
 
62
62
  # Stop skipping some manual testing
63
- if lines_of_code > 50 && pr_title.include? "📱" == false
63
+ if lines_of_code > 50 && pr_title.include?("📱") == false
64
64
  fail("Needs testing on a Phone if change is non-trivial")
65
65
  end
66
66
 
@@ -5,12 +5,14 @@ module Danger
5
5
  module CISource
6
6
  class CircleCI < CI
7
7
  def self.validates?(env)
8
- return !env["CIRCLE_BUILD_NUM"].nil? && !env["CI_PULL_REQUEST"].nil?
8
+ return !env["CIRCLE_BUILD_NUM"].nil? &&
9
+ !env["CI_PULL_REQUEST"].nil? &&
10
+ URI.parse(env["CI_PULL_REQUEST"]).path.split("/").count == 5
9
11
  end
10
12
 
11
13
  def initialize(env)
12
14
  paths = URI.parse(env["CI_PULL_REQUEST"]).path.split("/")
13
- # the first one is an extra slash, ignore it
15
+ # The first one is an extra slash, ignore it
14
16
  self.repo_slug = paths[1] + "/" + paths[2]
15
17
  self.pull_request_id = paths[4]
16
18
  end
@@ -1,32 +1,14 @@
1
- <% if @errors.count > 0 %>
2
- &nbsp; | <%= @errors.count %> Error<%= "s" unless @errors.count == 1 %>
3
- ------------- | ------------ <% @errors.each do |error| %>
4
- :no_entry_sign: | <%= error %><% end %>
5
- <% else %>
6
- :white_check_mark: | No errors found
7
- ------------- | ------------
1
+ <% @tables.each do |table| %>
2
+ <% if table[:content].any? %>
3
+ &nbsp; | <%= table[:content].count %> <%= table[:name] %><%= "s" unless table[:content].count == 1 %>
4
+ ------------- | ------------
5
+ <% table[:content].each do |message| -%>
6
+ :<%= table[:emoji] %>: | <%= message %>
7
+ <% end %>
8
+
9
+ <% end %>
8
10
  <% end %>
9
11
 
10
- <% if @warnings.count > 0 %>
11
- &nbsp; | <%= @warnings.count %> Warning<%= "s" unless @warnings.count == 1 %>
12
- ------------- | ------------ <% @warnings.each do |warning| %>
13
- :warning: | <%= warning %><% end %>
14
- <% else %>
15
- :white_check_mark: | No warnings found
16
- ------------- | ------------
17
- <% end %>
18
-
19
- <% if @messages.count > 0 %>
20
- &nbsp; | <%= @messages.count %> Message<%= "s" unless @messages.count == 1 %>
21
- ------------- | ------------ <% @messages.each do |message| %>
22
- :book: | <%= message %><% end %>
23
- <% end %>
24
-
25
- <p align="right">
26
- Generated by
27
- <a href="https://github.com/KrauseFx/danger">danger</a>
28
- on
29
- <i><%= Time.now.strftime("%Y-%m-%d") %></i>
12
+ <p align="right" meta="generated_by_danger">
13
+ Generated by :no_entry_sign: <a href="https://github.com/KrauseFx/danger/">danger</a>
30
14
  </p>
31
-
32
- <% "" # the reason why we have the each in the same line is because we don't want a new line in the markdown file %>
@@ -23,7 +23,8 @@ module Danger
23
23
 
24
24
  raise "Could not find a CI source".red unless self.ci_source
25
25
 
26
- self.request_source = GitHub.new(self.ci_source) # for now
26
+ # only GitHub for now, open for PRs adding more!
27
+ self.request_source = GitHub.new(self.ci_source, ENV)
27
28
  end
28
29
 
29
30
  def fill_environment_vars
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'rest'
2
3
  require 'json'
3
4
  require 'base64'
@@ -5,14 +6,15 @@ require 'octokit'
5
6
 
6
7
  module Danger
7
8
  class GitHub
8
- attr_accessor :ci_source, :pr_json
9
+ attr_accessor :ci_source, :pr_json, :environment
9
10
 
10
- def initialize(ci_source)
11
+ def initialize(ci_source, environment)
11
12
  self.ci_source = ci_source
13
+ self.environment = environment
12
14
  end
13
15
 
14
16
  def client
15
- token = ENV["DANGER_GITHUB_API_TOKEN"]
17
+ token = @environment["DANGER_GITHUB_API_TOKEN"]
16
18
  raise "No API given, please provide one using `DANGER_GITHUB_API_TOKEN`" unless token
17
19
 
18
20
  @client ||= Octokit::Client.new(
@@ -42,56 +44,81 @@ module Danger
42
44
 
43
45
  # Sending data to GitHub
44
46
  def update_pull_request!(warnings: nil, errors: nil, messages: nil)
45
- # First, add a comment
46
- body = generate_comment(warnings: warnings, errors: errors, messages: messages)
47
- result = client.add_comment(ci_source.repo_slug, ci_source.pull_request_id, body)
48
- delete_old_comment!(except: result[:id])
47
+ comment_result = {}
49
48
 
50
- # Now, set the pull request status
49
+ if (warnings + errors + messages).empty?
50
+ # Just remove the comment, if there's nothing to say.
51
+ delete_old_comments!
52
+ else
53
+ body = generate_comment(warnings: warnings, errors: errors, messages: messages)
54
+ comment_result = client.add_comment(ci_source.repo_slug, ci_source.pull_request_id, body)
55
+ delete_old_comments!(except: comment_result[:id])
56
+ end
57
+
58
+ # Now, set the pull request status.
59
+ # Note: this can terminate the entire process.
51
60
  submit_pull_request_status!(warnings: warnings,
52
61
  errors: errors,
53
- details_url: result['html_url'])
62
+ details_url: comment_result['html_url'])
54
63
  end
55
64
 
56
65
  def submit_pull_request_status!(warnings: nil, errors: nil, details_url: nil)
57
66
  status = (errors.count == 0 ? 'success' : 'failure')
67
+ message = generate_github_description(warnings: warnings, errors: errors)
58
68
  client.create_status(ci_source.repo_slug, latest_pr_commit_ref, status, {
59
- description: generate_github_description(warnings: warnings, errors: errors),
69
+ description: message,
60
70
  context: "KrauseFx/danger",
61
71
  target_url: details_url
62
72
  })
73
+ rescue
74
+ # This usually means the user has no commit access to this repo
75
+ # That's always the case for open source projects where you can only
76
+ # use a read-only GitHub account
77
+ if errors.count > 0
78
+ # We need to fail the actual build here
79
+ abort("\nDanger has failed this build. \nFound #{errors.count} error(s) and I don't have write access to the PR set a PR status.")
80
+ else
81
+ puts message
82
+ end
63
83
  end
64
84
 
65
85
  # Get rid of the previously posted comment, to only have the latest one
66
- def delete_old_comment!(except: nil)
86
+ def delete_old_comments!(except: nil)
67
87
  issues = client.issue_comments(ci_source.repo_slug, ci_source.pull_request_id)
68
88
  issues.each do |issue|
69
- next unless issue[:body].gsub(/\s+/, "").include?("Generatedby<ahref=")
89
+ next unless issue[:body].include?("generated_by_danger")
70
90
  next if issue[:id] == except
71
91
  client.delete_comment(ci_source.repo_slug, issue[:id])
72
92
  end
73
93
  end
74
94
 
75
95
  def generate_github_description(warnings: nil, errors: nil)
76
- if errors.count > 0
77
- "danger found errors"
78
- elsif warnings.count > 0
79
- "⚠️ danger found warnings, merge with caution"
96
+ if errors.empty? && warnings.empty?
97
+ compliment = ["Well done.", "Congrats.", "Woo!",
98
+ "Yay.", "Jolly good show.", "Good on 'ya.", "Nice work."]
99
+ return "All green. #{compliment.sample}"
80
100
  else
81
- "danger was successful"
101
+ message = "⚠ "
102
+ message += "#{errors.count} Error#{errors.count == 1 ? '' : 's'}. " unless errors.empty?
103
+ message += "#{warnings.count} Warning#{warnings.count == 1 ? '' : 's'}. " unless warnings.empty?
104
+ message += "Don't worry, everything is fixable."
105
+ return message
82
106
  end
83
107
  end
84
108
 
85
109
  def generate_comment(warnings: nil, errors: nil, messages: nil)
86
110
  require 'erb'
87
111
 
88
- @warnings = warnings
89
- @errors = errors
90
- @messages = messages
91
-
92
112
  md_template = File.join(Danger.gem_path, "lib/danger/comment_generators/github.md.erb")
93
- comment = ERB.new(File.read(md_template)).result(binding) # http://www.rrn.dk/rubys-erb-templating-system
94
- return comment
113
+
114
+ # erb: http://www.rrn.dk/rubys-erb-templating-system
115
+ # for the extra args: http://stackoverflow.com/questions/4632879/erb-template-removing-the-trailing-line
116
+ @tables = [
117
+ { name: "Error", emoji: "no_entry_sign", content: errors },
118
+ { name: "Warning", emoji: "warning", content: warnings },
119
+ { name: "Message", emoji: "book", content: messages }
120
+ ]
121
+ return ERB.new(File.read(md_template), 0, "-").result(binding)
95
122
  end
96
123
  end
97
124
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  DESCRIPTION = "Ensure your pull request is up to standard with a nice DSL"
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: 0.1.1
4
+ version: 0.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: 2016-01-07 00:00:00.000000000 Z
12
+ date: 2016-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -215,8 +215,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  requirements: []
217
217
  rubyforge_project:
218
- rubygems_version: 2.4.6
218
+ rubygems_version: 2.4.0
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: Ensure your pull request is up to standard with a nice DSL
222
222
  test_files: []
223
+ has_rdoc: