Skip to content

Commit f8d28e0

Browse files
kaizenccgithub-actions
and
github-actions
authored
chore: pr labeler workflow (#178)
equivalent to this file in aws/aws-cdk except `auto-approve` is governed by projen already: https://github.com/aws/aws-cdk/blob/main/.github/workflows/pr-labeler.yml. will copy over labels from linked issues to the PR. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent 09ef5a0 commit f8d28e0

File tree

8 files changed

+91
-9
lines changed

8 files changed

+91
-9
lines changed

.gitattributes

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/pr-labeler.yml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gitignore

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/files.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CodeCovWorkflow } from './projenrc/codecov';
88
import { ESLINT_RULES } from './projenrc/eslint';
99
import { IssueLabeler } from './projenrc/issue-labeler';
1010
import { JsiiBuild } from './projenrc/jsii';
11+
import { PrLabeler } from './projenrc/pr-labeler';
1112
import { RecordPublishingTimestamp } from './projenrc/record-publishing-timestamp';
1213
import { S3DocsPublishing } from './projenrc/s3-docs-publishing';
1314

@@ -1403,5 +1404,6 @@ new CodeCovWorkflow(repo, {
14031404
});
14041405

14051406
new IssueLabeler(repo);
1407+
new PrLabeler(repo);
14061408

14071409
repo.synth();

projenrc/issue-labeler.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, github } from 'projen';
22
import { JobPermission } from 'projen/lib/github/workflows-model';
33
import { TypeScriptProject } from 'projen/lib/typescript';
4+
import { GitHubToken, stringifyList } from './util';
45

56
const OSDS_DEVS = ['ashishdhingra', 'khushail', 'hunhsieh'];
67
const AREA_AFFIXES = ['@aws-cdk/'];
@@ -13,11 +14,6 @@ const AREA_PARAMS = [
1314
{ area: 'cdk-assets', keywords: ['assets', 'cdk-assets'], labels: ['cdk-assets'] },
1415
];
1516

16-
enum GitHubToken {
17-
GITHUB_TOKEN = 'secrets.GITHUB_TOKEN',
18-
PROJEN_GITHUB_TOKEN = 'secrets.PROJEN_GITHUB_TOKEN',
19-
}
20-
2117
/**
2218
* See https://github.com/aws-github-ops/aws-issue-triage-manager
2319
*/
@@ -41,10 +37,6 @@ interface TriageManagerOptions {
4137
githubToken?: GitHubToken;
4238
}
4339

44-
function stringifyList(list: string[]) {
45-
return `[${list.join('|')}]`;
46-
}
47-
4840
function triageManagerJob(triageManagerOptions: TriageManagerOptions) {
4941
return {
5042
name: 'Triage Manager',

projenrc/pr-labeler.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Component, github } from 'projen';
2+
import { JobPermission } from 'projen/lib/github/workflows-model';
3+
import { TypeScriptProject } from 'projen/lib/typescript';
4+
import { GitHubToken, stringifyList } from './util';
5+
6+
/**
7+
* See https://github.com/cdklabs/pr-triage-manager
8+
*/
9+
interface PrLabelerOptions {
10+
/**
11+
* @default GitHubToken.GITHUB_TOKEN
12+
*/
13+
githubToken?: GitHubToken;
14+
priorityLabels?: string[];
15+
classificationLabels?: string[];
16+
onPulls?: boolean;
17+
}
18+
19+
function prLabelerJob(prLabelerOptions: PrLabelerOptions = {}) {
20+
return {
21+
name: 'PR Labeler',
22+
runsOn: ['aws-cdk_ubuntu-latest_4-core'],
23+
permissions: { issues: JobPermission.WRITE, pullRequests: JobPermission.WRITE },
24+
steps: [
25+
{
26+
name: 'PR Labeler',
27+
uses: 'cdklabs/pr-triage-manager@main',
28+
with: {
29+
'github-token': `\${{ ${prLabelerOptions.githubToken ?? 'secrets.GITHUB_TOKEN'} }}`,
30+
'priority-labels': prLabelerOptions.priorityLabels ? stringifyList(prLabelerOptions.priorityLabels) : undefined,
31+
'classification-labels': prLabelerOptions.classificationLabels ? stringifyList(prLabelerOptions.classificationLabels) : undefined,
32+
'on-pulls': prLabelerOptions.onPulls,
33+
},
34+
},
35+
],
36+
};
37+
}
38+
39+
export class PrLabeler extends Component {
40+
public readonly workflow: github.GithubWorkflow;
41+
42+
constructor(repo: TypeScriptProject) {
43+
super(repo);
44+
45+
if (!repo.github) {
46+
throw new Error('Given repository does not have a GitHub component');
47+
}
48+
49+
this.workflow = repo.github.addWorkflow('pr-labeler');
50+
this.workflow.on({
51+
pullRequestTarget: { types: ['opened', 'edited', 'reopened'] },
52+
});
53+
54+
this.workflow.addJob('copy-labels', prLabelerJob());
55+
}
56+
}

projenrc/util.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum GitHubToken {
2+
GITHUB_TOKEN = 'secrets.GITHUB_TOKEN',
3+
PROJEN_GITHUB_TOKEN = 'secrets.PROJEN_GITHUB_TOKEN',
4+
}
5+
6+
export function stringifyList(list: string[]) {
7+
return `[${list.join('|')}]`;
8+
}

0 commit comments

Comments
 (0)