Skip to content

Commit

Permalink
Return tipResult from handleTipRequest, extract result to var
Browse files Browse the repository at this point in the history
  • Loading branch information
rzadp committed Feb 16, 2024
1 parent a2fdf04 commit a0004d2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bot-handle-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { updateBalance } from "./balance";
import { matrixNotifyOnFailure, matrixNotifyOnNewTip } from "./matrix";
import { recordTip } from "./metrics";
import { tipUser } from "./tip";
import { GithubReactionType, State, TipRequest } from "./types";
import { GithubReactionType, State, TipRequest, TipResult } from "./types";
import { formatTipSize, getTipSize, parseContributorAccount } from "./util";

type OnIssueCommentResult = { success: true; message: string } | { success: false; errorMessage: string };
type OnIssueCommentResult = { success: true; message: string, tipResult: Extract<TipResult,{success: true}> } | { success: false; errorMessage: string };

export const handleIssueCommentCreated = async (state: State, event: IssueCommentCreatedEvent): Promise<void> => {
const [botMention] = event.comment.body.split(" ") as (string | undefined)[];
Expand Down Expand Up @@ -47,8 +47,9 @@ export const handleIssueCommentCreated = async (state: State, event: IssueCommen

await githubEmojiReaction("eyes");
await matrixNotifyOnNewTip(state.matrix, event);
let result: OnIssueCommentResult
try {
const result = await handleTipRequest(state, event, tipRequester, octokitInstance);
result = await handleTipRequest(state, event, tipRequester, octokitInstance);
if (result.success) {
await githubComment(result.message);
await githubEmojiReaction("rocket");
Expand All @@ -64,6 +65,7 @@ export const handleIssueCommentCreated = async (state: State, event: IssueCommen
);
await githubEmojiReaction("confused");
await matrixNotifyOnFailure(state.matrix, event, { tagMaintainers: true });
return
}
};

Expand Down Expand Up @@ -141,6 +143,7 @@ export const handleTipRequest = async (
if (tipResult.success) {
return {
success: true,
tipResult,
message: `@${tipRequester} A referendum for a ${formatTipSize(
tipRequest,
)} tip was successfully submitted for @${contributorLogin} (${contributorAccount.address} on ${
Expand Down

0 comments on commit a0004d2

Please sign in to comment.