Skip to content

Commit

Permalink
fix: replace comment post with SDK function
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jan 6, 2025
1 parent 64bf798 commit 3fcb7e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
9 changes: 2 additions & 7 deletions src/handlers/query-user.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { postComment } from "@ubiquity-os/plugin-sdk";
import { Context } from "../types/context";

async function checkUserAccess(context: Context, username: string) {
Expand All @@ -23,7 +24,6 @@ async function checkUserAccess(context: Context, username: string) {
export async function queryUser(context: Context, username: string) {
const {
octokit,
payload,
adapters: { supabase },
config,
} = context;
Expand Down Expand Up @@ -54,12 +54,7 @@ User information for ${username} was not found.
body.push(`| Access | \`\`\`${Array.isArray(access.labels) ? access.labels.join(", ") : JSON.stringify(access.labels, null, 2)}\`\`\` |`);
}
}
await octokit.rest.issues.createComment({
body: body.join("\n"),
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
});
await postComment(context, context.logger.info(body.join("\n")), { raw: true, updateComment: true });
} catch (e) {
throw context.logger.fatal(`Could not query user ${username}.`, { e });
}
Expand Down
19 changes: 10 additions & 9 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { postComment } from "@ubiquity-os/plugin-sdk";
import { CommanderError } from "commander";
import { CommandParser } from "./handlers/command-parser";
import { Context } from "./types/context";
import { queryUser } from "./handlers/query-user";

export async function run(context: Context) {
const { octokit, logger, eventName, payload, command } = context;
const { logger, eventName, payload, command } = context;
if (command) {
await queryUser(context, command.parameters.username);
return;
Expand All @@ -20,21 +21,21 @@ export async function run(context: Context) {
} catch (e) {
if (e instanceof CommanderError) {
if (e.code !== "commander.unknownCommand") {
context.logger.fatal("Commander error", { e });
await octokit.rest.issues.createComment({
body: `\`\`\`
await postComment(
context,
context.logger.error(
`\`\`\`
Failed to run command-query-user.
${e.message}
${commandParser.helpInformation()}
\`\`\``,
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.issue.number,
});
{ e }
)
);
}
} else {
context.logger.error("error", { e });
context.logger.fatal("error", { e });
throw e;
}
}
Expand Down

0 comments on commit 3fcb7e7

Please sign in to comment.