Skip to content

Commit

Permalink
Merge pull request #121 from gentlementlegen/fix/pr-edit-assign
Browse files Browse the repository at this point in the history
fix: proper user assign on pull-request body edit
  • Loading branch information
gentlementlegen authored Jan 14, 2025
2 parents 8544719 + 516b721 commit 2a85f91
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/handlers/user-start-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function userPullRequest(context: Context<"pull_request.opened" | "
} as unknown as Context<"issue_comment.created">["payload"]["issue"];
context.payload = Object.assign({ issue: issueWithComment }, context.payload);
try {
return await start(context, issueWithComment, payload.sender, []);
return await start(context, issueWithComment, pull_request.user ?? payload.sender, []);
} catch (error) {
context.logger.info("The task could not be started, closing linked pull-request.", { pull_request });
await closePullRequest(context, { number: pull_request.number });
Expand Down
2 changes: 1 addition & 1 deletion src/utils/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export async function addAssignees(context: Context, issueNo: number, assignees:
assignees,
});
} catch (e: unknown) {
throw new Error(context.logger.error("Adding the assignee failed", { assignee: assignees, issueNo, error: e as Error }).logMessage.raw);
throw context.logger.error("Adding the assignee failed", { assignee: assignees, issueNo, error: e as Error });
}

await confirmMultiAssignment(context, issueNo, assignees);
Expand Down
60 changes: 60 additions & 0 deletions tests/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,64 @@ describe("Collaborator tests", () => {
},
});
});

it("should assign the author of the pull-request and not the sender of the edit", async () => {
db.users.create({
id: 3,
login: "ubiquity-os-sender",
role: "admin",
});
const issue = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 3 } } }) as unknown as PayloadSender;
const context = createContext(issue, sender, "") as Context<"pull_request.edited">;
context.eventName = "pull_request.edited";
context.payload.pull_request = {
html_url: "https://github.com/ubiquity-os-marketplace/command-start-stop",
number: 1,
user: {
id: 1,
login: "ubiquity-os-author",
},
} as unknown as Context<"pull_request.edited">["payload"]["pull_request"];
context.octokit = {
graphql: {
paginate: jest.fn(() =>
Promise.resolve({
repository: {
pullRequest: {
closingIssuesReferences: {
nodes: [
{
assignees: {
nodes: [],
},
labels: {
nodes: [{ name: "Time: <1 Hour" }],
},
},
],
},
},
},
})
),
},
} as unknown as Context<"pull_request.edited">["octokit"];

jest.unstable_mockModule("@supabase/supabase-js", () => ({
createClient: jest.fn(),
}));
jest.unstable_mockModule("../src/adapters", () => ({
createAdapters: jest.fn(),
}));
const start = jest.fn();
jest.unstable_mockModule("../src/handlers/shared/start", () => ({
start,
}));
const { startStopTask } = await import("../src/plugin");
await startStopTask(context);
// Make sure the author is the one who starts and not the sender who modified the comment
expect(start).toHaveBeenCalledWith(expect.anything(), expect.anything(), { id: 1, login: "ubiquity-os-author" }, []);
start.mockReset();
});
});

0 comments on commit 2a85f91

Please sign in to comment.