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 check membership & skip events #224

Merged
merged 2 commits into from
Jul 24, 2023
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
28 changes: 14 additions & 14 deletions src/bot/events/onIssueCommentCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ export const onIssueCommentCreated: WebhookHandler<"issue_comment.created"> = as
try {
const commands: (ParsedCommand | SkipEvent)[] = [];

if (!(await isRequesterAllowed(ctx, octokit, requester))) {
return getError("Requester could not be detected as a member of an allowed organization.");
}

for (const line of getLines(comment.body)) {
const parsedCommand = await parsePullRequestBotCommandLine(line, ctx, pr.repo);

if (parsedCommand instanceof Error) {
return getError(parsedCommand.message);
}

commands.push(parsedCommand);
}

if (commands.length === 0) {
return new SkipEvent("No commands found within a comment");
}

for (const parsedCommand of commands) {
logger.debug({ parsedCommand }, "Processing parsed command");

if (parsedCommand instanceof SkipEvent) {
const skip = getMetricsPrData("skip", eventName, pr, parsedCommand.reason);
counters.commandsRun.inc({ ...skip });
logger.debug(
{ command: comment.body, payload, ...skip },
`Skip command with reason: "${parsedCommand.reason}"`,
);
} else {
commands.push(parsedCommand);
}
}

if (commands.length === 0) {
return new SkipEvent("No commands found within a comment");
}

if (!(await isRequesterAllowed(ctx, octokit, requester))) {
return getError("Requester could not be detected as a member of an allowed organization.");
}

for (const parsedCommand of commands) {
logger.debug({ parsedCommand }, "Processing parsed command");

if (parsedCommand instanceof HelpCommand) {
await createComment(ctx, octokit, {
Expand Down
11 changes: 10 additions & 1 deletion src/bot/setupEvent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Probot } from "probot";

import { extractPullRequestData } from "src/bot/parse/extractPullRequestData";
import { FinishedEvent, PullRequestError, WebhookEventPayload, WebhookEvents, WebhookHandler } from "src/bot/types";
import {
FinishedEvent,
PullRequestError,
SkipEvent,
WebhookEventPayload,
WebhookEvents,
WebhookHandler,
} from "src/bot/types";
import { createComment, getOctokit, updateComment } from "src/github";
import { logger as parentLogger } from "src/logger";
import { counters, getMetricsPrData, summaries } from "src/metrics";
Expand Down Expand Up @@ -55,6 +62,8 @@ export const setupEvent = <E extends WebhookEvents>(
const ok = getMetricsPrData("ok", eventName, prData, result.comment.body);
counters.commandsRun.inc({ ...ok, repo: result.pr.repo, pr: result.pr.number });
eventLogger.info({ result }, "Finished command");
} else if (result instanceof SkipEvent) {
eventLogger.debug({ result }, "Skipping command");
} else {
const message = "Unknown result type";
const error = getMetricsPrData("error", eventName, prData, message);
Expand Down
2 changes: 1 addition & 1 deletion src/bot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type WebhookHandler<E extends WebhookEvents> = (
ctx: Context,
octokit: ExtendedOctokit,
event: WebhookEventPayload<E>,
) => Promise<PullRequestError | SkipEvent | FinishedEvent>;
) => Promise<PullRequestError | SkipEvent | FinishedEvent | unknown>;
Copy link
Contributor

@mutantcornholio mutantcornholio Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line troubles me a bit, but if typechecks are passing, we can get back to it later


export class SkipEvent {
constructor(public reason: string = "") {}
Expand Down
Loading