From 98dff7e45db0c278d8ba59a22acc09b30d7fb5db Mon Sep 17 00:00:00 2001 From: "Gustavo T. Rudiger" Date: Tue, 17 Oct 2023 15:04:29 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20allow=20to=20specify=20t?= =?UTF-8?q?he=20level=20of=20the=20fail=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/jira-client.ts | 6 +++++- src/index.ts | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/clients/jira-client.ts b/src/clients/jira-client.ts index f0d7fd7..31129c3 100644 --- a/src/clients/jira-client.ts +++ b/src/clients/jira-client.ts @@ -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; } } diff --git a/src/index.ts b/src/index.ts index fb861dd..63c5a7d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; @@ -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); + } } }