Skip to content

Commit

Permalink
fix: do not move issue to column if none is provided (#203)
Browse files Browse the repository at this point in the history
Closes #200
  • Loading branch information
scottmries authored Oct 31, 2024
2 parents 2154c49 + ec779e0 commit be80cd6
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 35 deletions.
14 changes: 7 additions & 7 deletions .github/actions/label-and-move-released-issues-v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ This action labels and moves issues that have been released.

## Inputs

| Name | Required | Description | Default |
| ---------------- | -------- | -------------------------------------------------------------------- | -------- |
| `commit-list` | Yes | The list of commits generated from the "Generate commit list" action | NA |
| `version` | Yes | The version number of the release | NA |
| `token` | Yes | The GitHub token with the required permissions (see below) | NA |
| `project-number` | No | The project number of the project board | 186 |
| `column-name` | No | Name of column to move to | released |
| Name | Required | Description | Default |
| ---------------- | -------- | -------------------------------------------------------------------- | ------- |
| `commit-list` | Yes | The list of commits generated from the "Generate commit list" action | NA |
| `version` | Yes | The version number of the release | NA |
| `token` | Yes | The GitHub token with the required permissions (see below) | NA |
| `project-number` | No | The project number of the project board | 186 |
| `column-name` | No | Name of column to move to, if one is provided | `''` |

## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inputs:
column-name:
description: 'Name of column to move to'
required: false
default: 'released'
default: ''
runs:
using: 'node20'
main: 'dist/index.js'
32 changes: 20 additions & 12 deletions .github/actions/label-and-move-released-issues-v1/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30671,10 +30671,13 @@ async function run(core, github) {
(0, getProjectBoardFieldList_1.default)({ projectNumber, owner })
]);
const statusField = fields.find(field => field.name.toLowerCase() === 'status');
const column = statusField.options.find(option => option.name.toLowerCase() === releaseColumn);
if (!column) {
core.setFailed(`\nColumn ${releaseColumn} not found in project board ${projectNumber}`);
return;
let column;
if (releaseColumn) {
column = statusField.options.find(option => option.name.toLowerCase() === releaseColumn);
if (!column) {
core.setFailed(`\nColumn ${releaseColumn} not found in project board ${projectNumber}`);
return;
}
}
const LABEL = `VERSION: ${repo}@${version}`;
let issueOwner;
Expand Down Expand Up @@ -30773,14 +30776,19 @@ async function run(core, github) {
issueUrl: issueURL
});
core.info(`\nReceived issue card ID ${issueCardID}`);
core.info(`\nMoving issue card ${issueCardID} to column ${releaseColumn}`);
await (0, moveIssueToColumn_1.default)({
issueCardID,
fieldID: statusField.id,
fieldColumnID: column.id,
projectID: projectBoardID
});
core.info(`\nSuccessfully moved issue card ${issueCardID}`);
if (column) {
core.info(`\nMoving issue card ${issueCardID} to column ${releaseColumn}`);
await (0, moveIssueToColumn_1.default)({
issueCardID,
fieldID: statusField.id,
fieldColumnID: column.id,
projectID: projectBoardID
});
core.info(`\nSuccessfully moved issue card ${issueCardID}`);
}
else {
core.info(`\nNot moving issue card. No column name provided.`);
}
}
}
catch (error) {
Expand Down
88 changes: 88 additions & 0 deletions .github/actions/label-and-move-released-issues-v1/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,94 @@ describe('run', () => {
})
})

describe('when the release column is not provided', () => {
it('should not move the issue', async () => {
generateInputs({ releaseColumn: '' })

// getProjectBoardID Stub
getExecOutput.onFirstCall().resolves({
stdout: JSON.stringify(MOCK_PROJECT_BOARD_ID)
})
// getProjectBoardFieldList Stub
getExecOutput.onSecondCall().resolves({
stdout: JSON.stringify(MOCK_FIELD_LIST)
})

// addIssueToBoard Stub
getExecOutput.onThirdCall().resolves({
stdout: JSON.stringify({
id: '123'
})
})

const core = {
getInput,
setFailed,
info
}

const github = {
context: {
repo: {
owner: 'owner',
repo: 'repo'
}
},
getOctokit: () => {
return {
...octokit,
rest: {
issues: {
listLabelsForRepo: listLabelsForRepoStub.resolves({
data: [MOCK_LIST_LABELS],
status: 200
} as unknown as Endpoints['GET /repos/{owner}/{repo}/labels']['response']),
createLabel: createLabelStub.resolves({
data: MOCK_CREATED_LABEL
} as unknown as Endpoints['POST /repos/{owner}/{repo}/labels']['response']),
get: () => {
return {
data: {
html_url: 'https://github.com/owner/repo/issues/1',
state: 'open'
},
status: 200
}
},
update: () => {
return {
data: {},
status: 200
}
},
addLabels: addLabelsStub.resolves({
data: {
labels: [MOCK_CREATED_LABEL],
status: 200
}
} as unknown as Endpoints['POST /repos/{owner}/{repo}/issues/{issue_number}/labels']['response'])
}
}
}
}
}

const graphqlStub = sinon.stub(octokit, 'graphql')

// getReferencedClosedIssues 1st call
graphqlStub.onFirstCall().resolves(MOCK_REFERENCED_CLOSED_ISSUES)
// getIssueProjectInfo 1st call
graphqlStub.onSecondCall().resolves(MOCK_PROJECT_INFO)

await run(core as unknown as Core, github as unknown as GitHub)

assert.equal(getExecOutput.callCount, 3)
assert.isTrue(
info.calledWith(`\nNot moving issue card. No column name provided.`)
)
})
})

describe('given the required inputs', () => {
interface GenerateResponsesArgs {
referencedClosedIssues?: object
Expand Down
40 changes: 25 additions & 15 deletions .github/actions/label-and-move-released-issues-v1/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ export default async function run(core: Core, github: GitHub): Promise<void> {
field => field.name.toLowerCase() === 'status'
)!

const column = statusField.options.find(
option => option.name.toLowerCase() === releaseColumn
)
let column

if (!column) {
core.setFailed(
`\nColumn ${releaseColumn} not found in project board ${projectNumber}`
if (releaseColumn) {
column = statusField.options.find(
option => option.name.toLowerCase() === releaseColumn
)
return

if (!column) {
core.setFailed(
`\nColumn ${releaseColumn} not found in project board ${projectNumber}`
)
return
}
}

const LABEL = `VERSION: ${repo}@${version}`
Expand Down Expand Up @@ -198,16 +202,22 @@ export default async function run(core: Core, github: GitHub): Promise<void> {

core.info(`\nReceived issue card ID ${issueCardID}`)

core.info(`\nMoving issue card ${issueCardID} to column ${releaseColumn}`)
if (column) {
core.info(
`\nMoving issue card ${issueCardID} to column ${releaseColumn}`
)

await moveIssueToColumn({
issueCardID,
fieldID: statusField.id,
fieldColumnID: column.id,
projectID: projectBoardID
})
await moveIssueToColumn({
issueCardID,
fieldID: statusField.id,
fieldColumnID: column.id,
projectID: projectBoardID
})

core.info(`\nSuccessfully moved issue card ${issueCardID}`)
core.info(`\nSuccessfully moved issue card ${issueCardID}`)
} else {
core.info(`\nNot moving issue card. No column name provided.`)
}
}
} catch (error) {
core.setFailed((error as Error).message)
Expand Down

0 comments on commit be80cd6

Please sign in to comment.