Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/webpack-5.76.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrotule authored Jun 3, 2024
2 parents 522b21c + 0196973 commit 642e37b
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 11 deletions.
1 change: 1 addition & 0 deletions .node-version
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.2
20.11.1
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Jira pull-request Github action

If the branch name of the current pull request starts with a Jira ticket:
If the branch name of the current pull request or the title starts with a Jira ticket:

- It adds the ticket number to the PR title
- It adds the Jira link to the PR description
- It also adds a preview link to the PR description if provided as `preview-link` input

If the branch name does not start with a Jira ticket:
If the branch name and the PR title does not start with a Jira ticket:

- The workflow will fail

Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:

steps:
- name: Add Jira ticket to PR title / add links to PR description
uses: onrunning/jira-pr-action@v1
uses: onrunning/jira-pr-action@v2
with:
jira-account: account-name
ticket-regex: ^A1C-\\d+
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ inputs:
description: Preview link to add to PR description (i.e. https://preview.example.com)
required: false
runs:
using: node16
using: node20
main: dist/index.js
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "jest"
},
"engines": {
"node": "16.13.2",
"node": "20.11.1",
"yarn": ">=1.22.5"
},
"dependencies": {
Expand Down
136 changes: 134 additions & 2 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,138 @@ describe('#pull-request', () => {
})
})

describe('when title includes Jira ticket', () => {
describe('and when PR update request is successful', () => {
describe('and when PR description already includes preview/Jira links', () => {
describe('and when links are changing', () => {
beforeAll(async () => {
jest.resetModules()
jest.resetAllMocks()
ticket = 'A1C-1234'
preview = 'https://preview-123.example.com'
const options = {
branch: `some-feature`,
preview,
updateStatus: HTTP_STATUS_SUCCESS,
prBody: '**[Preview](foo-bar.com)**\n**[Jira ticket](jira.com)**\n\nMore details',
prTitle: `${ticket} - some-feature`,
}
;({ setFailedSpy, errorSpy, prUpdateSpy } = await mockContext(options))
await import('.')
})

it('does not set failed status', () => {
expect(setFailedSpy).not.toHaveBeenCalled()
expect(errorSpy).not.toHaveBeenCalled()
})

it('updates the current links in description', () => {
expect(prUpdateSpy).toHaveBeenCalledWith({
...DEFAULT_REQUEST_OPTIONS,
body:
`**[Preview](${preview})**\n` +
`**[Jira ticket](https://account.atlassian.net/browse/${ticket})**\n\nMore details`,
})
})
})

describe('and when links are not changing', () => {
describe('and when PR title already includes Jira ticket', () => {
beforeAll(async () => {
jest.resetModules()
jest.resetAllMocks()
ticket = 'A1C-1234'
preview = 'preview-123'
const options = {
branch: `${ticket}-some-feature`,
preview,
updateStatus: HTTP_STATUS_SUCCESS,
prTitle: `${ticket} - Some feature`,
prBody:
`**[Preview](${preview})**\n` +
`**[Jira ticket](https://account.atlassian.net/browse/${ticket})**\n\nMore details`,
}
;({ setFailedSpy, errorSpy, prUpdateSpy } = await mockContext(options))
await import('.')
})

it('does not set failed status', () => {
expect(setFailedSpy).not.toHaveBeenCalled()
expect(errorSpy).not.toHaveBeenCalled()
})

it('does not update PR', () => {
expect(prUpdateSpy).not.toHaveBeenCalled()
})
})
})
})

describe('and when PR description does not include preview/Jira links yet', () => {
beforeAll(async () => {
jest.resetModules()
jest.resetAllMocks()
ticket = 'A1C-1234'
preview = 'preview-123'
const options = {
branch: `${ticket}-some-feature`,
preview,
updateStatus: HTTP_STATUS_SUCCESS,
}
;({ setFailedSpy, errorSpy, prUpdateSpy } = await mockContext(options))
await import('.')
})

it('does not set failed status', () => {
expect(setFailedSpy).not.toHaveBeenCalled()
expect(errorSpy).not.toHaveBeenCalled()
})

it('updates PR title and description', () => {
expect(prUpdateSpy).toHaveBeenCalledWith({
...DEFAULT_REQUEST_OPTIONS,
title: `${ticket} - title`,
body:
`**[Preview](${preview})**\n` +
`**[Jira ticket](https://account.atlassian.net/browse/${ticket})**\n\nbody`,
})
})
})
})

describe('and when PR update request fails', () => {
beforeAll(async () => {
jest.resetModules()
jest.resetAllMocks()
ticket = 'A1C-1234'
preview = 'preview-123'
const options = {
branch: `${ticket}-some-feature`,
preview,
updateStatus: HTTP_STATUS_ERROR,
}
;({ errorSpy, prUpdateSpy } = await mockContext(options))
await import('.')
})

it('tries to update PR title and description', () => {
expect(prUpdateSpy).toHaveBeenCalledWith({
...DEFAULT_REQUEST_OPTIONS,
title: `${ticket} - title`,
body:
`**[Preview](${preview})**\n` +
`**[Jira ticket](https://account.atlassian.net/browse/${ticket})**\n\nbody`,
})
})

it('sets error status', () => {
expect(errorSpy).toHaveBeenCalledWith(
`Updating the pull request has failed with ${HTTP_STATUS_ERROR}`
)
})
})
})

describe('when current branch does not include Jira ticket', () => {
describe('and when exception-regex input does not match current branch', () => {
beforeAll(async () => {
Expand All @@ -309,7 +441,7 @@ describe('#pull-request', () => {

it('sets failed status', () => {
expect(setFailedSpy).toHaveBeenCalledWith(
expect.stringContaining('branch name does not start with a Jira ticket')
expect.stringContaining('Neither current branch nor title start with a Jira ticket')
)
})

Expand Down Expand Up @@ -466,7 +598,7 @@ describe('#pull-request', () => {

it('sets failed status', () => {
expect(setFailedSpy).toHaveBeenCalledWith(
expect.stringContaining('branch name does not start with a Jira ticket')
expect.stringContaining('Neither current branch nor title start with a Jira ticket')
)
})

Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ async function run(): Promise<void> {

let ticketLine = ''
const headBranch = context.payload.pull_request.head.ref
const [ticketInBranch] = headBranch.match(ticketRegex) || []
const [ticketInBranch] =
headBranch.match(ticketRegex) || context.payload.pull_request.title.match(ticketRegex) || []

if (ticketInBranch) {
const jiraLink = `https://${jiraAccount}.atlassian.net/browse/${ticketInBranch}`
Expand All @@ -78,7 +79,7 @@ async function run(): Promise<void> {

if (!isException) {
const regexStr = ticketRegex.toString()
core.setFailed(`The current branch name does not start with a Jira ticket ${regexStr}.`)
core.setFailed(`Neither current branch nor title start with a Jira ticket ${regexStr}.`)
}
}
if (prPreviewLine || ticketLine) {
Expand Down

0 comments on commit 642e37b

Please sign in to comment.