You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update readme with additional examples and important note about pull_request_target event (#721)
* docs: add note about pull_request_target event trigger
* docs: change note from being caution to important
* docs: fix typos
* docs: add examples to the examples chapter
* docs: fix typos
Copy file name to clipboardExpand all lines: README.md
+36-3Lines changed: 36 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,9 @@ Automatically label new pull requests based on the paths of files being changed
13
13
14
14
4) Version 5 of this action updated the [runtime to Node.js 20](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions). All scripts are now run with Node.js 20 instead of Node.js 16 and are affected by any breaking changes between Node.js 16 and 20.
15
15
16
+
> [!IMPORTANT]
17
+
> Before the update to the v5, please check out [this information](#notes-regarding-pull_request_target-event) about the `pull_request_target` event trigger.
18
+
16
19
## Usage
17
20
18
21
### Create `.github/labeler.yml`
@@ -110,6 +113,18 @@ Documentation:
110
113
- changed-files:
111
114
- any-glob-to-any-file: docs/*
112
115
116
+
# Add 'Documentation' label to any file changes within 'docs' or 'guides' folders
117
+
Documentation:
118
+
- changed-files:
119
+
- any-glob-to-any-file:
120
+
- docs/*
121
+
- guides/*
122
+
123
+
## Equivalent of the above mentioned configuration using another syntax
124
+
Documentation:
125
+
- changed-files:
126
+
- any-glob-to-any-file: ['docs/*', 'guides/*']
127
+
113
128
# Add 'Documentation' label to any change to .md files within the entire repository
114
129
Documentation:
115
130
- changed-files:
@@ -126,7 +141,7 @@ source:
126
141
feature:
127
142
- head-branch: ['^feature', 'feature']
128
143
129
-
# Add 'release' label to any PR that is opened against the `main` branch
144
+
# Add 'release' label to any PR that is opened against the `main` branch
130
145
release:
131
146
- base-branch: 'main'
132
147
```
@@ -246,9 +261,27 @@ jobs:
246
261
In order to add labels to pull requests, the GitHub labeler action requires write permissions on the pull-request. However, when the action runs on a pull request from a forked repository, GitHub only grants read access tokens for `pull_request` events, at most. If you encounter an `Error: HttpError: Resource not accessible by integration`, it's likely due to these permission constraints. To resolve this issue, you can modify the `on:` section of your workflow to use
247
262
[`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) instead of `pull_request` (see example [above](#create-workflow)). This change allows the action to have write access, because `pull_request_target` alters the [context of the action](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) and safely grants additional permissions. Refer to the [GitHub token permissions documentation](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token) for more details about access levels and event contexts.
248
263
249
-
## Notes regarding `pull_request_target`
264
+
## Notes regarding `pull_request_target` event
265
+
266
+
Using the `pull_request_target` event trigger involves several peculiarities related to initial set up of the labeler or updating version of the labeler.
267
+
268
+
### Initial set up of the labeler action
269
+
270
+
When submitting an initial pull request to a repository using the `pull_request_target` event, the labeler workflow will not run on that pull request because the `pull_request_target` execution runs off the base branch instead of the pull request's branch. Unfortunately this means the introduction of the labeler can not be verified during that pull request and it needs to be committed blindly.
271
+
272
+
### Updating major version of the labeler
273
+
274
+
When submitting a pull request that includes updates of the labeler action version and associated configuration files, using the `pull_request_target` event may result in a failed workflow. This is due to the nature of `pull_request_target`, which uses the code from the base branch rather than the branch linked to the pull request — so, potentially outdated configuration files may not be compatible with the updated labeler action.
275
+
276
+
To prevent this issue, you can switch to using the `pull_request` event temporarily, before merging. This event execution draws from the code within the branch of your pull request, allowing you to verify the new configuration's compatibility with the updated labeler action.
277
+
278
+
```yml
279
+
name: "Pull Request Labeler"
280
+
on:
281
+
- pull_request
282
+
```
250
283
251
-
When submitting a initial pull request to a repository using the `pull_request_target` event, the labeler workflow will not run on that pull request because the `pull_request_target` execution runs off the base branch instead of the pull request's branch. Unfortunately this means the introduction of the labeler can not be verified during that pull request and it needs to be committed blindly.
284
+
Once you confirm that the updated configuration files function as intended, you can then revert to using the `pull_request_target` event before merging the pull request. Following this step ensures that your workflow is robust and free from disruptions.
0 commit comments