1
- // Provides dev-time type structures for `danger` - doesn't affect runtime.
2
1
import { DangerDSLType } from "../node_modules/danger/distribution/dsl/DangerDSL" ;
3
2
import { JiraClient } from "./clients/jira-client" ;
4
3
declare const danger : DangerDSLType ;
@@ -15,34 +14,35 @@ export default async function jiraPrValidation(
15
14
username : string ,
16
15
token : string ,
17
16
projectKey : string ,
17
+ level : "fail" | "warn" = "fail" ,
18
18
) {
19
- // Replace this with the code from your Dangerfile
20
- const title = danger . github . pr . title ;
21
19
const base = danger . github . pr . base . ref ;
22
20
const head = danger . github . pr . head . ref ;
23
- message ( `PR Title: ${ title } ` ) ;
24
- message ( `PR Base: ${ base } ` ) ;
25
- message ( `PR Head: ${ head } ` ) ;
26
21
27
22
const jiraClient = new JiraClient ( baseUrl , username , token , projectKey ) ;
28
23
29
24
const jiraKey = jiraClient . extractJiraKey ( head ) ;
30
25
31
- message ( "jiraKey " + jiraKey ) ;
32
26
if ( ! jiraKey ) {
33
27
warn ( "⚠️ No Jira key found in branch name, exiting" ) ;
34
28
return ;
35
29
}
36
30
37
31
const jiraIssue = await jiraClient . getIssue ( jiraKey ) ;
38
- message ( "jiraIssue " + jiraIssue ) ;
39
32
if ( ! jiraIssue ) {
40
33
warn ( "⚠️ Could not get issue, exiting" ) ;
41
34
return ;
42
35
}
43
36
44
- if ( fixVersionsMatchesBranch ( base , jiraIssue . fixVersions ) ) {
45
- fail ( "🚨 Base branch doesn't match Jira fixVersion" ) ;
37
+ message ( "Jira issue: " + jiraIssue ) ;
38
+
39
+ if ( ! fixVersionsMatchesBranch ( base , jiraIssue . fixVersions ) ) {
40
+ const message = "🚨 Base branch doesn't match Jira fixVersion" ;
41
+ if ( level === "warn" ) {
42
+ warn ( message ) ;
43
+ } else {
44
+ fail ( message ) ;
45
+ }
46
46
}
47
47
}
48
48
0 commit comments