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

Attempting creation of pull request Error: Not Found #3235

Closed
timteka opened this issue Aug 21, 2024 · 10 comments
Closed

Attempting creation of pull request Error: Not Found #3235

timteka opened this issue Aug 21, 2024 · 10 comments

Comments

@timteka
Copy link

timteka commented Aug 21, 2024

Subject of the issue

Can't create PR with unclear error

Attempting creation of pull request
Error: Not Found

Describe your issue here.
After successful creation of branch your action is not able to create PR. Maybe smth wrong with multiple checkouts?
Running this action in ParentRepo

Steps to reproduce

on:
  push:
    branches:
      - master
permissions: write-all
jobs:
  PR-Actions:
    runs-on: self-hosted
    
    steps:
...
- uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
          ssh-key: ${{ secrets.myorg }}
          path: parent-repo

      - uses: actions/checkout@v4
        with:
          repository: MyOrg/ChildRepo
          ref: master
          ssh-key: ${{ secrets.myorg }}
          path: child-repo
...
here numerous CRUD stuff with files from ChildRepo
...
- name: Create Pull Request
        env:
          BRANCH: ${{ steps.newbranch.outputs.BRANCH }}
          COMMITTER: ${{ steps.initiator.outputs.COMMITTER }}
          COMMITMSG: ${{ steps.initiator.outputs.COMMITMSG }}
        uses: peter-evans/create-pull-request@v6
        with:
          author: OurCorp <16988934324553+corp-ltd@users.noreply.github.com>
          branch: ${{ env.BRANCH }}
          title: "Automatic updates to ${{ env.BRANCH }}"
          body: "This is an auto-generated PR. Initiated by  ${{ env.COMMITTER }}. \n ${{ env.COMMITMSG }}"
          commit-message: "${{ env.COMMITMSG }}"
          path: child-repo

If this issue is describing a possible bug please provide (or link to) your GitHub Actions workflow.

@peter-evans
Copy link
Owner

Hi @timteka

Are you trying to create a pull request in the parent-repo with updates you've fetched from the child-repo? Or is it the other way round?

@timteka
Copy link
Author

timteka commented Aug 21, 2024

The Action is triggered by push into parent repo. In parent I only need to get some info (like changed packages versions) and afterwards everything else is gonna take place in child repo. The Action creates new branch successfully in child repo, but fails on PR (though I've set already sec permissions: the machine user is a Maintainer in child repo)

@peter-evans
Copy link
Owner

peter-evans commented Aug 21, 2024

the machine user is a Maintainer in child repo

Are you referring to the machine user that owns the SSH keys?

The action can only use SSH auth for the git operations. For creating the pull request the action needs a token. Because you've not specified a token the action will use the default GITHUB_TOKEN in the repository where the workflow is running. In your case the workflow is running in the parent repo, so the token is scoped to the parent. If you want to allow the action to create a pull request in the child then you need to use a PAT created on the machine user (with write access to the child repo), and pass that as the token input.

@peter-evans
Copy link
Owner

peter-evans commented Aug 21, 2024

Also see the docs here, where it says:

Note that you cannot use deploy keys alone to create a pull request 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.

@timteka
Copy link
Author

timteka commented Aug 21, 2024

I've added the token string:

- name: Create Pull Request
        env:
          BRANCH: ${{ steps.newbranch.outputs.BRANCH }}
          COMMITTER: ${{ steps.initiator.outputs.COMMITTER }}
          COMMITMSG: ${{ steps.initiator.outputs.COMMITMSG }}
        uses: peter-evans/create-pull-request@v6
        with:
          token: ${{ secrets.myOrg }}
          author: OurCorp <16988934324553+corp-ltd@users.noreply.github.com>
          branch: ${{ env.BRANCH }}
          title: "Automatic updates to ${{ env.BRANCH }}"
          body: "This is an auto-generated PR. Initiated by  ${{ env.COMMITTER }}. \n ${{ env.COMMITMSG }}"
          commit-message: "${{ env.COMMITMSG }}"
          path: child-repo

Another error:

Attempting creation of pull request
  Error: Headers.append: "token ***" is an invalid header value.

@peter-evans
Copy link
Owner

Did you pass the SSH key to the token input? That won't work. You need a PAT.

@timteka
Copy link
Author

timteka commented Aug 22, 2024

Did you pass the SSH key to the token input? That won't work. You need a [PAT]
Dear Peter, i've used the PAT defined on organization level:
image

@timteka
Copy link
Author

timteka commented Aug 22, 2024

Sorry, my bad. Need to read more thoroughly on PATs ))

@timteka
Copy link
Author

timteka commented Aug 22, 2024

Thank you so much, dear Peter. After generating fine-graned PAT everything is ok. PR was successfully created!

@peter-evans
Copy link
Owner

Good to hear you got it working!

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

2 participants