export async function postJunieWorkingStatusComment()

in src/github/operations/comments/feedback.ts [233:301]


export async function postJunieWorkingStatusComment(
    octokit: Octokit,
    context: JunieExecutionContext,
) {
    if (context.inputs.silentMode) {
        console.log('Silent mode enabled - skipping initial feedback comment');
        return;
    }

    // Check if we have an entity to comment on (issue or PR number)
    // entityNumber is required for all comment types, including review comments
    if (!context.entityNumber) {
        console.log(`Skip creating initial comment for ${context.eventName} event - no entity number`);
        return;
    }

    const {owner, name} = context.payload.repository;
    const ownerLogin = owner.login;

    const jobRunLink = createJobRunLink(ownerLogin, name, context.runId);
    const initialBody = createCommentBody(jobRunLink, context.workflow);

    // Add thumbs up reaction to the trigger comment
    await addThumbsUpToTriggerComment(octokit, context);

    try {
        let initCommentId: number | undefined;

        // Check if we should use single comment mode
        if (context.inputs.useSingleComment) {
            console.log('Single comment mode enabled - searching for existing Junie comment');
            const existingCommentId = await findExistingJunieComment(octokit, context);

            if (existingCommentId) {
                // Update existing comment
                await updateExistingComment(octokit, context, existingCommentId, initialBody, ownerLogin, name);
                initCommentId = existingCommentId;
            } else {
                // No existing comment found, create a new one
                console.log('No existing Junie comment found - creating new comment');
                initCommentId = await createNewComment(octokit, context, initialBody, ownerLogin, name);
            }
        } else {
            // Single comment mode disabled, always create new comment
            initCommentId = await createNewComment(octokit, context, initialBody, ownerLogin, name);
        }

        // Only set output if we have a comment ID
        if (initCommentId !== undefined) {
            // Save comment ID as output for later retrieval in finish-feedback step
            core.setOutput(OUTPUT_VARS.INIT_COMMENT_ID, initCommentId);
        }

        return initCommentId;
    } catch (error) {
        const entityType = context.isPR ? 'PR' : context.entityNumber ? `issue #${context.entityNumber}` : 'event';
        const repoFullName = `${ownerLogin}/${name}`;
        console.error(`❌ Failed to create/update initial feedback comment for ${entityType}:`, error);
        throw new Error(
            `❌ Failed to create/update initial feedback comment on ${repoFullName}. ` +
            `This could be due to:\n` +
            `• Insufficient token permissions (needs 'issues:write' or 'pull_requests:write' scope)\n` +
            `• GitHub API rate limits\n` +
            `• The issue or PR may be locked or deleted\n` +
            `• Network connectivity issues\n` +
            `Original error: ${error instanceof Error ? error.message : String(error)}`
        );
    }
}