diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 84e6130..8887f38 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -47,3 +47,4 @@ jobs: APP_ID: ${{ secrets.APP_ID }} WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }} PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} + GPUTESTER_PAT: ${{ secrets.GPUTESTER_PAT }} diff --git a/serverless.yaml b/serverless.yaml index dd18508..c4d7e96 100644 --- a/serverless.yaml +++ b/serverless.yaml @@ -18,6 +18,7 @@ provider: APP_ID: ${env:APP_ID} WEBHOOK_SECRET: ${env:WEBHOOK_SECRET} PRIVATE_KEY: ${env:PRIVATE_KEY} + GPUTESTER_PAT: ${env:GPUTESTER_PAT} iam: role: statements: diff --git a/src/index.ts b/src/index.ts index bcccc28..5318da1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,7 @@ import { initBranchChecker } from "./plugins/BranchChecker"; import { initLabelChecker } from "./plugins/LabelChecker"; import { initRecentlyUpdated } from "./plugins/RecentlyUpdated"; import { initReleaseDrafter } from "./plugins/ReleaseDrafter"; -// import { initForwardMerger } from "./plugins/ForwardMerger"; +import { initForwardMerger } from "./plugins/ForwardMerger"; export = (app: Probot) => { initBranchChecker(app); @@ -28,6 +28,5 @@ export = (app: Probot) => { initReleaseDrafter(app); initAutoMerger(app); initRecentlyUpdated(app); - // TODO: Re-enable ForwardMerger once branch protection blocker is resolved - // initForwardMerger(app); + initForwardMerger(app); }; diff --git a/src/plugins/ForwardMerger/forward_merger.ts b/src/plugins/ForwardMerger/forward_merger.ts index 70fe574..500a4b9 100644 --- a/src/plugins/ForwardMerger/forward_merger.ts +++ b/src/plugins/ForwardMerger/forward_merger.ts @@ -19,6 +19,8 @@ import { PayloadRepository } from "../../types"; import { isVersionedBranch, getVersionFromBranch } from "../../shared"; import { basename } from "path"; import { Context } from "probot"; +import { Octokit } from "@octokit/rest" + export class ForwardMerger extends OpsBotPlugin { context: Context; @@ -61,7 +63,8 @@ export class ForwardMerger extends OpsBotPlugin { try { this.logger.info("Merging PR"); - await this.context.octokit.pulls.merge({ + const gpuTesterClient = this.initNewClient(); // see https://github.com/rapidsai/ops/issues/3159#issue-2198146626 for why we're initializing a new client. + await gpuTesterClient.pulls.merge({ owner: this.repo.owner.login, repo: this.repo.name, pull_number: pr.number, @@ -82,6 +85,10 @@ export class ForwardMerger extends OpsBotPlugin { ); } + initNewClient(): InstanceType { + return new Octokit({ auth: process.env.GPUTESTER_PAT }); + } + async getBranches(): Promise { const branches = await this.context.octokit.paginate( this.context.octokit.repos.listBranches, diff --git a/test/forward_merger.test.ts b/test/forward_merger.test.ts index 07f49cf..6b612f1 100644 --- a/test/forward_merger.test.ts +++ b/test/forward_merger.test.ts @@ -126,6 +126,9 @@ describe("Forward Merger", () => { mockCreatePR.mockResolvedValue(pr); mockMerge.mockResolvedValue(true); + const mockNewClient = jest.fn().mockName("initNewClient"); + mockNewClient.mockReturnValue({ pulls: { merge: mockMerge } }); + forwardMerger.initNewClient = mockNewClient; const mockIssueComment = jest .fn() .mockName("issueComment") @@ -162,7 +165,11 @@ describe("Forward Merger", () => { .mockReturnValue(nextBranch); const pr = { data: { number: 1, head: { sha: 123456 } } }; mockCreatePR.mockResolvedValue(pr); + mockMerge.mockRejectedValueOnce(new Error("error")); + const mockNewClient = jest.fn().mockName("initNewClient"); + mockNewClient.mockReturnValue({ pulls: { merge: mockMerge } }); + forwardMerger.initNewClient = mockNewClient; const mockIssueComment = jest .fn() .mockName("issueComment")