Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
approve format
Browse files Browse the repository at this point in the history
  • Loading branch information
shikajiro committed Sep 25, 2023
1 parent ee6f2dc commit cbd1da3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
needToSendApproveMention, latestReviewer, needToMention,
} from "./modules/github";
import {
buildChatworkErrorMessage, buildChatworkPostMentionMessage,
buildChatworkErrorMessage, buildChatworkPostApproveMessage, buildChatworkPostMentionMessage,
buildChatworkPostMessage,
ChatworkRepositoryImpl,
} from "./modules/chatwork";
Expand Down Expand Up @@ -209,21 +209,23 @@ export const execApproveMention = async (
}

const info = pickupInfoFromGithubPayload(payload);
const approveOwner = payload.sender?.login;
const message = [
`[To:${account.account_id}] (cracker) has been approved ${info.url} ${info.title} by ${approveOwner}.`,
info.body || "",
].join("\n");
const message = buildChatworkPostApproveMessage(
[account.account_id],
info.title,
info.url,
info.body,
payload.sender?.login
)
const { apiToken} = allInputs;

const postSlackResult = await chatworkClient.postToChatwork(
const postResult = await chatworkClient.postToChatwork(
apiToken,
account.room_id,
message
);

core.info(
["postToSlack result", JSON.stringify({ postSlackResult }, null, 2)].join(
["postToSlack result", JSON.stringify({ postSlackResult: postResult }, null, 2)].join(
"\n"
)
);
Expand Down
11 changes: 11 additions & 0 deletions src/modules/chatwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export const buildChatworkPostMentionMessage = (
return `${mentionBlock}\n[info][title]${senderName}がメンションしました[/title] ${issueTitle}\n${commentLink}\n[hr]\n${githubBody}\n[/info]`;
};

export const buildChatworkPostApproveMessage = (
chatworkIdsForMention: string[],
issueTitle: string,
commentLink: string,
githubBody: string,
senderName: string
): string => {
const mentionBlock = chatworkIdsForMention.map((id) => `[To:${id}]`).join(" ");
return `${mentionBlock}\n[info][title](cracker)${senderName}が承認しました[/title] ${issueTitle}\n${commentLink}\n[hr]\n${githubBody}\n[/info]`;
};

export const buildChatworkPostMessage = (
issueTitle: string,
commentLink: string,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const latestReviewer = async (repoName: string, prNumber: number, repoTok
export const pickupInfoFromGithubPayload = (
payload: WebhookPayload
): {
body: string | null;
body: string;
title: string;
url: string;
senderName: string;
Expand Down

0 comments on commit cbd1da3

Please sign in to comment.