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

Question: Does this action work with pull requests from forks? #8

Closed
alexearnshaw opened this issue Apr 8, 2020 · 5 comments · Fixed by #80
Closed

Question: Does this action work with pull requests from forks? #8

alexearnshaw opened this issue Apr 8, 2020 · 5 comments · Fixed by #80

Comments

@alexearnshaw
Copy link

Hi, I'm looking for an app or action to label pull requests with a size based on LOC. This action looks perfect, but another similar action I tried did not work on PRs created from forks (which is the majority of PRs in our project). Can you confirm if this action will work on PRs from forks?

@rgomezcasas
Copy link
Member

It works! But if it's a fork you need to do some changes.

I'll change the README to reflect it (I'll close this issue when this is done). But for now:

If it's a fork you can't use the secrets.GITHUB_TOKEN because this belongs only to your project, so a fork won't have access to it.
To be able to use it, you should create a custom token from a user of your organization (usually you create a "bot" user for it, like ours) and then add this token to your repository secrets (usually with a GITHUB_BOT_TOKEN name or similar).

So, instead of having something like:

steps:
    - uses: codelytv/pr-size-labeler@v1
      with:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

You'll have:

steps:
    - uses: codelytv/pr-size-labeler@v1
      with:
        GITHUB_TOKEN: ${{ secrets.GITHUB_BOT_TOKEN }}

If you don't want to create a new user you can create a personal token from any member of your organization. But then on every pull request, when autolabeled, instead of "github-bot have added some label" you'll have "This user has added some label".

I guess it's the same problem you have with other Actions, the solution it's the same for everyone. 😊

@alexearnshaw
Copy link
Author

Thanks so much @rgomezcasas I'll give that a try!

@alexearnshaw
Copy link
Author

@rgomezcasas I'm hoping you can help me a little more. I've followed the instructions above and this action is now working for PRs created from branches of the repo (see the PR where I added it where it was correctly labeled)
However, it's not working correctly for a PR from a fork - see 2 examples here https://github.com/Axway/axway-open-docs/pull/612 and https://github.com/Axway/axway-open-docs/pull/610)

This is the output of the action:
image

The bot user I created docsbuilder has write access to our repo and the token I created for this user has been granted all scopes. Am I missing something?

@S-Coyle
Copy link

S-Coyle commented Feb 1, 2021

@alexearnshaw @rgomezcasas I don't suppose anyone found any workaround or alternative for this to work from PRs from forks? Exactly the scenario I was hoping to cover.

@markmandel
Copy link

markmandel commented Aug 9, 2021

I resolved this by using pull_request_target as the target, since that GITHUB_TOKEN has read and write permissions 👍🏻

https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target

Achllle added a commit to Achllle/pr-size-labeler that referenced this issue Jul 23, 2024
@Achllle Achllle mentioned this issue Jul 23, 2024
1 task
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

Successfully merging a pull request may close this issue.

4 participants