Skip to content

Commit

Permalink
feat: 🎸 allow to specify the level of the fail message
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavotr committed Oct 17, 2023
1 parent 8c90ed0 commit 98dff7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/clients/jira-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class JiraIssue {
) {}

toString(): string {
return `${this.key} | ${this.type} | ${this.title}`;
let issue = `${this.key} | ${this.type} | ${this.title}`;
if (this.fixVersions?.length) {
issue += `\nFix versions: ${this.fixVersions.join(" ")}`;
}
return issue;
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Provides dev-time type structures for `danger` - doesn't affect runtime.
import { DangerDSLType } from "../node_modules/danger/distribution/dsl/DangerDSL";
import { JiraClient } from "./clients/jira-client";
declare const danger: DangerDSLType;
Expand All @@ -15,34 +14,35 @@ export default async function jiraPrValidation(
username: string,
token: string,
projectKey: string,
level: "fail" | "warn" = "fail",
) {
// Replace this with the code from your Dangerfile
const title = danger.github.pr.title;
const base = danger.github.pr.base.ref;
const head = danger.github.pr.head.ref;
message(`PR Title: ${title}`);
message(`PR Base: ${base}`);
message(`PR Head: ${head}`);

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

const jiraKey = jiraClient.extractJiraKey(head);

message("jiraKey " + jiraKey);
if (!jiraKey) {
warn("⚠️ No Jira key found in branch name, exiting");
return;
}

const jiraIssue = await jiraClient.getIssue(jiraKey);
message("jiraIssue " + jiraIssue);
if (!jiraIssue) {
warn("⚠️ Could not get issue, exiting");
return;
}

if (fixVersionsMatchesBranch(base, jiraIssue.fixVersions)) {
fail("🚨 Base branch doesn't match Jira fixVersion");
message("Jira issue: " + jiraIssue);

if (!fixVersionsMatchesBranch(base, jiraIssue.fixVersions)) {
const message = "🚨 Base branch doesn't match Jira fixVersion";
if (level === "warn") {
warn(message);
} else {
fail(message);
}
}
}

Expand Down

0 comments on commit 98dff7e

Please sign in to comment.