-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for workflow_dispatch event (#51)
* feat: support workflow dispatch trigger * feat: return json instead of text in fetch * feat: add PR_NUMBER to inputs * chore: add logging for troubleshooting * fix: wrong headers on get PR * chore: remove some logs * chore: update logs again * fix: broken url formatting * chore: build fix to url * chore: remove logs and cleanup * docs: add workflow docs to readme file * chore: change back to v1 lockfile * feat: use octokit instead of node-fetch * chore: retur error if no PR number is present * chore: finish unfinished error message * chore: update dist from build * chore: add better conditionals and checks for user input * chore: consolidate getter for PR * fix: add missing await keyword * chore: reduce logic and update pull request function * chroe: update pr number check logic * chore: test output * chore: log more output * chore: remove output logging and change PR number checks * chore: test PR number input * chore: log additional data * chore: use proper condition for check for PR * Update README.md Co-authored-by: Simone Busoli <[email protected]> * docs: update parameter for pr number Co-authored-by: Simone Busoli <[email protected]> Co-authored-by: Simone Busoli <[email protected]>
- Loading branch information
Showing
6 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,9 @@ _Optional_ A flag to only auto-merge updates based on Semantic Versioning. Defau | |
|
||
For more details on how semantic version difference calculated please see [semver](https://www.npmjs.com/package/semver) package | ||
|
||
### `pr-number` | ||
|
||
_Optional_ A pull request number, only required if triggered from a workflow_dispatch event. Typically this would be triggered by a script running in a seperate CI provider. See [Trigger action from workflow_dispatch event](#trigger-action-from-workflow_dispatch-event) | ||
|
||
## Example usage | ||
|
||
|
@@ -89,6 +92,42 @@ steps: | |
approve-only: true | ||
``` | ||
### Trigger action from workflow_dispatch event | ||
If you need to trigger this action manually, you can use the [workflow_dispatch](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event. A use case might be that your CI runs on a seperate provider, so you would like to run this action as a result of a successful CI run. | ||
When using the `workflow_dispatch` approach, you will need to send the PR number as part of the input for this action: | ||
|
||
```yml | ||
name: automerge | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
pr-number: | ||
required: true | ||
jobs: | ||
automerge: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: fastify/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
pr-number: ${{ github.event.inputs.pr-number }} | ||
``` | ||
|
||
You can initiate a call to trigger this event via [API](https://docs.github.com/en/rest/reference/actions/#create-a-workflow-dispatch-event): | ||
|
||
```bash | ||
# Note: replace dynamic values with your relevant data | ||
curl -X POST \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: token {token}" \ | ||
https://api.github.com/repos/{owner}/{reponame}/actions/workflows/{workflow}/dispatches \ | ||
-d '{"ref":"{ref}", "inputs":{ "pr-number": "{number}"}}' | ||
``` | ||
|
||
## Notes | ||
|
||
- A GitHub token is automatically provided by Github Actions, which can be accessed using `secrets.GITHUB_TOKEN` and supplied to the action as an input `github-token`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const github = require('@actions/github') | ||
|
||
const getPullRequest = async ({ pullRequestNumber, githubToken }) => { | ||
const payload = github.context.payload | ||
const octokit = github.getOctokit(githubToken) | ||
|
||
const repo = payload.repository | ||
const owner = repo.owner.login | ||
const repoName = repo.name | ||
|
||
const { data: pullRequest } = await octokit.rest.pulls.get({ | ||
owner, | ||
repo: repoName, | ||
pull_number: pullRequestNumber, | ||
}) | ||
|
||
return pullRequest | ||
} | ||
|
||
module.exports = getPullRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters