async function createNewComment()

in src/github/operations/comments/feedback.ts [308:345]


async function createNewComment(
    octokit: Octokit,
    context: JunieExecutionContext,
    body: string,
    ownerLogin: string,
    repoName: string,
): Promise<number | undefined> {
    let response;

    // Different comment APIs based on context type
    if (isPullRequestReviewCommentEvent(context)) {
        // For review comments (code-level comments), create a reply to the review comment
        response = await octokit.rest.pulls.createReplyForReviewComment({
            owner: ownerLogin,
            repo: repoName,
            pull_number: context.entityNumber!,
            comment_id: context.payload.comment.id,
            body: body,
        });
    } else if (context.entityNumber) {
        // For issue comments and PR comments (conversation-level), use issues API
        // Note: GitHub treats PR comments as issue comments in the API
        response = await octokit.rest.issues.createComment({
            owner: ownerLogin,
            repo: repoName,
            issue_number: context.entityNumber,
            body: body,
        });
    } else {
        // No entity number means this is an automated event (workflow_dispatch, schedule, etc.)
        // These don't have a specific issue/PR to comment on
        console.log(`Skip creating initial comment for ${context.eventName} event`);
        return undefined;
    }

    console.log(`Created initial comment with ID: ${response.data.id}`);
    return response.data.id;
}