Skip to content

Commit

Permalink
Fix comment search
Browse files Browse the repository at this point in the history
  • Loading branch information
Holi0317 committed Feb 18, 2024
1 parent 33c7efd commit 3630bcd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"@octokit/auth-app": "^6.0.3",
"octokit": "^3.1.2",
"parse-git-diff": "^0.0.15"
"parse-git-diff": "^0.0.15",
"zod": "^3.22.4"
}
}
4 changes: 3 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/octo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { App, type Octokit } from "octokit";
import type { PullRequest } from "@octokit/webhooks-types";
import { genDiffSummary } from "./diff";
import { unwrap } from "./utils";
import { z } from "zod";

const ViewerSchema = z.object({
viewer: z.object({
databaseId: z.number(),
}),
});

/**
* Find PR comment number to edit, if we have already left a comment there.
Expand All @@ -10,7 +17,10 @@ import { unwrap } from "./utils";
* suggesting we should create a new comment.
*/
async function findPRComment(octo: Octokit, pr: PullRequest) {
const me = await octo.request("GET /user");
// IDK how to get the app's user ID with rest API. But this is trivial with
// graphQL
const viewerQuery = await octo.graphql(`query { viewer { databaseId } }`);
const viewer = ViewerSchema.parse(viewerQuery);

// Only listing the first page for pr comments. This endpoint sorts comments
// in ascending order of comment number (which means commenting order/creation
Expand All @@ -26,7 +36,7 @@ async function findPRComment(octo: Octokit, pr: PullRequest) {
);

for (const comment of comments.data) {
if (comment.user?.id === me.data.id) {
if (comment.user?.id === viewer.viewer.databaseId) {
return comment.id;
}
}
Expand Down

0 comments on commit 3630bcd

Please sign in to comment.