Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions rules/common/__tests__/hasJiraID.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
jest.mock("danger", () => jest.fn())
import * as danger from "danger"
const dm = danger as any

import hasJiraID from "../hasJiraID"

const errorMessage =
"The title of this PR does not contain a JIRA ID. Please consider including one so that this work is linked to the correct JIRA ticket. Expected format: ABC-123"

beforeEach(() => {
dm.warn = jest.fn()
})

it("warns when PR title has no JIRA ID", () => {
dm.danger = { github: { pr: { title: "My awesome PR title" } } }

hasJiraID()
expect(dm.warn).toHaveBeenLastCalledWith(errorMessage)
})

describe("warns if PR title has jira id in the wrong format", () => {
it("[ABC-1234] ...", () => {
dm.danger = { github: { pr: { title: "[ABC-1234] My awesome PR title" } } }
hasJiraID()
expect(dm.warn).toHaveBeenLastCalledWith(errorMessage)
})

it("... (ABC-123)", () => {
dm.danger = { github: { pr: { title: "Awesome PR (ABC-123)" } } }
hasJiraID()
expect(dm.warn).toHaveBeenLastCalledWith(errorMessage)
})
})

describe("does not warn if title does have a JIRA ID in the correct format", () => {
it("ABC-123 ...", () => {
dm.danger = { github: { pr: { title: "ABC-123 - My awesome PR title" } } }
hasJiraID()
expect(dm.warn).not.toHaveBeenCalled()
})

it("AB-123 ...", () => {
dm.danger = { github: { pr: { title: "AB-123 - My awesome PR title" } } }
hasJiraID()
expect(dm.warn).not.toHaveBeenCalled()
})
})
15 changes: 15 additions & 0 deletions rules/common/hasJiraID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { danger, warn } from "danger"

const hasJiraID = () => {
const pr = danger.github.pr
const pattern = /^\w{2,4}-\d+/g
const found = pattern.test(pr.title)

if (!found) {
warn(
"The title of this PR does not contain a JIRA ID. Please consider including one so that this work is linked to the correct JIRA ticket. Expected format: ABC-123"
)
}
}

export default hasJiraID