Skip to content

Commit

Permalink
fix comment on merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jobenjada committed Oct 3, 2024
1 parent ef55d17 commit 3ecd191
Showing 1 changed file with 50 additions and 26 deletions.
76 changes: 50 additions & 26 deletions lib/github/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,37 @@ export const processAndComment = async ({
issueNumber: number;
ossGgRepoId: string;
}) => {
const user = await processUserPoints({
installationId: context.payload.installation?.id!,
prAuthorGithubId: pullRequest.user.id,
prAuthorUsername: pullRequest.user.login,
avatarUrl: pullRequest.user.avatar_url,
points,
url: pullRequest.html_url,
repoId: ossGgRepoId,
comment: "",
});
console.log(`Starting processAndComment for PR #${issueNumber} in ${owner}/${repo}`);

try {
const user = await processUserPoints({
installationId: context.payload.installation?.id!,
prAuthorGithubId: pullRequest.user.id,
prAuthorUsername: pullRequest.user.login,
avatarUrl: pullRequest.user.avatar_url,
points,
url: pullRequest.html_url,
repoId: ossGgRepoId,
comment: "",
});

const comment = `Awarding ${user.login}: ${points} points 🕹️ Well done! Check out your new contribution on [oss.gg/${user.login}](https://oss.gg/${user.login})`;
console.log(`User points processed for ${user.login}`);

// Post comment on the issue or pull request
postComment({
installationId: context.payload.installation?.id!,
body: comment,
issueNumber: issueNumber,
repo,
owner,
});
const comment = `Awarding ${user.login}: ${points} points 🕹️ Well done! Check out your new contribution on [oss.gg/${user.login}](https://oss.gg/${user.login})`;

await postComment({
installationId: context.payload.installation?.id!,
body: comment,
issueNumber: issueNumber,
repo,
owner,
});

console.log(`Comment posted successfully for PR #${issueNumber}`);
} catch (error) {
console.error(`Error in processAndComment for PR #${issueNumber}:`, error);
throw error; // Re-throw the error to be handled by the caller
}
};

export const processUserPoints = async ({
Expand Down Expand Up @@ -152,14 +162,28 @@ export const processUserPoints = async ({
return user;
};

export const postComment = async ({ installationId, body, issueNumber, repo, owner }: TPostComment) => {
// Update the postComment function to return a promise and add logging
export const postComment = async ({
installationId,
body,
issueNumber,
repo,
owner,
}: TPostComment): Promise<void> => {
console.log(`Attempting to post comment on ${owner}/${repo}#${issueNumber}`);
const octokit = getOctokitInstance(installationId!);
await octokit.issues.createComment({
body,
issue_number: issueNumber,
repo,
owner,
});
try {
await octokit.issues.createComment({
body,
issue_number: issueNumber,
repo,
owner,
});
console.log(`Comment posted successfully on ${owner}/${repo}#${issueNumber}`);
} catch (error) {
console.error(`Error posting comment on ${owner}/${repo}#${issueNumber}:`, error);
throw error;
}
};

export const filterValidLabels = (labels: any[]) =>
Expand Down

0 comments on commit 3ecd191

Please sign in to comment.