Skip to content

Commit

Permalink
fix: login of null issue
Browse files Browse the repository at this point in the history
  • Loading branch information
roseline124 committed Jul 4, 2024
1 parent 9148f52 commit 74fdf95
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
19 changes: 9 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43389,30 +43389,29 @@ async function handleReviewSubmitted(octokit, event, reviewers) {
for (const comment of submittedReviewComments) {
if (!comment.body)
continue;
const commentAuthor = reviewers.reviewers.find((rev) => rev.githubName === comment.user.login);
const message = (0, generate_comment_1.generateComment)(commentAuthor?.name ?? comment.user.login, comment.body);
const commentAuthor = reviewers.reviewers.find((rev) => rev.githubName === comment.user?.login);
const message = (0, generate_comment_1.generateComment)(commentAuthor?.name ?? comment.user?.login ?? "bot", comment.body);
core.info("Message constructed:");
core.debug(message);
await (0, slack_1.postThreadMessage)(ts, message);
}
let lastMessage = "";
const commentAuthor = reviewers.reviewers.find((rev) => rev.githubName === review.user.login);
const commentAuthor = reviewers.reviewers.find((rev) => rev.githubName === review.user?.login);
const commentAuthorName = commentAuthor?.name ?? review.user?.login ?? "bot";
const assignee = reviewers.reviewers.find((rev) => rev.githubName === pull_request.assignee?.login);
const assigneeMention = assignee ? `\n<@${assignee.slackId}>` : "";
if (review.state === "approved") {
lastMessage = (0, generate_comment_1.generateComment)(commentAuthor?.name ?? review.user.login, ":white_check_mark: LGTM\n" + (review.body ?? ""));
lastMessage = (0, generate_comment_1.generateComment)(commentAuthorName, ":white_check_mark: LGTM\n" + (review.body ?? "") + assigneeMention);
}
else if (review.state === "changes_requested") {
const requestChangeMessage = i18next_1.default.t("request_changes");
lastMessage = (0, generate_comment_1.generateComment)(commentAuthor?.name ?? review.user.login, `:pray: ${requestChangeMessage}\n` + (review.body ?? ""));
lastMessage = (0, generate_comment_1.generateComment)(commentAuthorName, `:pray: ${requestChangeMessage}\n` + (review.body ?? "") + assigneeMention);
}
else {
if (review.body) {
lastMessage = (0, generate_comment_1.generateComment)(commentAuthor?.name ?? review.user.login, review.body);
lastMessage = (0, generate_comment_1.generateComment)(commentAuthorName, review.body + assigneeMention);
}
}
const assignee = reviewers.reviewers.find((rev) => rev.githubName === pull_request.assignee.login);
if (assignee) {
lastMessage += `\n<@${assignee.slackId}>`;
}
await (0, slack_1.postThreadMessage)(ts, lastMessage);
}
async function listReviewComments(octokit, owner, repo, prNumber) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions src/handlers/handle-review-submitted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export async function handleReviewSubmitted(
for (const comment of submittedReviewComments) {
if (!comment.body) continue;
const commentAuthor = reviewers.reviewers.find(
(rev) => rev.githubName === comment.user.login
(rev) => rev.githubName === comment.user?.login
);
const message = generateComment(
commentAuthor?.name ?? comment.user.login,
commentAuthor?.name ?? comment.user?.login ?? "bot",
comment.body
);
core.info("Message constructed:");
Expand All @@ -58,36 +58,34 @@ export async function handleReviewSubmitted(

let lastMessage: string = "";
const commentAuthor = reviewers.reviewers.find(
(rev) => rev.githubName === review.user.login
(rev) => rev.githubName === review.user?.login
);

const commentAuthorName = commentAuthor?.name ?? review.user?.login ?? "bot";
const assignee = reviewers.reviewers.find(
(rev) => rev.githubName === pull_request.assignee?.login
);
const assigneeMention = assignee ? `\n<@${assignee.slackId}>` : "";
if (review.state === "approved") {
lastMessage = generateComment(
commentAuthor?.name ?? review.user.login,
":white_check_mark: LGTM\n" + (review.body ?? "")
commentAuthorName,
":white_check_mark: LGTM\n" + (review.body ?? "") + assigneeMention
);
} else if (review.state === "changes_requested") {
const requestChangeMessage = i18n.t("request_changes");
lastMessage = generateComment(
commentAuthor?.name ?? review.user.login,
`:pray: ${requestChangeMessage}\n` + (review.body ?? "")
commentAuthorName,
`:pray: ${requestChangeMessage}\n` + (review.body ?? "") + assigneeMention
);
} else {
if (review.body) {
lastMessage = generateComment(
commentAuthor?.name ?? review.user.login,
review.body
commentAuthorName,
review.body + assigneeMention
);
}
}

const assignee = reviewers.reviewers.find(
(rev) => rev.githubName === pull_request.assignee.login
);
if (assignee) {
lastMessage += `\n<@${assignee.slackId}>`;
}

await postThreadMessage(ts, lastMessage);
}

Expand Down

0 comments on commit 74fdf95

Please sign in to comment.