Skip to content

Commit

Permalink
chore: update automerge.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
xiehan authored Oct 19, 2023
1 parent 00cf388 commit cbfeeee
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions projenrc/automerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { javascript } from "projen";
import { JobPermission } from "projen/lib/github/workflows-model";

/**
* Merges PRs with the "automerge" label
* Enables GitHub's built-in automerge for PRs with the "automerge" label
*/
export class AutoMerge {
export class Automerge {
constructor(project: javascript.NodeProject) {
const workflow = project.github?.addWorkflow("automerge");

if (!workflow) throw new Error("no workflow defined");

workflow.on({
pullRequest: {
pullRequestTarget: {
types: [
"opened",
"labeled",
Expand All @@ -29,6 +29,7 @@ export class AutoMerge {

(workflow.concurrency as any) = "${{ github.workflow }}-${{ github.ref }}";

const maintainerStatuses = `fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]')`;
workflow.addJobs({
automerge: {
runsOn: ["ubuntu-latest"],
Expand All @@ -39,7 +40,8 @@ export class AutoMerge {
uses: "actions/checkout@v3",
},
{
name: "Turn on automerge for this PR",
name: "Turn on automerge for this PR by a trusted user or bot",
if: `github.event.pull_request.user.login == 'team-tf-cdk' || contains(${maintainerStatuses}, github.event.pull_request.author_association) || github.actor == 'dependabot[bot]`,
run: "gh pr merge --auto --squash ${{ github.event.pull_request.number }}",
env: {
GH_TOKEN: "${{ secrets.PROJEN_GITHUB_TOKEN }}",
Expand Down

0 comments on commit cbfeeee

Please sign in to comment.