Skip to content
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

Merged
merged 9 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions .github/workflows/issue-label-assign.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AdcPublishing } from './projenrc/adc-publishing';
import { BundleCli } from './projenrc/bundle';
import { CodeCovWorkflow } from './projenrc/codecov';
import { ESLINT_RULES } from './projenrc/eslint';
import { IssueLabeler } from './projenrc/issue-labeler';
import { JsiiBuild } from './projenrc/jsii';
import { RecordPublishingTimestamp } from './projenrc/record-publishing-timestamp';
import { S3DocsPublishing } from './projenrc/s3-docs-publishing';
Expand Down Expand Up @@ -1339,4 +1340,6 @@ new CodeCovWorkflow(repo, {
packages: [cli.name],
});

new IssueLabeler(repo);

repo.synth();
114 changes: 114 additions & 0 deletions projenrc/issue-labeler.ts
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;
Copy link
Contributor

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.

Copy link
Contributor Author

@kaizencc kaizencc Feb 26, 2025

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

Copy link
Contributor Author

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).

Copy link
Contributor

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?

/**
* @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'],
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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'],
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
}));
}
}
Loading