Skip to content

Commit 97d02a8

Browse files
kaizenccgithub-actions
andauthored
chore: issue labeler workflow (#118)
Attempting to copy and projenify this workflow: https://github.com/aws/aws-cdk/blob/main/.github/workflows/issue-label-assign.yml --- 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 <github-actions@github.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent bf33829 commit 97d02a8

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/issue-label-assign.yml

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gitignore

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/files.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AdcPublishing } from './projenrc/adc-publishing';
66
import { BundleCli } from './projenrc/bundle';
77
import { CodeCovWorkflow } from './projenrc/codecov';
88
import { ESLINT_RULES } from './projenrc/eslint';
9+
import { IssueLabeler } from './projenrc/issue-labeler';
910
import { JsiiBuild } from './projenrc/jsii';
1011
import { RecordPublishingTimestamp } from './projenrc/record-publishing-timestamp';
1112
import { S3DocsPublishing } from './projenrc/s3-docs-publishing';
@@ -1352,4 +1353,6 @@ new CodeCovWorkflow(repo, {
13521353
packages: [cli.name],
13531354
});
13541355

1356+
new IssueLabeler(repo);
1357+
13551358
repo.synth();

projenrc/issue-labeler.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { Component, github } from 'projen';
2+
import { JobPermission } from 'projen/lib/github/workflows-model';
3+
import { TypeScriptProject } from 'projen/lib/typescript';
4+
5+
const OSDS_DEVS = ['ashishdhingra', 'khushail', 'hunhsieh'];
6+
const AREA_AFFIXES = ['@aws-cdk/'];
7+
const AREA_PARAMS = [
8+
{ area: '@aws-cdk/cli-lib-alpha', keywords: ['cli', 'cli-lib', 'cli-lib-alpha'], labels: ['@aws-cdk/cli-lib-alpha'] },
9+
{ area: '@aws-cdk/cloud-assembly-schema', keywords: ['cloud-assembly', 'schema'], labels: ['@aws-cdk/cloud-assembly-schema'] },
10+
{ area: '@aws-cdk/cloudformation-diff', keywords: ['diff', 'cloudformation'], labels: ['@aws-cdk/cloudformation-diff'] },
11+
{ area: '@aws-cdk/toolkit-lib', keywords: ['toolkit', 'programmtic toolkit', 'toolkit-lib'], labels: ['@aws-cdk/toolkit-lib'] },
12+
{ area: 'aws-cdk', keywords: ['aws-cdk', 'cli', 'cdk cli'], labels: ['aws-cdk'] },
13+
{ area: 'cdk-assets', keywords: ['assets', 'cdk-assets'], labels: ['cdk-assets'] },
14+
];
15+
16+
enum GitHubToken {
17+
GITHUB_TOKEN = 'secrets.GITHUB_TOKEN',
18+
PROJEN_GITHUB_TOKEN = 'secrets.PROJEN_GITHUB_TOKEN',
19+
}
20+
21+
/**
22+
* See https://github.com/aws-github-ops/aws-issue-triage-manager
23+
*/
24+
interface TriageManagerOptions {
25+
target: 'pull-requests' | 'issues' | 'both';
26+
excludedExpressions?: string[];
27+
includedLabels?: string[];
28+
excludedLabels?: string[];
29+
defaultArea?: string;
30+
parameters?: string;
31+
affixes?: string;
32+
areaIsKeyword?: boolean;
33+
/**
34+
* Whether or not the env variables are needed for the job.
35+
* Workflow-level env variables are not configurable via Projen
36+
*/
37+
needEnvs?: boolean;
38+
/**
39+
* @default GitHubToken.GITHUB_TOKEN
40+
*/
41+
githubToken?: GitHubToken;
42+
}
43+
44+
function stringifyList(list: string[]) {
45+
return `[${list.join('|')}]`;
46+
}
47+
48+
function triageManagerJob(triageManagerOptions: TriageManagerOptions) {
49+
return {
50+
name: 'Triage Manager',
51+
runsOn: ['aws-cdk_ubuntu-latest_4-core'],
52+
permissions: { issues: JobPermission.WRITE, pullRequests: JobPermission.WRITE },
53+
steps: [
54+
{
55+
name: 'Triage Manager',
56+
uses: 'aws-github-ops/aws-issue-triage-manager@main',
57+
with: {
58+
'github-token': `\${{ ${triageManagerOptions.githubToken ?? 'secrets.GITHUB_TOKEN'} }}`,
59+
'target': triageManagerOptions.target,
60+
'excluded-expressions': triageManagerOptions.excludedExpressions ? stringifyList(triageManagerOptions.excludedExpressions) : undefined,
61+
'included-labels': triageManagerOptions.includedLabels ? stringifyList(triageManagerOptions.includedLabels) : undefined,
62+
'excluded-labels': triageManagerOptions.excludedLabels ? stringifyList(triageManagerOptions.excludedLabels) : undefined,
63+
'default-area': triageManagerOptions.defaultArea,
64+
'parameters': triageManagerOptions.parameters,
65+
'affixes': triageManagerOptions.affixes,
66+
'area-is-keyword': triageManagerOptions.areaIsKeyword,
67+
},
68+
},
69+
],
70+
...(triageManagerOptions.needEnvs ? {
71+
env: {
72+
AREA_PARAMS: JSON.stringify(AREA_PARAMS),
73+
AREA_AFFIXES: `{"prefixes":${JSON.stringify(AREA_AFFIXES)}}`,
74+
OSDS_DEVS: `{"assignees":${JSON.stringify(OSDS_DEVS)}}`,
75+
},
76+
} : {}),
77+
};
78+
}
79+
80+
export class IssueLabeler extends Component {
81+
public readonly workflow: github.GithubWorkflow;
82+
83+
constructor(repo: TypeScriptProject) {
84+
super(repo);
85+
86+
if (!repo.github) {
87+
throw new Error('Given repository does not have a GitHub component');
88+
}
89+
90+
this.workflow = repo.github.addWorkflow('issue-label-assign');
91+
this.workflow.on({
92+
pullRequestTarget: { types: ['opened'] },
93+
issues: { types: ['opened', 'edited'] },
94+
});
95+
96+
this.workflow.addJob('Triage Issues', triageManagerJob({
97+
target: 'issues',
98+
excludedExpressions: ['CDK CLI Version', 'TypeScript', 'Java', 'Python', 'Go'],
99+
includedLabels: ['needs-triage'],
100+
excludedLabels: ['p1', 'p2', 'p0', 'effort-small', 'effort-medium', 'effort-large', 'guidance'],
101+
defaultArea: '${{ env.OSDS_DEVS }}',
102+
parameters: '${{ env.AREA_PARAMS }}',
103+
affixes: '${{ env.AREA_AFFIXES }}',
104+
needEnvs: true,
105+
}));
106+
this.workflow.addJob('Triage Pull Requests', triageManagerJob({
107+
target: 'pull-requests',
108+
areaIsKeyword: true,
109+
defaultArea: '{"reviewers":{"teamReviewers":["aws-cdk-owners"]}}',
110+
parameters: '[{"area":"pullrequests","keywords":["pullrequestkeyword"]}]',
111+
githubToken: GitHubToken.PROJEN_GITHUB_TOKEN,
112+
}));
113+
}
114+
}

0 commit comments

Comments
 (0)