File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ jiraIssue({
25
25
key: ' JIRA' ,
26
26
url: ' https://myjira.atlassian.net/browse' ,
27
27
emoji: ' :paperclip:' ,
28
+ format (emoji , jiraUrls ) { // Optional Formatter
29
+ return ' Some Custom Message' ;
30
+ }
28
31
})
29
32
```
30
33
Original file line number Diff line number Diff line change @@ -110,4 +110,19 @@ describe("jiraIssue()", () => {
110
110
':link: <a href="https://jira.net/browse/ABC-123">ABC-123</a>, <a href="https://jira.net/browse/DEF-456">DEF-456</a>'
111
111
) ;
112
112
} ) ;
113
+ it ( "supports a custom format function" , ( ) => {
114
+ global . danger = {
115
+ github : { pr : { title : "[ABC-123][DEF-456] Change some things" } }
116
+ } ;
117
+ jiraIssue ( {
118
+ format : ( emoji , jiraUrls ) => {
119
+ return `${ emoji } JIRA Tickets: ${ jiraUrls . join ( ", " ) } ` ;
120
+ } ,
121
+ key : [ "ABC" , "DEF" ] ,
122
+ url : "https://jira.net/browse"
123
+ } ) ;
124
+ expect ( global . message ) . toHaveBeenCalledWith (
125
+ ':link: JIRA Tickets: <a href="https://jira.net/browse/ABC-123">ABC-123</a>, <a href="https://jira.net/browse/DEF-456">DEF-456</a>'
126
+ ) ;
127
+ } ) ;
113
128
} ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,13 @@ export interface Options {
15
15
* Defaults to `':link:'`.
16
16
*/
17
17
emoji ?: string ;
18
+ /**
19
+ * A format function to format the message
20
+ * @param {string } emoji
21
+ * @param {string[] } jiraUrls
22
+ * @returns {string }
23
+ */
24
+ format ?: ( emoji : string , jiraUrls : string [ ] ) => string ;
18
25
}
19
26
20
27
const link = ( href : string , text : string ) : string =>
@@ -53,10 +60,16 @@ export default function jiraIssue(options: Options) {
53
60
jiraIssues . push ( match [ 0 ] ) ;
54
61
}
55
62
if ( jiraIssues . length > 0 ) {
56
- const jiraUrls = jiraIssues
57
- . map ( issue => link ( resolve ( ensureUrlEndsWithSlash ( url ) , issue ) , issue ) )
58
- . join ( ", " ) ;
59
- message ( `${ emoji } ${ jiraUrls } ` ) ;
63
+ const jiraUrls = jiraIssues . map ( issue =>
64
+ link ( resolve ( ensureUrlEndsWithSlash ( url ) , issue ) , issue )
65
+ ) ;
66
+
67
+ // use custom formatter, or default
68
+ if ( options . format ) {
69
+ message ( options . format ( emoji , jiraUrls ) ) ;
70
+ } else {
71
+ message ( `${ emoji } ${ jiraUrls . join ( ", " ) } ` ) ;
72
+ }
60
73
} else {
61
74
warn ( `Please add the JIRA issue key to the PR title (e.g. ${ key } -123)` ) ;
62
75
}
You can’t perform that action at this time.
0 commit comments