Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRs fail to create due to Error: For same-org, cross-repo pulls, 'head_repo' is required: {"resource":"PullRequest","field":"head","code":"invalid"} #1459

Closed
davereid-pfg opened this issue Jan 4, 2023 · 52 comments

Comments

@davereid-pfg
Copy link

davereid-pfg commented Jan 4, 2023

Subject of the issue

I have a workflow that is pushing the branch but failing to create the pull request due to a new error, when the action has worked before:

      - name: Generate token using the Github App
        uses: tibdex/github-app-token@v1
        if: ${{ env.UPDATER_APP_ID && env.UPDATER_PRIVATE_KEY }}
        id: app-token
        with:
          app_id: ${{ env.UPDATER_APP_ID }}
          private_key: ${{ env.UPDATER_PRIVATE_KEY }}
      - name: Create pull request containing any changed files
        id: create-pull-request
        uses: peter-evans/create-pull-request@v3
        with:
          branch: scheduled-updater-changes
          base: ${{ github.base_ref || github.ref_name }}
          delete-branch: true
          token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
          title: Automatic dependency updates
          body: Rest of the body truncated, not important.

Steps to reproduce

Logs where the workflow fails:

Run peter-evans/create-pull-request@v3
  with:
    branch: scheduled-updater-changes
    base: main
    delete-branch: true
    token: ***
    title: Automatic dependency updates
    body: Rest of the body truncated, not important.
    add-paths: -A
  
    commit-message: [create-pull-request] automated change
    committer: GitHub <[email protected]>
    author: Reid-Dave_pfghub <[email protected]>
    signoff: false
    draft: false
...
Pushing pull request branch to 'origin/scheduled-updater-changes'
  /usr/bin/git push --force-with-lease origin HEAD:refs/heads/scheduled-updater-changes
  remote: 
  remote: Create a pull request for 'scheduled-updater-changes' on GitHub by visiting:        
  remote:      https://github.com/***/private-repo/pull/new/scheduled-updater-changes        
  remote: 
  To https://github.com/***/private-repo
   * [new branch]      HEAD -> scheduled-updater-changes
Create or update the pull request
  Attempting creation of pull request
  Error: For same-org, cross-repo pulls, 'head_repo' is required: {"resource":"PullRequest","field":"head","code":"invalid"}

I cannot link to the actual logs since it is a private repository.

The same exact workflow from Dec 22 succeeded:

Run peter-evans/create-pull-request@v3
  with:
    branch: scheduled-updater-changes
    base: main
    delete-branch: true
    token: ***
    title: Automatic dependency updates
    body: Rest of the body truncated, not important.
    add-paths: -A
  
    commit-message: [create-pull-request] automated change
    committer: GitHub <[email protected]>
    author: Reid-Dave_pfghub <[email protected]>
    signoff: false
    draft: false
...
Pushing pull request branch to 'origin/scheduled-updater-changes'
  /usr/bin/git push --force-with-lease origin HEAD:refs/heads/scheduled-updater-changes
  remote: 
  remote: Create a pull request for 'scheduled-updater-changes' on GitHub by visiting:        
  remote:      https://github.com/***/private-repo/pull/new/scheduled-updater-changes        
  remote: 
  To https://github.com/***/private-repo
   * [new branch]      HEAD -> scheduled-updater-changes
Create or update the pull request
  Attempting creation of pull request
  Created pull request #12 (***:scheduled-updater-changes => main)

I'm also not able to replicate this consistently. The same exact workflow works fine in another private repository, it seems to be this specific repository causing the issue.

@yktakaha4
Copy link

I just encountered the same error.
It occurred in the organization's private repository, so it could be a factor.

@chachasikes
Copy link

chachasikes commented Jan 5, 2023

Following

Similar issue - started 6-7 hours ago from the time of writing this message.
We are still getting this error.
This is the error we got in the build output:

DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

@chachasikes
Copy link

Didn't see any issues with GitHub Actions for today
https://www.githubstatus.com/

@peter-evans
Copy link
Owner

Thanks for the report. I'm looking into this.

There haven't been any changes to the action that I think could have caused this, so it's likely to be a change with GitHub's API.

@chachasikes The deprecation warning is unrelated. See #1336

@peter-evans

This comment was marked as outdated.

@jbum
Copy link

jbum commented Jan 5, 2023

Can confirm it's happening with v4 (I'm working with @chachasikes )

@quantumfusion
Copy link

I can confirm the problem is still there with v4. Also running in a private repo, I have consistently had the 'head_repo' is required error.
Relevant snippets from the run on the private repo:
From setup, confirms using latest published version of the action

Wed, 04 Jan 2023 23:58:40 GMT Download action repository 'peter-evans/create-pull-request@v4' (SHA:2b011faafdcbc9ceb11414d64d0573f37c774b04)

And the same error as mentioned in OP:

Thu, 05 Jan 2023 00:12:39 GMT
Create or update the pull request
Thu, 05 Jan 2023 00:12:39 GMT   Attempting creation of pull request
Thu, 05 Jan 2023 00:12:40 GMT   Error: For same-org, cross-repo pulls, 'head_repo' is required: {"resource":"PullRequest","field":"head","code":"invalid"}

The theory around it being an API seems plausible, our last working run was at Wed, 04 Jan 2023 21:30:52 GMT.

@peter-evans
Copy link
Owner

I've created a GitHub support ticket because I'm fairly sure this is a change to the API they have made. I don't know if it's intentional, but if it is the documentation is incorrect and there was no warning.

@peter-evans
Copy link
Owner

I'm unable to reproduce this issue. Please could you explain a bit more about your scenario.

  1. Are you creating a pull request remotely? (In a repo other than where the workflow is running)
  2. Is the repo where the workflow runs private?
  3. Is the remote repo private?
  4. What type of token are you using? What scopes?
  5. Are the repos in an org or user account?

@chachasikes
Copy link

@jbum & I reporting that our repo is public

@jbum
Copy link

jbum commented Jan 5, 2023

(Both repos are public, in an org account). Our first failure is here (a few hours before quantumfusion's last success): https://github.com/cagov/cannabis.ca.gov/actions/runs/3840800379

@peter-evans
Copy link
Owner

@jbum Thank you. So it looks like the repo for the workflow and where you are creating the pull request is the same. I wonder if the error is being caused because the workflow is triggered by repository_dispatch from a different repository. I noticed that your workflow also can be triggered manually by workflow_dispatch. Please could try manually running the workflow from the GitHub UI. If that works, then it could be a permissions change they have made to the GITHUB_TOKEN regarding being triggered from a different repo.

@jbum
Copy link

jbum commented Jan 5, 2023

Fwiw, I notice that the call right after "Attempting creation of pull request" is to octokit (which was updated some 7 hours ago, around the time the failures started for us?). We will try that thanks!

@jbum
Copy link

jbum commented Jan 5, 2023

The manual run also fails (tried it in a different public repo we've been testing on). https://github.com/cagov/odi-publishing-11ty-sandbox/actions/runs/3843544700

@peter-evans
Copy link
Owner

Fwiw, I notice that the call right after "Attempting creation of pull request" is to octokit (which was updated some 7 hours ago, around the time the failures started for us?). We will try that thanks!

Octokit is a library in use by the action. But you are using v4 of the action, the release of which hasn't changed since 28th November last year.
https://github.com/peter-evans/create-pull-request/releases/tag/v4

@jbum
Copy link

jbum commented Jan 5, 2023

Yes, understood. Don't think this is your issue. But I'm curious if anyone is successfully using the action at this point?

@peter-evans
Copy link
Owner

All my tests are passing, so I think this is a very specific issue. I'm trying to figure out the exact scenario.

Test run from a hour or so ago:
https://github.com/peter-evans/create-pull-request-tests/actions/runs/3843283956

@peter-evans
Copy link
Owner

I forked your test repo, made a few changes to ignore secrets I don't have, and it seems to work.
https://github.com/peter-evans/odi-publishing-11ty-sandbox/actions/runs/3843584226/jobs/6545964628

@jbum
Copy link

jbum commented Jan 5, 2023

Woah! Trying that.

@peter-evans
Copy link
Owner

I also tried it in an org and that works, too. I don't have any idea what is going on. 🤔
https://github.com/create-pull-request/odi-publishing-11ty-sandbox/actions/runs/3843637176

@jbum
Copy link

jbum commented Jan 5, 2023

I suspect our token has expired (still fails if I comment out committer). Will continue investigating that. Thank so much for helping us isolate it. You want way above and beyond.

It is curious that a few folks experienced this specific error message today...

@peter-evans
Copy link
Owner

peter-evans commented Jan 5, 2023

I suspect our token has expired

It looks like you are using the default GITHUB_TOKEN for the repository. That token doesn't expire.
Or have you created a secret in your repository with the exact same name as the default token?

It is curious that a few folks experienced this specific error message today...

That's why I would be surprised if this was just down to token expiration. Please let me know if you solve it.

@davereid-pfg
Copy link
Author

davereid-pfg commented Jan 5, 2023

Are you creating a pull request remotely? (In a repo other than where the workflow is running)

No, it is the same repository.

Is the repo where the workflow runs private?

Yes

Is the remote repo private?

Yes, but also same repository, not remote

What type of token are you using? What scopes?

Generated via Github App using https://github.com/tibdex/github-app-token action.

    permissions:
      contents: write
      pull-requests: write

Are the repos in an org or user account?

An organization account.

@davereid-pfg
Copy link
Author

davereid-pfg commented Jan 5, 2023

The mysterious thing is that several other similar private repositories under the same organization account didn't fail and were just fine, using the exact same workflow (and same Github token generation via Github App). It seems isolated to one repository, I just can't figure out why. All the logs look the same and I cannot find any distinguishing factor in the workflow runs.

@chachasikes
Copy link

👋🏼 @davereid-pfg
Interesting & mysterious indeed.

We are trying different configurations of setting head_repo - but no luck yet.

@jbum
Copy link

jbum commented Jan 5, 2023

We're pretty sure it's not the token or committer at this point...

@chachasikes
Copy link

chachasikes commented Jan 5, 2023

Not seeing head_repo set anywhere in create-pull-request. It may be a bug coming from octokit.
We are stopping for the night. Will revisit tomorrow.

@davereid-pfg
Copy link
Author

I just checked out the branch that was created in our workflow via this action locally for the repository and used gh pr create --base main --title "Test" --body "Body" which succeeded so it doesn't seem to me to be an issue with the API or cli at this point.

@Becram
Copy link

Becram commented Jan 5, 2023

@peter-evans I am having similar issue, my scenario it different than your test case, I checkout a different repo and use the action to create pr into that repo. This might help reproduce the issue

@Katz-Tal
Copy link

Katz-Tal commented Jan 5, 2023

Hey everyone, same issue for me.
I'm using it for fork sync and since today (it runs every day) it's started doing that error
For same-org, cross-repo pulls, 'head_repo' is required: {"resource":"PullRequest","field":"head","code":"invalid"}

@akbast
Copy link

akbast commented Jan 5, 2023

I am having also the same issue and the same scenario which @davereid-pfg has described. I am using a reusable workflow in all of the private repositories in which this action used and it is configured with a GitHub App. In some of the repositories it suddenly stopped working.

@unkali
Copy link

unkali commented Jan 5, 2023

I saw the exact same error pop up yesterday during our workflow

@matanshk
Copy link

matanshk commented Jan 5, 2023

Same issue appears in our public repo under our organization

For same-org, cross-repo pulls, 'head_repo' is required: {"resource":"PullRequest","field":"head","code":"invalid"}

@peter-evans
Copy link
Owner

I found this other issue by searching GitHub. It looks related.
interledger/web-monetization-projects#3558

I'm keeping an eye out for similar issues:
https://github.com/search?q=%22For+same-org%2C+cross-repo+pulls%22&type=issues

I haven't had a response from GitHub Support yet.

@gm3dmo
Copy link

gm3dmo commented Jan 5, 2023

GitHub engineering are now investigating.

@gm3dmo
Copy link

gm3dmo commented Jan 5, 2023

@peter-evans Changes have been made. Please can you retry and let us know if the behaviour persists.

@akbast
Copy link

akbast commented Jan 5, 2023

I have tried in one of the failing repositories. It is working again.

@Becram
Copy link

Becram commented Jan 5, 2023

its working thank you

@gm3dmo
Copy link

gm3dmo commented Jan 5, 2023

Apologies for the inconvenience.

@peter-evans
Copy link
Owner

@gm3dmo Thank you for the fix!

@Katz-Tal
Copy link

Katz-Tal commented Jan 5, 2023

It was solved, thanks!

@clxmstaab
Copy link

solved, thanks

@davereid-pfg
Copy link
Author

Can confirm as well, resolved today without any changes.

@jbum
Copy link

jbum commented Jan 5, 2023

@chachasikes and I can confirm as well. Working.

@jbum
Copy link

jbum commented Jan 5, 2023

Thank you everyone who reported this, and @peter-evans for investigating and @gm3dmo for the fix!

@peter-evans
Copy link
Owner

Closing as resolved. Thank you everyone!

@littleGnAl
Copy link

I'm not very sure if it's the same issue, here's my failed job:
https://github.com/littleGnAl/hoe/actions/runs/4492290785

After I change it to the restful API, it works fine:
https://github.com/littleGnAl/hoe/actions/runs/4492523688

@krebemm
Copy link

krebemm commented Aug 23, 2023

getting same error Validation Failed: {"resource":"PullRequest","field":"head","code":"invalid"}

it has been working all day too...

@krebemm
Copy link

krebemm commented Aug 23, 2023

getting same error Validation Failed: {"resource":"PullRequest","field":"head","code":"invalid"}

it has been working all day too...

it is happening in two of my repos that have been using it for months and just today has ran 4 hrs ago as well. in my third testing repo, it is working as well

@krebemm
Copy link

krebemm commented Aug 29, 2023

following up @peter-evans this is still happening unfortunately, do you have any suggestions?

@HarryZ10
Copy link

@krebemm did you get it working?

@krebemm
Copy link

krebemm commented Feb 14, 2024

@HarryZ10 yes but i ended up just using git cli instead of this action, it has been reliable so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests