Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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.

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 @@ -8,6 +8,7 @@ import { CodeCovWorkflow } from './projenrc/codecov';
import { ESLINT_RULES } from './projenrc/eslint';
import { IssueLabeler } from './projenrc/issue-labeler';
import { JsiiBuild } from './projenrc/jsii';
import { PrLabeler } from './projenrc/pr-labeler';
import { RecordPublishingTimestamp } from './projenrc/record-publishing-timestamp';
import { S3DocsPublishing } from './projenrc/s3-docs-publishing';

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('|')}]`;
}
Loading