Skip to content

Commit

Permalink
feat: support multiple JIRA issues in PR title
Browse files Browse the repository at this point in the history
closes #8
  • Loading branch information
macklinu committed Jun 2, 2017
1 parent 82c1b01 commit 86c01d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,17 @@ describe('jiraIssue()', () => {
':paperclip: <a href="https://jira.net/browse/ABC-123">ABC-123</a>',
)
})
it('supports multiple JIRA keys in PR title', () => {
global.danger = {
github: { pr: { title: '[ABC-123][ABC-456] Change some things' } },
}
jiraIssue({
key: 'ABC',
url: 'https://jira.net/browse',
})
expect(global.message).toHaveBeenCalledWith(
// tslint:disable-next-line:max-line-length
':link: <a href="https://jira.net/browse/ABC-123">ABC-123</a>, <a href="https://jira.net/browse/ABC-456">ABC-456</a>',
)
})
})
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ export default function jiraIssue(options: Options) {
throw Error(`'key' missing - must supply JIRA issue key`)
}

const jiraKeyRegex = new RegExp(`^.*(${key}-[0-9]+).*$`, 'g')
const match = jiraKeyRegex.exec(danger.github.pr.title)
if (match) {
const issue = match[1]
const jiraUrl = link(resolve(ensureUrlEndsWithSlash(url), issue), issue)
message(`${emoji} ${jiraUrl}`)
const jiraKeyRegex = new RegExp(`(${key}-[0-9]+)`, 'g')
let match
const jiraIssues = []
// tslint:disable-next-line:no-conditional-assignment
while ((match = jiraKeyRegex.exec(danger.github.pr.title)) != null) {
jiraIssues.push(match[0])
}
if (jiraIssues.length > 0) {
const jiraUrls = jiraIssues
.map((issue) => link(resolve(ensureUrlEndsWithSlash(url), issue), issue))
.join(', ')
message(`${emoji} ${jiraUrls}`)
} else {
warn(`Please add the JIRA issue key to the PR title (e.g. ${key}-123)`)
}
Expand Down

0 comments on commit 86c01d0

Please sign in to comment.