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