Skip to content

Commit

Permalink
chore: pr labeler workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc committed Feb 28, 2025
1 parent b580d1e commit 1e2abd3
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitattributes

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

21 changes: 21 additions & 0 deletions .github/workflows/pr-labeler.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.

2 changes: 2 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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';
import { PrLabeler } from './projenrc/pr-labeler';

// 5.7 sometimes gives a weird error in `ts-jest` in `@aws-cdk/cli-lib-alpha`
// https://github.com/microsoft/TypeScript/issues/60159
Expand Down Expand Up @@ -1407,5 +1408,6 @@ new CodeCovWorkflow(repo, {
});

new IssueLabeler(repo);
new PrLabeler(repo);

repo.synth();
10 changes: 1 addition & 9 deletions projenrc/issue-labeler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, github } from 'projen';
import { JobPermission } from 'projen/lib/github/workflows-model';
import { TypeScriptProject } from 'projen/lib/typescript';
import { GitHubToken, stringifyList } from './util';

const OSDS_DEVS = ['ashishdhingra', 'khushail', 'hunhsieh'];
const AREA_AFFIXES = ['@aws-cdk/'];
Expand All @@ -13,11 +14,6 @@ const AREA_PARAMS = [
{ 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
*/
Expand All @@ -41,10 +37,6 @@ interface TriageManagerOptions {
githubToken?: GitHubToken;
}

function stringifyList(list: string[]) {
return `[${list.join('|')}]`;
}

function triageManagerJob(triageManagerOptions: TriageManagerOptions) {
return {
name: 'Triage Manager',
Expand Down
56 changes: 56 additions & 0 deletions projenrc/pr-labeler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Component, github } from 'projen';
import { JobPermission } from 'projen/lib/github/workflows-model';
import { TypeScriptProject } from 'projen/lib/typescript';
import { GitHubToken, stringifyList } from './util';

/**
* See https://github.com/cdklabs/pr-triage-manager
*/
interface PrLabelerOptions {
/**
* @default GitHubToken.GITHUB_TOKEN
*/
githubToken?: GitHubToken;
priorityLabels?: string[];
classificationLabels?: string[];
onPulls?: boolean;
}

function prLabelerJob(prLabelerOptions: PrLabelerOptions = {}) {
return {
name: 'PR Labeler',
runsOn: ['aws-cdk_ubuntu-latest_4-core'],
permissions: { issues: JobPermission.WRITE, pullRequests: JobPermission.WRITE },
steps: [
{
name: 'PR Labeler',
uses: 'cdklabs/pr-triage-manager@main',
with: {
'github-token': `\${{ ${prLabelerOptions.githubToken ?? 'secrets.GITHUB_TOKEN'} }}`,
'priority-labels': prLabelerOptions.priorityLabels ? stringifyList(prLabelerOptions.priorityLabels) : undefined,
'classification-labels': prLabelerOptions.classificationLabels ? stringifyList(prLabelerOptions.classificationLabels) : undefined,
'on-pulls': prLabelerOptions.onPulls,
},
},
],
};
}

export class PrLabeler 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('pr-labeler');
this.workflow.on({
pullRequestTarget: { types: ['opened', 'edited', 'reopened'] },
});

this.workflow.addJob('copy-labels', prLabelerJob());
}
}
8 changes: 8 additions & 0 deletions projenrc/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum GitHubToken {
GITHUB_TOKEN = 'secrets.GITHUB_TOKEN',
PROJEN_GITHUB_TOKEN = 'secrets.PROJEN_GITHUB_TOKEN',
}

export function stringifyList(list: string[]) {
return `[${list.join('|')}]`;
}

0 comments on commit 1e2abd3

Please sign in to comment.