Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proper user assign on pull-request body edit #121

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