Skip to content

Commit

Permalink
Use elevated actor to merge forward-mergers (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyodeAwe authored Mar 21, 2024
1 parent 9a0b5dc commit ed40519
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ 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);
initLabelChecker(app);
initReleaseDrafter(app);
initAutoMerger(app);
initRecentlyUpdated(app);
// TODO: Re-enable ForwardMerger once branch protection blocker is resolved
// initForwardMerger(app);
initForwardMerger(app);
};
9 changes: 8 additions & 1 deletion src/plugins/ForwardMerger/forward_merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -82,6 +85,10 @@ export class ForwardMerger extends OpsBotPlugin {
);
}

initNewClient(): InstanceType<typeof Octokit> {
return new Octokit({ auth: process.env.GPUTESTER_PAT });
}

async getBranches(): Promise<string[]> {
const branches = await this.context.octokit.paginate(
this.context.octokit.repos.listBranches,
Expand Down
7 changes: 7 additions & 0 deletions test/forward_merger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit ed40519

Please sign in to comment.