Skip to content

Commit

Permalink
Merge pull request #386 from peter-evans/close-reason
Browse files Browse the repository at this point in the history
Add support for issue closing reason
  • Loading branch information
peter-evans authored Aug 18, 2022
2 parents 6b9ae90 + 995bc4f commit 3dd5574
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
| `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` |
| `repository` | The GitHub repository containing the issue. | Current repository |
| `issue-number` | The number of the issue to close. | `github.event.issue.number` |
| `close-reason` | Reason for closing the issue; `completed` or `not_planned`. | `completed` |
| `comment` | A comment to make on the issue before closing. | |

### Accessing issues in other repositories
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ name: 'Close Issue'
description: 'A GitHub action to close an issue'
inputs:
token:
required: false
description: 'GitHub auth token'
default: ${{ github.token }}
repository:
required: false
description: 'The GitHub repository containing the issue'
default: ${{ github.repository }}
issue-number:
required: false
description: 'The number of the issue to close'
default: ${{ github.event.issue.number }}
close-reason:
required: false
description: 'Reason for closing the issue, "completed" or "not_planned"'
default: 'completed'
comment:
required: false
description: 'A comment to make on the issue before closing'
runs:
using: 'node16'
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function run() {
token: core.getInput('token'),
repository: core.getInput('repository'),
issueNumber: Number(core.getInput('issue-number')),
closeReason: core.getInput('close-reason'),
comment: core.getInput('comment')
};
core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`);
Expand All @@ -60,12 +61,13 @@ function run() {
body: inputs.comment
});
}
core.info('Closing the issue');
core.info('Closing the issue as ' + inputs.closeReason);
yield octokit.rest.issues.update({
owner: owner,
repo: repo,
issue_number: inputs.issueNumber,
state: 'closed'
state: 'closed',
state_reason: inputs.closeReason
});
}
catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ async function run(): Promise<void> {
token: core.getInput('token'),
repository: core.getInput('repository'),
issueNumber: Number(core.getInput('issue-number')),
closeReason: core.getInput('close-reason'),
comment: core.getInput('comment')
}
core.debug(`Inputs: ${inspect(inputs)}`)
Expand All @@ -27,12 +28,13 @@ async function run(): Promise<void> {
})
}

core.info('Closing the issue')
core.info('Closing the issue as ' + inputs.closeReason)
await octokit.rest.issues.update({
owner: owner,
repo: repo,
issue_number: inputs.issueNumber,
state: 'closed'
state: 'closed',
state_reason: inputs.closeReason
})
} catch (error: any) {
core.debug(inspect(error))
Expand Down

0 comments on commit 3dd5574

Please sign in to comment.