Add retry logic to handle GitHub API eventual consistency errors that
can occur after creating a new pull request. Follow-up API calls for
milestones, labels, assignees, and reviewers may fail with a 422
"Could not resolve to a node" error before the PR is fully propagated.
- Add generic `retryWithBackoff` helper in `src/utils.ts` with
exponential backoff (default 2 retries, starting at 1s delay)
- Wrap post-creation API calls in `src/github-helper.ts` with
`withRetryForNewPr()`, which only retries for newly created PRs
- Use `@octokit/request-error` `RequestError` type for precise error
matching (status 422 + "Could not resolve to a node" message)
- Add unit tests for `retryWithBackoff` covering success, retry,
exhaustion, and non-retryable error scenarios
- Update `dist/index.js` bundle and `package.json` dependencies
Add the retry plugin to automatically retry requests that fail with
server errors (5xx status codes). Configure the plugin to exclude 429
(rate limit) from retries since that is already handled by the
throttling plugin.
- Add @octokit/plugin-retry dependency
- Register retry plugin in Octokit client
- Export retryOptions with doNotRetry list excluding 429
- Apply retryOptions in GitHubHelper constructor
Wrap the git remote prune command in a try-catch block to prevent
the action from failing if the prune operation fails. Instead, log
a warning message and allow the action to continue.
Fixes edge cases where the prune command may fail on self-hosted
runners but shouldn't block the pull request creation workflow.
* fix: GitHub API not providing details for existing PRs in private repos (#4064)
* fix: extract fallback into func getPullNumber
---------
Co-authored-by: Noah Miller <mike@stealthwing.com>
* GitCommandManager: add a function to get a file's contents at a specific revision
* use showFileAtRef instead of readFileBase64
* Teach GitCommandManager.exec about an object of exec parameters so we can add more
* Encode the showFiletRef output as base64 out of the gate
* Fix missing async for function
* Use Buffer.concat to avoid issues with partial data streams
* formatting
---------
Co-authored-by: gustavderdrache <alex.ford@determinate.systems>
- [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md)
- [Examples](docs/examples.md)
- [Updating to v7](docs/updating.md)
- [Updating between versions](docs/updating.md)
- [Common issues](docs/common-issues.md)
## Usage
```yml
- uses:actions/checkout@v4
- uses:actions/checkout@v6
# Make changes to pull request here
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
```
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v7.x.x`
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v8.x.x`
### Workflow permissions
@@ -53,7 +53,7 @@ All inputs are **optional**. If not set, sensible defaults will be used.
| `token` | The token that the action will use to create and update the pull request. See [token](#token). | `GITHUB_TOKEN` |
| `branch-token` | The token that the action will use to create and update the branch. See [branch-token](#branch-token). | Defaults to the value of `token` |
| `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` |
| `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. If no paths are specified, all new and modified files are added. See [Add specific paths](#add-specific-paths). | |
| `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. See [Add specific paths](#add-specific-paths). | If no paths are specified, all new and modified files are added. |
| `commit-message` | The message to use when committing changes. See [commit-message](#commit-message). | `[create-pull-request] automated change` |
| `committer` | The committer name and email address in the format `Display Name <email@address.com>`. Defaults to the GitHub Actions bot user on github.com. | `github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>` |
| `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>` |
@@ -131,7 +131,7 @@ If you want branches to be deleted immediately on merge then you should use GitH
For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable.
```yml
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
env:
https_proxy:http://<proxy_address>:<port>
```
@@ -153,7 +153,7 @@ Note that in order to read the step outputs the action step must have an id.
```yml
- name:Create Pull Request
id:cpr
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
- name:Check outputs
if:${{ steps.cpr.outputs.pull-request-number }}
run:|
@@ -216,7 +216,7 @@ File changes that do not match one of the paths will be stashed and restored aft
```yml
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
with:
add-paths:|
*.java
@@ -230,7 +230,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
```yml
steps:
- uses:actions/checkout@v4
- uses:actions/checkout@v6
- name:Create commits
run:|
git config user.name 'Peter Evans'
@@ -243,7 +243,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
--`+o;constt=newUint8Array(o.length);for(letn=0;n<o.length;n++)t[n]=o.charCodeAt(n),this.boundaryChars[t[n]]=!0;this.boundary=t,this.lookbehind=newUint8Array(this.boundary.length+8),this.state=S.START_BOUNDARY}write(o){lett=0;constn=o.length;letE=this.index,{lookbehind:l,boundary:h,boundaryChars:H,index:e,state:a,flags:d}=this;constb=this.boundary.length,m=b-1,O=o.length;letr,P;constu=c(D=>{this[D+"Mark"]=t},"mark"),i=c(D=>{deletethis[D+"Mark"]},"clear"),T=c((D,p,_,N)=>{(p===void0||p!==_)&&this[D](N&&N.subarray(p,_))},"callback"),L=c((D,p)=>{const_=D+"Mark";_inthis&&(p?(T(D,this[_],t,o),deletethis[_]):(T(D,this[_],o.length,o),this[_]=0))},"dataCallback");for(t=0;t<n;t++)switch(r=o[t],a){caseS.START_BOUNDARY:if(e===h.length-2){if(r===HYPHEN)d|=F.LAST_BOUNDARY;elseif(r!==CR)return;e++;break}elseif(e-1===h.length-2){if(d&F.LAST_BOUNDARY&&r===HYPHEN)a=S.END,d=0;elseif(!(d&F.LAST_BOUNDARY)&&r===LF)e=0,T("onPartBegin"),a=S.HEADER_FIELD_START;elsereturn;break}r!==h[e+2]&&(e=-2),r===h[e+2]&&e++;break;caseS.HEADER_FIELD_START:a=S.HEADER_FIELD,u("onHeaderField"),e=0;caseS.HEADER_FIELD:if(r===CR){i("onHeaderField"),a=S.HEADERS_ALMOST_DONE;break}if(e++,r===HYPHEN)break;if(r===COLON){if(e===1)return;L("onHeaderField",!0),a=S.HEADER_VALUE_START;break}if(P=lower(r),P<A||P>Z)return;break;caseS.HEADER_VALUE_START:if(r===SPACE)break;u("onHeaderValue"),a=S.HEADER_VALUE;caseS.HEADER_VALUE:r===CR&&(L("onHeaderValue",!0),T("onHeaderEnd"),a=S.HEADER_VALUE_ALMOST_DONE);break;caseS.HEADER_VALUE_ALMOST_DONE:if(r!==LF)return;a=S.HEADER_FIELD_START;break;caseS.HEADERS_ALMOST_DONE:if(r!==LF)return;T("onHeadersEnd"),a=S.PART_DATA_START;break;caseS.PART_DATA_START:a=S.PART_DATA,u("onPartData");caseS.PART_DATA:if(E=e,e===0){for(t+=m;t<O&&!(o[t]inH);)t+=b;t-=m,r=o[t]}if(e<h.length)h[e]===r?(e===0&&L("onPartData",!0),e++):e=0;elseif(e===h.length)e++,r===CR?d|=F.PART_BOUNDARY:r===HYPHEN?d|=F.LAST_BOUNDARY:e=0;elseif(e-1===h.length)if(d&F.PART_BOUNDARY){if(e=0,r===LF){d&=~F.PART_BOUNDARY,T("onPartEnd"),T("onPartBegin"),a=S.HEADER_FIELD_START;break}}elsed&F.LAST_BOUNDARY&&r===HYPHEN?(T("onPartEnd"),a=S.END,d=0):e=0;if(e>0)l[e-1]=r;elseif(E>0){constD=newUint8Array(l.buffer,l.byteOffset,l.byteLength);T("onPartData",0,E,D),E=0,u("onPartData"),t--}break;caseS.END:break;default:thrownewError(`Unexpected state entered: ${a}`)}L("onHeaderField"),L("onHeaderValue"),L("onPartData"),this.index=e,this.state=a,this.flags=d}end(){if(this.state===S.HEADER_FIELD_START&&this.index===0||this.state===S.PART_DATA&&this.index===this.boundary.length)this.onPartEnd();elseif(this.state!==S.END)thrownewError("MultipartParser.end(): stream ended unexpectedly")}};c(g,"MultipartParser");letMultipartParser=g;function_fileName(R){consto=R.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);if(!o)return;constt=o[2]||o[3]||"";letn=t.slice(t.lastIndexOf("\\")+1);returnn=n.replace(/%22/g,'"'),n=n.replace(/&#(\d{4});/g,(E,l)=>String.fromCharCode(l)),n}c(_fileName,"_fileName");asyncfunctiontoFormData(R,o){if(!/multipart/i.test(o))thrownewTypeError("Failed to fetch");constt=o.match(/boundary=(?:"([^"]+)"|([^;]+))/i);if(!t)thrownewTypeError("no or bad content-type header, no multipart boundary");constn=newMultipartParser(t[1]||t[2]);letE,l,h,H,e,a;constd=[],b=newnode.FormData,m=c(i=>{h+=u.decode(i,{stream:!0})},"onPartData"),O=c(i=>{d.push(i)},"appendToFile"),r=c(()=>{consti=newnode.File(d,a,{type:e});b.append(H,i)},"appendFileToFormData"),P=c(()=>{b.append(H,h)},"appendEntryToFormData"),u=newTextDecoder("utf-8");u.decode(),n.onPartBegin=function(){n.onPartData=m,n.onPartEnd=P,E="",l="",h="",H="",e="",a=null,d.length=0},n.onHeaderField=function(i){E+=u.decode(i,{stream:!0})},n.onHeaderValue=function(i){l+=u.decode(i,{stream:!0})},n.onHeaderEnd=function(){if(l+=u.decode(),E=E.toLowerCase(),E==="content-disposition"){consti=l.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);i&&(H=i[2]||i[3]||""),a=_fileName(l),a&&(n.onPartData=O,n.onPartEnd=r)}elseE==="content-type"&&(e=l);l="",E=""};forawait(constiofR)n.write(i);returnn.end(),b}c(toFormData,"toFormData"),exports.toFormData=toFormData;
@@ -37,7 +37,7 @@ So the straightforward solution is to just not install them during the workflow
- If hooks are automatically enabled by a framework, use an option provided by the framework to disable them. For example, for Husky users, they can be disabled with the `--ignore-scripts` flag, or by setting the `HUSKY` environment variable when the action runs.
@@ -25,7 +25,7 @@ This document covers terminology, how the action works, general usage guidelines
## Terminology
[Pull requests](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#about-pull-requests) are proposed changes to a repository branch that can be reviewed by a repository's collaborators before being accepted or rejected.
[Pull requests](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#about-pull-requests) are proposed changes to a repository branch that can be reviewed by a repository's collaborators before being accepted or rejected.
A pull request references two branches:
@@ -40,7 +40,7 @@ For each [event type](https://docs.github.com/en/actions/reference/events-that-t
The default can be overridden by specifying a `ref` on checkout.
```yml
- uses:actions/checkout@v4
- uses:actions/checkout@v6
with:
ref:develop
```
@@ -77,7 +77,7 @@ jobs:
example:
runs-on:ubuntu-latest
steps:
- uses:actions/checkout@v4
- uses:actions/checkout@v6
```
There may be use cases where it makes sense to execute the workflow on a branch that is not the base of the pull request. In these cases, the base branch can be specified with the `base` action input. The action will attempt to rebase changes made during the workflow on to the actual base.
@@ -92,7 +92,7 @@ In these cases, you *must supply* the `base` input so the action can rebase chan
Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request) events will by default check out a merge commit. Set the `base` input as follows to base the new pull request on the current pull request's branch.
```yml
- uses:peter-evans/create-pull-request@v7
- uses:peter-evans/create-pull-request@v8
with:
base:${{ github.head_ref }}
```
@@ -100,7 +100,7 @@ Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/refer
Workflows triggered by [`release`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release) events will by default check out a tag. For most use cases, you will need to set the `base` input to the branch name of the tagged commit.
```yml
- uses:peter-evans/create-pull-request@v7
- uses:peter-evans/create-pull-request@v8
with:
base:main
```
@@ -150,7 +150,7 @@ There are a number of workarounds with different pros and cons.
- Use the default `GITHUB_TOKEN` and allow the action to create pull requests that have no checks enabled. Manually close pull requests and immediately reopen them. This will enable `on: pull_request` workflows to run and be added as checks. To prevent merging of pull requests without checks erroneously, use [branch protection rules](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests).
- Create draft pull requests by setting the `draft: always-true` input, and configure your workflow to trigger `on: ready_for_review`. The workflow will run when users manually click the "Ready for review" button on the draft pull requests. If the pull request is updated by the action, the `always-true` mode ensures that the pull request will be converted back to a draft.
- Create draft pull requests by setting the `draft: always-true` input, and configure your workflow to trigger `ready_for_review` in `on: pull_request`. The workflow will run when users manually click the "Ready for review" button on the draft pull requests. If the pull request is updated by the action, the `always-true` mode ensures that the pull request will be converted back to a draft.
- Use a [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) created on an account that has write access to the repository that pull requests are being created in. This is the standard workaround and [recommended by GitHub](https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow). It's advisable to use a dedicated [machine account](https://docs.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements) that has collaborator access to the repository, rather than creating a PAT on a personal user account. Also note that because the account that owns the PAT will be the creator of pull requests, that user account will be unable to perform actions such as request changes or approve the pull request.
@@ -179,14 +179,14 @@ This action uses [ncc](https://github.com/vercel/ncc) to compile the Node.js cod
Checking out a branch from a different repository from where the workflow is executing will make *that repository* the target for the created pull request. In this case, the `GITHUB_TOKEN` will not work and one of the other [token options](../README.md#token) must be used.
```yml
- uses:actions/checkout@v4
- uses:actions/checkout@v6
with:
token:${{ secrets.PAT }}
repository:owner/repo
# Make changes to pull request here
- uses:peter-evans/create-pull-request@v7
- uses:peter-evans/create-pull-request@v8
with:
token:${{ secrets.PAT }}
```
@@ -197,8 +197,9 @@ Checking out a branch from a different repository from where the workflow is exe
Allowing the action to push with a configured deploy key will trigger `on: push` workflows. This makes it an alternative to using a PAT to trigger checks for pull requests.
> [!NOTE]
> You cannot use deploy keys alone to [create a pull request in a remote repository](#creating-pull-requests-in-a-remote-repository) because then using a PAT would become a requirement.
> - You cannot use deploy keys alone to [create a pull request in a remote repository](#creating-pull-requests-in-a-remote-repository) because then using a PAT would become a requirement.
> This method only makes sense if creating a pull request in the repository where the workflow is running.
> - You cannot use deploy keys with [commit signature verification for bots](#commit-signature-verification-for-bots) (`sign-commits: true`).
How to use SSH (deploy keys) with create-pull-request action:
@@ -209,14 +210,14 @@ How to use SSH (deploy keys) with create-pull-request action:
```yml
steps:
- uses:actions/checkout@v4
- uses:actions/checkout@v6
with:
ssh-key:${{ secrets.SSH_PRIVATE_KEY }}
# Make changes to pull request here
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
```
### Push pull request branches to a fork
@@ -237,11 +238,11 @@ It will use their own fork to push code and create the pull request.
6. As shown in the following example workflow, set the `push-to-fork` input to the full repository name of the fork.
```yaml
- uses:actions/checkout@v4
- uses:actions/checkout@v6
# Make changes to pull request here
- uses:peter-evans/create-pull-request@v7
- uses:peter-evans/create-pull-request@v8
with:
token:${{ secrets.MACHINE_USER_PAT }}
push-to-fork:machine-user/fork-of-repository
@@ -271,7 +272,7 @@ The `token` input will then default to the repository's `GITHUB_TOKEN`, which wi
The following is an example of pushing to a fork using GitHub App tokens.
```yaml
- uses:actions/create-github-app-token@v1
- uses:actions/create-github-app-token@v2
id:generate-token
with:
app-id:${{ secrets.APP_ID }}
@@ -279,12 +280,12 @@ The following is an example of pushing to a fork using GitHub App tokens.
@@ -318,18 +319,18 @@ GitHub App generated tokens can be configured with fine-grained permissions and
```yaml
steps:
- uses:actions/create-github-app-token@v1
- uses:actions/create-github-app-token@v2
id:generate-token
with:
app-id:${{ secrets.APP_ID }}
private-key:${{ secrets.APP_PRIVATE_KEY }}
- uses:actions/checkout@v4
- uses:actions/checkout@v6
# Make changes to pull request here
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
with:
token:${{ steps.generate-token.outputs.token }}
```
@@ -341,7 +342,7 @@ For this case a token must be generated from the GitHub App installation of the
In the following example, a pull request is being created in remote repo `owner/repo`.
```yaml
steps:
- uses:actions/create-github-app-token@v1
- uses:actions/create-github-app-token@v2
id:generate-token
with:
app-id:${{ secrets.APP_ID }}
@@ -349,7 +350,7 @@ In the following example, a pull request is being created in remote repo `owner/
owner:owner
repositories:repo
- uses:actions/checkout@v4
- uses:actions/checkout@v6
with:
token:${{ steps.generate-token.outputs.token }}# necessary if the repo is private
repository:owner/repo
@@ -357,7 +358,7 @@ In the following example, a pull request is being created in remote repo `owner/
# Make changes to pull request here
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
with:
token:${{ steps.generate-token.outputs.token }}
```
@@ -373,7 +374,7 @@ The action supports two methods to sign commits, [commit signature verification
The action can sign commits as `github-actions[bot]` when using the repository's default `GITHUB_TOKEN`, or your own bot when using [GitHub App tokens](#authenticating-with-github-app-generated-tokens).
> [!IMPORTANT]
> [!IMPORTANT]
> - When setting `sign-commits: true` the action will ignore the `committer` and `author` inputs.
> - If you attempt to use a [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) the action will create the pull request, but commits will *not* be signed. Commit signing is only supported with bot generated tokens.
> - The GitHub API has a 40MiB limit when creating git blobs. An error will be raised if there are files in the pull request larger than this. If you hit this limit, use [GPG commit signature verification](#gpg-commit-signature-verification) instead.
@@ -381,12 +382,12 @@ The action can sign commits as `github-actions[bot]` when using the repository's
In this example the `token` input is not supplied, so the action will use the repository's default `GITHUB_TOKEN`. This will sign commits as `github-actions[bot]`.
```yaml
steps:
- uses:actions/checkout@v4
- uses:actions/checkout@v6
# Make changes to pull request here
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
with:
sign-commits:true
```
@@ -394,9 +395,9 @@ In this example the `token` input is not supplied, so the action will use the re
In this example, the `token` input is generated using a GitHub App. This will sign commits as `<application-name>[bot]`.
```yaml
steps:
- uses:actions/checkout@v4
- uses:actions/checkout@v6
- uses:actions/create-github-app-token@v1
- uses:actions/create-github-app-token@v2
id:generate-token
with:
app-id:${{ secrets.APP_ID }}
@@ -405,7 +406,7 @@ In this example, the `token` input is generated using a GitHub App. This will si
# Make changes to pull request here
- name:Create Pull Request
uses:peter-evans/create-pull-request@v7
uses:peter-evans/create-pull-request@v8
with:
token:${{ steps.generate-token.outputs.token }}
sign-commits:true
@@ -436,7 +437,7 @@ The action can use GPG to sign commits with a GPG key that you generate yourself
```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: crazy-max/ghaction-import-gpg@v5
with:
@@ -448,7 +449,7 @@ The action can use GPG to sign commits with a GPG key that you generate yourself
@@ -540,7 +540,7 @@ Note that the step where output variables are defined must have an id.
echo "pr_title=$pr_title" >> $GITHUB_OUTPUT
echo "pr_body=$pr_body" >> $GITHUB_OUTPUT
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
uses: peter-evans/create-pull-request@v8
with:
title: ${{ steps.vars.outputs.pr_title }}
body: ${{ steps.vars.outputs.pr_body }}
@@ -566,7 +566,7 @@ The template is rendered using the [render-template](https://github.com/chuhlomi
bar: that
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
uses: peter-evans/create-pull-request@v8
with:
body: ${{ steps.template.outputs.result }}
```
@@ -612,3 +612,30 @@ To enable step debug logging set the secret `ACTIONS_STEP_DEBUG` to `true` in th
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
```
### Show an annotation message for a created pull request
Showing an annotation message for a created or updated pull request allows you to confirm the pull request easily, such as by visiting the link. This can be achieved by adding a step that uses the [`notice` workflow command](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions?tool=bash#setting-a-notice-message).
In this example, when a pull request is created, you will be able to see the following message on an action run page (e.g., `/actions/runs/12812393039`):
```
https://github.com/peter-evans/create-pull-request/pull/1 was created.
- If using self-hosted runners or GitHub Enterprise Server, there are minimum requirements for `v8` to run. See "What's new" below for details.
### What's new
- Updated runtime to Node.js 24
- The action now requires a minimum version of [v2.327.1](https://github.com/actions/runner/releases/tag/v2.327.1) for the Actions runner. Update self-hosted runners to v2.327.1 or later to ensure compatibility.
thrownewError('Unexpected: retry loop exited without return or throw')
}
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.