danger 6.2.0 → 6.2.1

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
  SHA256:
3
- metadata.gz: 12728d6688a88a9852c1db80a4538bd610511388749fb76b2f774ea31a9f0517
4
- data.tar.gz: bc6f5250eb2851de5537c9f9ac0755259a6e249c393617125f09665334ab3587
3
+ metadata.gz: 7fc0e933daf60c17871113311a2ff2fb180248a22f0574b2b9c00f7d60705107
4
+ data.tar.gz: 3a94095eaf6b2c14acc45e50f1b3ca6b9ea61814e551dbb2fc088f59425166be
5
5
  SHA512:
6
- metadata.gz: 694c5bae91efcbbc823cf42708533bed4d298ae31af50b4d3dadb3edf50e4acb6aca907eade1e4913fdee370366ad3c1ac3d90e13f2bbb4bcba09a4fb8d14efd
7
- data.tar.gz: 4c62ee57532ea5ef825fc4b7c6798c7bc2496250d3b7d928e60cf392d1dd95ce4fc936a4b07ca28d337cc618450b3a3f612a37b46531aa1a4feca721e0bddc48
6
+ metadata.gz: 0cbc8d6e42a7b0e8bb1e89883f5206cade8543de3cf197e9cc8c26fa66cb0fcf37f498531fd5afe14170a720576271f5e5361d8d51212410a57152b7887a2550
7
+ data.tar.gz: 909bc0705e6ee02713f49666f70bb4d4b05e7c6fd65badf000bbe5fe4f234a9cb1a9c5862189e556c8d8a0b569fdd23eecafacd9073bf2575346f09d0395a324
@@ -7,9 +7,9 @@ module Danger
7
7
  # - bundle exec danger --verbose
8
8
  # ```
9
9
  #
10
- # #### Token Setup
10
+ # ### Token Setup
11
11
  #
12
- # Add `DANGER_BITBUCKETCLOUD_USERNAME` and `DANGER_BITBUCKETCLOUD_USERNAME` to your pipeline repository variable
12
+ # Add `DANGER_BITBUCKETCLOUD_USERNAME` and `DANGER_BITBUCKETCLOUD_PASSWORD` to your pipeline repository variable
13
13
  # or instead using `DANGER_BITBUCKETCLOUD_OAUTH_KEY` and `DANGER_BITBUCKETCLOUD_OAUTH_SECRET`.
14
14
  #
15
15
  # You can find them in Settings > Pipelines > Repository Variables
@@ -17,4 +17,4 @@
17
17
  <%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
18
18
  <%- end -%>
19
19
 
20
- Generated by [Danger](https://danger.systems/ "generated_by_<%= @danger_id %>")
20
+ Generated by :no_entry_sign: [Danger](https://danger.systems/ "generated_by_<%= @danger_id %>")
@@ -0,0 +1,15 @@
1
+ <%- @tables.each do |table| -%>
2
+ <%- table[:content].each do |violation| -%>
3
+ <%= @emoji_mapper.map(table[:emoji]) if table[:emoji] %> <%= violation.message %>
4
+ <%- end -%>
5
+ <%- table[:resolved].each do |message| -%>
6
+ <%= @emoji_mapper.map("white_check_mark") %> <%= message %>
7
+ <%- end -%>
8
+ <%- end -%>
9
+
10
+ <%- @markdowns.each do |current| -%>
11
+ <%= current %>
12
+ <%# the previous line has to be aligned far to the left, otherwise markdown can break easily %>
13
+ <%- end -%>
14
+
15
+ Generated by :no_entry_sign: [Danger](https://danger.systems/ "generated_by_<%= @danger_id %>")
@@ -104,7 +104,7 @@ module Danger
104
104
  )
105
105
  end
106
106
 
107
- def generate_inline_comment_body(emoji, message, danger_id: "danger", resolved: false, template: "github")
107
+ def generate_inline_comment_body(emoji, message, danger_id: "danger", resolved: [], template: "github")
108
108
  apply_template(
109
109
  tables: [{ content: [message], resolved: resolved, emoji: emoji }],
110
110
  danger_id: danger_id,
@@ -120,11 +120,12 @@ module Danger
120
120
  )
121
121
  end
122
122
 
123
- def generate_description(warnings: nil, errors: nil)
123
+ def generate_description(warnings: nil, errors: nil, template: "github")
124
+ emoji_mapper = EmojiMapper.new(template)
124
125
  if errors.empty? && warnings.empty?
125
126
  return "All green. #{random_compliment}"
126
127
  else
127
- message = "⚠️ "
128
+ message = "#{emoji_mapper.map('warning')} "
128
129
  message += "#{'Error'.danger_pluralize(errors.count)}. " unless errors.empty?
129
130
  message += "#{'Warning'.danger_pluralize(warnings.count)}. " unless warnings.empty?
130
131
  message += "Don't worry, everything is fixable."
@@ -8,15 +8,16 @@ module Danger
8
8
  "white_check_mark" => "✅"
9
9
  },
10
10
  "bitbucket_server" => {
11
- "no_entry_sign" => "\u274C",
12
- "warning" => "⚠️",
13
- "book" => "\u2728",
14
- "white_check_mark" => "\u2705"
11
+ "no_entry_sign" => ":no_entry_sign:",
12
+ "warning" => ":warning:",
13
+ "book" => ":book:",
14
+ "white_check_mark" => ":white_check_mark:"
15
15
  }
16
16
  }.freeze
17
17
 
18
18
  def initialize(template)
19
- @template = DATA.include?(template) ? template : "github"
19
+ template.sub!('_inline', '')
20
+ @template = DATA.has_key?(template) ? template : "github"
20
21
  end
21
22
 
22
23
  def map(emoji)
@@ -71,21 +71,52 @@ module Danger
71
71
  def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger", new_comment: false, remove_previous_comments: false)
72
72
  delete_old_comments(danger_id: danger_id) if !new_comment || remove_previous_comments
73
73
 
74
- comment = generate_description(warnings: warnings, errors: errors)
74
+ comment = generate_description(warnings: warnings, errors: errors, template: "bitbucket_server")
75
75
  comment += "\n\n"
76
+
77
+ warnings = update_inline_comments_for_kind!(:warnings, warnings, danger_id: danger_id)
78
+ errors = update_inline_comments_for_kind!(:errors, errors, danger_id: danger_id)
79
+ messages = update_inline_comments_for_kind!(:messages, messages, danger_id: danger_id)
80
+ markdowns = update_inline_comments_for_kind!(:markdowns, markdowns, danger_id: danger_id)
81
+
76
82
  comment += generate_comment(warnings: warnings,
77
- errors: errors,
78
- messages: messages,
79
- markdowns: markdowns,
80
- previous_violations: {},
81
- danger_id: danger_id,
82
- template: "bitbucket_server")
83
+ errors: errors,
84
+ messages: messages,
85
+ markdowns: markdowns,
86
+ previous_violations: {},
87
+ danger_id: danger_id,
88
+ template: "bitbucket_server")
83
89
 
84
90
  @api.post_comment(comment)
85
91
  end
86
92
 
93
+ def update_inline_comments_for_kind!(kind, messages, danger_id: "danger")
94
+ emoji = { warnings: "warning", errors: "no_entry_sign", messages: "book" }[kind]
95
+
96
+ messages.reject do |message|
97
+ next false unless message.file && message.line
98
+
99
+ body = ""
100
+
101
+ if kind == :markdown
102
+ body = generate_inline_markdown_body(message,
103
+ danger_id: danger_id,
104
+ template: "bitbucket_server")
105
+ else
106
+ body = generate_inline_comment_body(emoji, message,
107
+ danger_id: danger_id,
108
+ template: "bitbucket_server")
109
+ end
110
+
111
+ @api.post_comment(body, file: message.file, line: message.line)
112
+
113
+ true
114
+ end
115
+ end
116
+
87
117
  def delete_old_comments(danger_id: "danger")
88
118
  @api.fetch_last_comments.each do |c|
119
+ next if c[:user][:uuid] != @api.my_uuid
89
120
  @api.delete_comment(c[:id]) if c[:content][:raw] =~ /generated_by_#{danger_id}/
90
121
  end
91
122
  end
@@ -30,6 +30,11 @@ module Danger
30
30
  @username && !@username.empty? && @password && !@password.empty?
31
31
  end
32
32
 
33
+ def my_uuid
34
+ uri = URI("https://api.bitbucket.org/2.0/users/#{@username}")
35
+ @my_uuid ||= fetch_json(uri)[:uuid]
36
+ end
37
+
33
38
  def pull_request(*)
34
39
  fetch_pr_json
35
40
  end
@@ -39,9 +44,16 @@ module Danger
39
44
  fetch_json(uri)
40
45
  end
41
46
 
42
- def fetch_last_comments
43
- uri = URI("#{pr_api_endpoint}/activity?limit=1000")
44
- fetch_json(uri)[:values].select { |v| v[:comment] }.map { |v| v[:comment] }
47
+ def fetch_comments
48
+ values = []
49
+ # TODO: use a url parts encoder to encode the query
50
+ uri = "#{pr_api_endpoint}/comments?pagelen=100&q=deleted+%7E+false+AND+user.username+%7E+%22#{@username}%22"
51
+ while(uri)
52
+ json = fetch_json(URI(uri))
53
+ values += json[:values]
54
+ uri = json[:next]
55
+ values
56
+ end
45
57
  end
46
58
 
47
59
  def delete_comment(id)
@@ -49,14 +61,16 @@ module Danger
49
61
  delete(uri)
50
62
  end
51
63
 
52
- def post_comment(text)
64
+ def post_comment(text, file: nil, line: nil)
53
65
  uri = URI("#{pr_api_endpoint}/comments")
54
66
  body = {
55
- content: {
67
+ content: {
56
68
  raw: text
57
69
  }
58
- }.to_json
59
- post(uri, body)
70
+ }
71
+ body.merge!(inline: { path: file, to: line }) if file && line
72
+
73
+ post(uri, body.to_json)
60
74
  end
61
75
 
62
76
  private
@@ -83,15 +97,15 @@ module Danger
83
97
  oauth_secret = environment["DANGER_BITBUCKETCLOUD_OAUTH_SECRET"]
84
98
  return nil if oauth_key.nil?
85
99
  return nil if oauth_secret.nil?
86
-
100
+
87
101
  uri = URI.parse("https://bitbucket.org/site/oauth2/access_token")
88
102
  req = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
89
103
  req.basic_auth oauth_key, oauth_secret
90
104
  req.set_form_data({'grant_type' => 'client_credentials'})
91
105
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
92
- http.request(req)
106
+ http.request(req)
93
107
  end
94
-
108
+
95
109
  JSON.parse(res.body, symbolize_names: true)[:access_token]
96
110
  end
97
111
 
@@ -129,13 +143,13 @@ module Danger
129
143
 
130
144
  def delete(uri)
131
145
  raise credentials_not_available unless credentials_given?
132
-
146
+
133
147
  req = Net::HTTP::Delete.new(uri.request_uri, { "Content-Type" => "application/json" })
134
148
  if access_token.nil?
135
149
  req.basic_auth @username, @password
136
150
  else
137
151
  req["Authorization"] = "Bearer #{access_token}"
138
- end
152
+ end
139
153
  Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
140
154
  http.request(req)
141
155
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "6.2.0".freeze
2
+ VERSION = "6.2.1".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: 6.2.0
4
+ version: 6.2.1
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: 2020-01-22 00:00:00.000000000 Z
12
+ date: 2020-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.5'
48
+ version: '1.6'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.5'
55
+ version: '1.6'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: colored2
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -248,6 +248,7 @@ files:
248
248
  - lib/danger/commands/runner.rb
249
249
  - lib/danger/commands/systems.rb
250
250
  - lib/danger/comment_generators/bitbucket_server.md.erb
251
+ - lib/danger/comment_generators/bitbucket_server_inline.md.erb
251
252
  - lib/danger/comment_generators/github.md.erb
252
253
  - lib/danger/comment_generators/github_inline.md.erb
253
254
  - lib/danger/comment_generators/gitlab.md.erb
@@ -319,8 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
319
320
  - !ruby/object:Gem::Version
320
321
  version: '0'
321
322
  requirements: []
322
- rubyforge_project:
323
- rubygems_version: 2.7.6.2
323
+ rubygems_version: 3.1.2
324
324
  signing_key:
325
325
  specification_version: 4
326
326
  summary: Like Unit Tests, but for your Team Culture.