Add labels when creating PR
Subject of the issue
It will be good if labels get added at the time of PR creation. This way application based on a new PR event with the label will work. Like slack notification filter https://github.com/integrations/slack#filters
Hi @avdhoot
GitHub's REST API actually doesn't support applying labels at the same time as creating the pull request. You can see the documentation here.
Can you explain in further detail what you are trying to do that doesn't work. There may be an alternative way or workaround.
Looking to get slack notification when PR is created with a specific label. To achieve this; I have configured GitHub slack app and added filters like /github subscribe myorg/myrepo pulls +label:"notify".
Get notification in the below scenario:
- Created PR with label using web.
No notification in the below scenario:
- Created PR later added label using web.
- PR created using create-pull-request action with a label.
Note: Trying to avoid slack action in a workflow
Thanks for reply @peter-evans
I see. Thank you for the explanation.
I found an issue with this exact problem being discussed. https://github.com/integrations/slack/issues/1039 Unfortunately, it doesn't look like there is a good solution. This is really a problem/limitation of GitHub's own APIs.
I also found this thread with official responses that make it clear that both the REST API and GraphQL API have this limitation. https://github.community/t/create-pull-request-and-add-labels-in-a-single-request/116146
I have a problem with this asynchronous label creation in the following scenario:
- create PR and add a label (using this action)
- creating PR triggers a separate label checker action for the new PR
- issue: sometimes label checker action fails because the label for the auto-generated PR is not yet in place
To get the label checker pass, I add labels as a separate GitHub CLI call.
Any comments on this @peter-evans? Is it possible that this action would start working with the label check? (edit: reading the linked Github community thread it seems that there is none)
Hi @laojala
Unfortunately, I don't think there is anything I can do to resolve this from the action itself. It's a limitation of how GitHub's APIs work. There is no API I can call which will create the pull request and label it at the same time.
I can only suggest working around the issue, perhaps by triggering workflows based on the label being added rather than the pull request being created.
e.g.
on:
issues:
types:
- labeled
jobs:
exampleJob:
if: github.event.label.name == 'my-label'
runs-on: ubuntu-latest
steps:
...