-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: issue labeler workflow #118
Changes from 7 commits
f7885c2
3005419
1f69481
5943304
0c8f184
0a86b99
3163d4e
6c5bf3f
cb4775e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this works? In the aws-cdk repo this is configured as a string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missed a cnversion step :( |
||
includedLabels: ['needs-triage'], | ||
excludedLabels: ['p1', 'p2', 'p0', 'effort-small', 'effort-medium', 'effort-large', 'guidance'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
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, | ||
})); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come one jobs needs it and one doesn't? I see its configured on the workflow level in the aws-cdk repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its configured on the workflow level, yes. but it doesn't look like the other job uses those env variables, even if it might have access to it. because of that i think its fine to have the env variables be configured to the job level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't add the guidance step, which would utilize the workflow level env vars (probs why they put it on the workflow level).
however, projen doesn't currently support workflow-level env variables, so if we were to include the guidance job i'd just add
needEnvs: true
to that step for now (until we have projen support).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followup then - do we not need the guidance step?