Skip to content

Commit 98dff7e

Browse files
committed
feat: 🎸 allow to specify the level of the fail message
1 parent 8c90ed0 commit 98dff7e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/clients/jira-client.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export class JiraIssue {
2121
) {}
2222

2323
toString(): string {
24-
return `${this.key} | ${this.type} | ${this.title}`;
24+
let issue = `${this.key} | ${this.type} | ${this.title}`;
25+
if (this.fixVersions?.length) {
26+
issue += `\nFix versions: ${this.fixVersions.join(" ")}`;
27+
}
28+
return issue;
2529
}
2630
}
2731

src/index.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Provides dev-time type structures for `danger` - doesn't affect runtime.
21
import { DangerDSLType } from "../node_modules/danger/distribution/dsl/DangerDSL";
32
import { JiraClient } from "./clients/jira-client";
43
declare const danger: DangerDSLType;
@@ -15,34 +14,35 @@ export default async function jiraPrValidation(
1514
username: string,
1615
token: string,
1716
projectKey: string,
17+
level: "fail" | "warn" = "fail",
1818
) {
19-
// Replace this with the code from your Dangerfile
20-
const title = danger.github.pr.title;
2119
const base = danger.github.pr.base.ref;
2220
const head = danger.github.pr.head.ref;
23-
message(`PR Title: ${title}`);
24-
message(`PR Base: ${base}`);
25-
message(`PR Head: ${head}`);
2621

2722
const jiraClient = new JiraClient(baseUrl, username, token, projectKey);
2823

2924
const jiraKey = jiraClient.extractJiraKey(head);
3025

31-
message("jiraKey " + jiraKey);
3226
if (!jiraKey) {
3327
warn("⚠️ No Jira key found in branch name, exiting");
3428
return;
3529
}
3630

3731
const jiraIssue = await jiraClient.getIssue(jiraKey);
38-
message("jiraIssue " + jiraIssue);
3932
if (!jiraIssue) {
4033
warn("⚠️ Could not get issue, exiting");
4134
return;
4235
}
4336

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+
}
4646
}
4747
}
4848

0 commit comments

Comments
 (0)