Skip to content

Commit fd6e9cb

Browse files
committed
feat: Remove dependency on .github/labels.yaml
Instead, use a first party `.prowlabels.yaml` file for labeling support Signed-off-by: John McBirde <[email protected]>
1 parent a55b50d commit fd6e9cb

17 files changed

+71
-144
lines changed

.github/workflows/prLabeler.yml

-12
This file was deleted.

.github/labels.yaml renamed to .prowlabels.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@ kind:
99
priority:
1010
- 'low'
1111
- 'high'
12-
13-
tests:
14-
- '**/*.test.ts'
15-
16-
source:
17-
- 'src/**'

README.md

+4-27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Check out the _"EXAMPLE"_ issues and pull requests (open and closed) in this rep
1010

1111
---
1212
Run specified actions or jobs for issue and PR comments through a `workflow.yaml` file:
13+
1314
```yaml
1415
name: "Prow github actions"
1516
on:
@@ -41,34 +42,8 @@ jobs:
4142
github-token: "${{ secrets.GITHUB_TOKEN }}"
4243
```
4344
44-
Automatically label PRs with the [Github actions/labeler](https://github.com/actions/labeler/blob/main/README.md) based on globs from `.github/labels.yml`:
45-
```yaml
46-
name: "Pull Request Labeler"
47-
on:
48-
- pull_request_target
49-
50-
jobs:
51-
triage:
52-
runs-on: ubuntu-latest
53-
steps:
54-
- uses: actions/labeler@main
55-
with:
56-
repo-token: "${{ secrets.GITHUB_TOKEN }}"
57-
```
58-
59-
Your `.github/labels.yaml` may look like:
60-
```yaml
61-
# labels to be used with /area command
62-
area:
63-
- 'bug'
64-
- 'important'
65-
66-
# File globs for PR labeler
67-
tests:
68-
- '**/*.test.ts'
69-
```
70-
7145
You can automatically merge PRs based on a cron schedule if it contains the `lgtm` label:
46+
7247
```yaml
7348
name: "Merge on lgtm label"
7449
on:
@@ -89,6 +64,7 @@ jobs:
8964
```
9065

9166
Prow Github actions also supports removing the lgtm label when a PR is updated
67+
9268
```yaml
9369
name: "Run Jobs on PR"
9470
on: pull_request
@@ -115,6 +91,7 @@ jobs:
11591
- [Contributing](./docs/contributing.md)
11692

11793
---
94+
11895
_open water breeze
11996
the ocean seas are endless
12097
forward to the prow_

__tests__/fixtures/labels/labelFileContentsResp.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"encoding": "base64",
44
"size": 5362,
55
"name": "labels.yaml",
6-
"path": ".github/labels.yaml",
6+
"path": ".prowlabels.yaml",
77
"content": "YXJlYToKICAtICdidWcnCiAgLSAnaW1wb3J0YW50JwoKa2luZDoKICAtICdmYWlsaW5nLXRlc3QnCiAgLSAnY2xlYW51cCcKCnByaW9yaXR5OgogIC0gJ2xvdycKICAtICdoaWdoJwoKdGVzdHM6CiAgLSAnKiovKi50ZXN0LnRzJwoKc291cmNlOgogIC0gJ3NyYy8qKicK",
88
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1",
99
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/.github.jpy.wang/labels.yaml",
@@ -15,4 +15,4 @@
1515
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/.github.jpy.wang/labels.yaml",
1616
"html": "https://github.com/octokit/octokit.rb/blob/master/.github.jpy.wang/labels.yaml"
1717
}
18-
}
18+
}

__tests__/fixtures/labels/labelFileMalformedResponse.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"encoding": "base64",
44
"size": 5362,
55
"name": "labels.yaml",
6-
"path": ".github/labels.yaml",
6+
"path": ".prowlabels.yaml",
77
"content": "Cm15LXNwaWN5LWxhYmVsczoKICBhcmVhOgogIC0gJ2J1ZycKICAtICdpbXBvcnRhbnQnCgpraW5kOgogIC0gJ2ZhaWxpbmctdGVzdCcKICAtICdjbGVhbnVwJwoKdGVzdHM6CiAgLSAnX190ZXN0c19fLyonCgpzb3VyY2U6CiAgLSAnc3JjLyonCg==",
88
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1",
99
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/.github.jpy.wang/labels.yaml",
@@ -15,4 +15,4 @@
1515
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/.github.jpy.wang/labels.yaml",
1616
"html": "https://github.com/octokit/octokit.rb/blob/master/.github.jpy.wang/labels.yaml"
1717
}
18-
}
18+
}

__tests__/label/area.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('area', () => {
3535

3636
server.use(
3737
rest.get(
38-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
38+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
3939
utils.mockResponse(200, labelFileContents)
4040
)
4141
)
@@ -61,7 +61,7 @@ describe('area', () => {
6161

6262
server.use(
6363
rest.get(
64-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
64+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
6565
utils.mockResponse(200, labelFileContents)
6666
)
6767
)
@@ -73,7 +73,7 @@ describe('area', () => {
7373
})
7474
})
7575

76-
it('only adds area labels for files in .github/labels.yaml', async () => {
76+
it('only adds area labels for files in .prowlabels.yaml', async () => {
7777
issueCommentEvent.comment.body = '/area bug bad important'
7878
const commentContext = new utils.mockContext(issueCommentEvent)
7979

@@ -87,7 +87,7 @@ describe('area', () => {
8787

8888
server.use(
8989
rest.get(
90-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
90+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
9191
utils.mockResponse(200, labelFileContents)
9292
)
9393
)

__tests__/label/kind.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('kind', () => {
3535

3636
server.use(
3737
rest.get(
38-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
38+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
3939
utils.mockResponse(200, labelFileContents)
4040
)
4141
)
@@ -61,7 +61,7 @@ describe('kind', () => {
6161

6262
server.use(
6363
rest.get(
64-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
64+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
6565
utils.mockResponse(200, labelFileContents)
6666
)
6767
)
@@ -73,7 +73,7 @@ describe('kind', () => {
7373
})
7474
})
7575

76-
it('only adds kind labels for files in .github/labels.yaml', async () => {
76+
it('only adds kind labels for files in .prowlabels.yaml', async () => {
7777
issueCommentEvent.comment.body = '/kind cleanup bad failing-test'
7878
const commentContext = new utils.mockContext(issueCommentEvent)
7979

@@ -87,7 +87,7 @@ describe('kind', () => {
8787

8888
server.use(
8989
rest.get(
90-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
90+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
9191
utils.mockResponse(200, labelFileContents)
9292
)
9393
)

__tests__/label/priority.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('priority', () => {
3535

3636
server.use(
3737
rest.get(
38-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
38+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
3939
utils.mockResponse(200, labelFileContents)
4040
)
4141
)
@@ -61,7 +61,7 @@ describe('priority', () => {
6161

6262
server.use(
6363
rest.get(
64-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
64+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
6565
utils.mockResponse(200, labelFileContents)
6666
)
6767
)
@@ -73,7 +73,7 @@ describe('priority', () => {
7373
})
7474
})
7575

76-
it('only adds priority labels for files in .github/labels.yaml', async () => {
76+
it('only adds priority labels for files in .prowlabels.yaml', async () => {
7777
issueCommentEvent.comment.body = '/priority low mid high'
7878
const commentContext = new utils.mockContext(issueCommentEvent)
7979

@@ -87,7 +87,7 @@ describe('priority', () => {
8787

8888
server.use(
8989
rest.get(
90-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
90+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
9191
utils.mockResponse(200, labelFileContents)
9292
)
9393
)

__tests__/utils/labeling.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ describe('utils labeling', () => {
3838

3939
server.use(
4040
rest.get(
41-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yml`,
41+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yml`,
4242
utils.mockResponse(200, labelFileContents)
4343
),
4444
rest.get(
45-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
45+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
4646
utils.mockResponse(404)
4747
)
4848
)
@@ -62,11 +62,11 @@ describe('utils labeling', () => {
6262

6363
server.use(
6464
rest.get(
65-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yml`,
65+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yml`,
6666
utils.mockResponse(200, malformedFileContents)
6767
),
6868
rest.get(
69-
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
69+
`${utils.api}/repos/Codertocat/Hello-World/contents/.prowlabels.yaml`,
7070
utils.mockResponse(404)
7171
)
7272
)

dist/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ const tryMergePr = async (pr, octokit, context = github.context) => {
238238

239239
"use strict";
240240

241+
/**
242+
* @deprecated - it's no longer recommended to use the cron labeler for PRs.
243+
* As of ~2020, GitHub actions support `pull_request_target` which can be used with
244+
* the "actions/labeler" workflow. This supports labeling PRs when they are opened,
245+
* even from forks (which this feature attempted to subvert via a cron).
246+
*/
241247
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
242248
if (k2 === undefined) k2 = k;
243249
var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -2774,7 +2780,7 @@ exports.cancelLabel = exports.addPrefix = exports.removeLabels = exports.getCurr
27742780
const core = __importStar(__nccwpck_require__(2186));
27752781
const yaml = __importStar(__nccwpck_require__(1917));
27762782
/**
2777-
* getArgumentLabels will get the .github/labels.yaml or .github.labels.yml file.
2783+
* getArgumentLabels will get the .prowlabels.yaml or .prowlabels.yml file.
27782784
* it will then return the section specified by arg.
27792785
*
27802786
* This method has some eslint ignores related to
@@ -2790,18 +2796,18 @@ const getArgumentLabels = async (octokit, context, arg) => {
27902796
try {
27912797
response = await octokit.repos.getContent({
27922798
...context.repo,
2793-
path: '.github/labels.yaml'
2799+
path: '.prowlabels.yaml'
27942800
});
27952801
}
27962802
catch (e) {
27972803
try {
27982804
response = await octokit.repos.getContent({
27992805
...context.repo,
2800-
path: '.github/labels.yml'
2806+
path: '.prowlabels.yml'
28012807
});
28022808
}
28032809
catch (e2) {
2804-
throw new Error(`could not get .github/labels.yaml or .github/labels.yml: ${e} ${e2}`);
2810+
throw new Error(`could not get .prowlabels.yaml or .prowlabels.yml: ${e} ${e2}`);
28052811
}
28062812
}
28072813
if (!response.data.content || !response.data.encoding) {

docs/commands.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Commands | Policy | Description
1717

1818
Label Commands | Policy | Description
1919
--- | --- | ---
20-
`/area [label1 label2 ...]` | anyone | adds an area/<> label(s) if it's defined in [the `.github/labels.yaml` file](./labeling.md)
21-
`/kind [label1 label2 ...]` | anyone | adds a kind/<> label(s) if it's defined in [the `.github/labels.yaml` file](./labeling.md)
20+
`/area [label1 label2 ...]` | anyone | adds an area/<> label(s) if it's defined in [the `.prowlabels.yaml` file](./labeling.md)
21+
`/kind [label1 label2 ...]` | anyone | adds a kind/<> label(s) if it's defined in [the `.prowlabels.yaml` file](./labeling.md)
2222
`/lgtm` | [OWNERS](#owners) if present, otherwise Collaborators and Org Members | adds the `lgtm` label. This is used for [automatic PR merging]()
2323
`/lgtm cancel` | [OWNERS](#owners) if present, otherwise Collaborators and Org Members | removes the `lgtm` label
2424
`/hold` | anyone | adds the `hold` label which prevents [automatic PR merging](./automatic-merging.md). Also see [lgtm removal on pr update](./pr-jobs.md)
2525
`/hold cancel` | anyone | removes the `hold` label
26-
`/priority [label1 label2 ...]` | anyone | adds a priority/<> label(s) if it's defined in [the `.github/labels.yaml` file](./automatic-merging.md)
26+
`/priority [label1 label2 ...]` | anyone | adds a priority/<> label(s) if it's defined in [the `.prowlabels.yaml` file](./automatic-merging.md)
2727
`/remove [label1 label2 ...]` | Collaborators | removes a specified label(s) on an issue / PR
2828

2929
## OWNERS

docs/cron-jobs.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ The following jobs are supported through [cron Github workflows]().
55
Jobs | Description
66
--- | ---
77
`lgtm` | Will attempt to automatically merge a PR with the `lgtm` label. Blocked by the `hold` label. Removed by the [lgtm PR job on pr update](./pr-jobs.md)
8-
`pr-labeler` | Labels PRs with labels based on file globs found in `.github/labels.yaml`. See [docs on PR labeler for more info](pr-labeling.md)
8+
`pr-labeler` | **(DEPRECATED)** Labels PRs with labels based on file globs found in `.github/labels.yaml`. See [docs on PR labeler for more info](pr-labeling.md)
99

10-
## PR labeler
11-
> What is this Chron job PR labeler?
10+
> What is the Chron job PR labeler?
1211
1312
This job is a legacy feature of Github Prow bot which would label PRs
1413
based on a chron schedule. This was created since Github at the time did not provide a way
15-
to securely run actions (and therefore code) from PR forks, which could possibly be untrusted.
14+
to securely run actions (and therefore code) from PR forks, which could possibly be untrusted.
1615
This chron job runs from _the main branch_ and not forks, therefore preventing any
1716
forked malicious code from being run against the repository.
1817

@@ -36,6 +35,7 @@ However, this has some known limitations. The chron labeler queries Github in 10
3635
This can trigger github to rate limit the bot.
3736

3837
This job may be run with the following workflow configuration:
38+
3939
```yml
4040
name: "Label PRs from globs"
4141
on:

docs/examples.md

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# Examples
22

3-
* [.github/labels.yaml](#githublabelsyaml)
3+
* [`.prowlabels.yaml`](#prowlabelsyaml)
44
* [Review and Approve Pull Requests](#review-and-approve-pull-requests)
55
* [All prow github actions](#all-prow-github-actions)
66
* [PR Labeler](#pr-labeler)
77
* [Automatic PR merger](#automatic-pr-merger)
88
* [PR job to remove lgtm label on update](#pr-job-to-remove-lgtm-label-on-update)
99

10-
### .github/labels.yaml
11-
A `.github/labels.yaml` file is necessary for most of the labeling commands & jobs
10+
### `.prowlabels.yaml`
11+
12+
A `.prowlabels.yaml` file is necessary for most of the labeling commands & jobs:
1213

1314
```yaml
1415
area:
@@ -23,14 +24,6 @@ priority:
2324
- 'low'
2425
- 'mid'
2526
- 'high'
26-
27-
# File globs for PR labeler
28-
# refer to github actions/labeler for further documentation
29-
tests:
30-
- '**/*.test.ts'
31-
32-
source:
33-
- 'src/**'
3427
```
3528
3629
### Review and Approve Pull Requests

0 commit comments

Comments
 (0)