danger-jira 0.4.0 → 0.4.1

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
2
  SHA1:
3
- metadata.gz: 349f7574894426c9a762617ccdbd993a48e03158
4
- data.tar.gz: bea55cf6f864564a26502f4ef8416005c35810ab
3
+ metadata.gz: 80a48c0714244892fd4a261ccc9e488f4cf5111f
4
+ data.tar.gz: bed4700e427eda5556c26dd69631ee1e0c8f2492
5
5
  SHA512:
6
- metadata.gz: 85fcb10b043ba8bd3411092c207ca83547f81d41335c61b8248f6ffceb0005c21f840ced3c1f10bb3cc29bdc17856cb2161005191f0ab45f148031ea54507563
7
- data.tar.gz: 4e8f2b814fcf5a52b76dde8066e94225f3315ad9c35a2e2dd2c8e23a9d2c5523e296e637efef526e40547cf8ced22c402cdb8b55ce444da65c3877020f071c7d
6
+ metadata.gz: 52f36a30ef82ea8b9445944e2bb308020e60d58b1139b329693eceec99b2687e3276daadb867881fabd38e5872659b8fb4740719f3da01dc1f0b06ad66b9888b
7
+ data.tar.gz: e15f44b307f2060e1f4830544b31013559f831d93ac23513cb05c35f051da7ae6bd7e0f158b761de5601687187a9e470249258b5c1d48e24a27e9693ab0cd74e
data/README.md CHANGED
@@ -20,7 +20,10 @@ gem 'danger-jira'
20
20
  jira.check(
21
21
  key: ["KEY", "PM"],
22
22
  url: "https://myjira.atlassian.net/browse",
23
- fail_on_warning: true
23
+ search_title: true,
24
+ search_commits: false,
25
+ fail_on_warning: false,
26
+ report_missing: true
24
27
  )
25
28
  ```
26
29
 
@@ -42,7 +45,7 @@ With "KEY-123" in the PR title or PR body, Danger will comment with:
42
45
 
43
46
 
44
47
  <p align="right">
45
- Generated by :no_entry_sign: <a href="http://github.com/danger/danger-js/">dangerJS</a>
48
+ Generated by :no_entry_sign: <a href="http://github.com/danger/danger/">Danger</a>
46
49
  </p>
47
50
 
48
51
  ## License
@@ -1,3 +1,3 @@
1
1
  module Jira
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
@@ -38,6 +38,28 @@ module Danger
38
38
  throw Error("'key' missing - must supply JIRA issue key") if key.nil?
39
39
  throw Error("'url' missing - must supply JIRA installation URL") if url.nil?
40
40
 
41
+ jira_issues = find_jira_issues(
42
+ key: key,
43
+ search_title: search_title,
44
+ search_commits: search_commits
45
+ )
46
+
47
+ if !jira_issues.empty?
48
+ jira_urls = jira_issues.map { |issue| link(href: ensure_url_ends_with_slash(url), issue: issue) }.join(", ")
49
+ message("#{emoji} #{jira_urls}")
50
+ elsif report_missing
51
+ msg = "This PR does not contain any JIRA issue keys in the PR title or commit messages (e.g. KEY-123)"
52
+ if fail_on_warning
53
+ fail(msg)
54
+ else
55
+ warn(msg)
56
+ end
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def find_jira_issues(key: nil, search_title: true, search_commits: false)
41
63
  # Support multiple JIRA projects
42
64
  keys = key.kind_of?(Array) ? key.join("|") : key
43
65
  jira_key_regex_string = "((?:#{keys})-[0-9]+)"
@@ -46,35 +68,27 @@ module Danger
46
68
  jira_issues = []
47
69
 
48
70
  if search_title
49
- jira_issues << github.pr_title.scan(regexp)
71
+ github.pr_title.gsub(regexp) do |match|
72
+ jira_issues << match
73
+ end
50
74
  end
75
+
51
76
  if search_commits
52
- jira_issues << git.commits.map { |commit| commit.message.scan(regexp) }.compact
77
+ git.commits.map do |commit|
78
+ commit.message.gsub(regexp) do |match|
79
+ jira_issues << match
80
+ end
81
+ end
53
82
  end
54
83
 
55
- jira_issues.flatten.uniq
56
-
57
84
  if jira_issues.empty?
58
85
  github.pr_body.gsub(regexp) do |match|
59
86
  jira_issues << match
60
87
  end
61
88
  end
62
-
63
- if !jira_issues.empty?
64
- jira_urls = jira_issues.map { |issue| link(href: ensure_url_ends_with_slash(url), issue: issue) }.join(", ")
65
- message("#{emoji} #{jira_urls}")
66
- elsif report_missing
67
- msg = "This PR does not contain any JIRA issue keys in the PR title or commit messages (e.g. KEY-123)"
68
- if fail_on_warning
69
- fail(msg)
70
- else
71
- warn(msg)
72
- end
73
- end
89
+ return jira_issues
74
90
  end
75
91
 
76
- private
77
-
78
92
  def ensure_url_ends_with_slash(url)
79
93
  return "#{url}/" unless url.end_with?("/")
80
94
  return url
@@ -11,10 +11,41 @@ module Danger
11
11
  #
12
12
  describe "with Dangerfile" do
13
13
  before do
14
+ @jira = testing_dangerfile.jira
15
+ DangerJira.send(:public, *DangerJira.private_instance_methods)
16
+ github = Danger::RequestSources::GitHub.new({}, testing_env)
14
17
  end
15
18
 
16
- # Some examples for writing tests
17
- # You should replace these with your own.
19
+ it "can find jira issues via title" do
20
+ allow(@jira).to receive_message_chain("github.pr_title").and_return("Ticket [WEB-123] and WEB-124")
21
+ issues = @jira.find_jira_issues(key: "WEB")
22
+ expect((issues <=> ["WEB-123", "WEB-124"]) == 0)
23
+ end
24
+
25
+ it "can find jira issues in commits" do
26
+ single_commit = Object.new
27
+ def single_commit.message
28
+ "WIP [WEB-125]"
29
+ end
30
+ commits = [single_commit]
31
+ allow(@jira).to receive_message_chain("git.commits").and_return(commits)
32
+ issues = @jira.find_jira_issues(
33
+ key: "WEB",
34
+ search_title: false,
35
+ search_commits: true
36
+ )
37
+ expect((issues <=> ["WEB-125"]) == 0)
38
+ end
39
+
40
+ it "can find jira issues in pr body" do
41
+ allow(@jira).to receive_message_chain("github.pr_body").and_return("[WEB-126]")
42
+ issues = @jira.find_jira_issues(
43
+ key: "WEB",
44
+ search_title: false,
45
+ search_commits: false
46
+ )
47
+ expect((issues <=> ["WEB-126"]) == 0)
48
+ end
18
49
  end
19
50
  end
20
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-jira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - RestlessThinker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-26 00:00:00.000000000 Z
11
+ date: 2018-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api