All files / scripts update-comment.ts

100% Statements 17/17
93.75% Branches 15/16
100% Functions 3/3
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                              7x 7x   7x 1x 1x     6x 6x   5x 5x   5x   4x 7x 1x         7x 1x   7x    
#!/usr/bin/env node
/**
 * Standalone CLI script called by the AI agent to update PR comment threads.
 * Fails silently — always exits 0.
 *
 * Usage:
 *   node update-comment.js --thread-id 123 --status Fixed
 *   node update-comment.js --thread-id 123 --comment-id 456 --content "Updated text"
 */
 
import { AdoClient } from '../ado-api/client';
import { updateThreadStatus, updateCommentContent } from '../ado-api/comments';
import { parseArgs, loadAdoEnv } from '../utils/args';
 
async function main(): Promise<void> {
    const args = parseArgs(process.argv.slice(2));
    const threadId = parseInt(args['threadId'] ?? '0', 10);
 
    if (!threadId) {
        console.warn('update-comment: --thread-id is required');
        return;
    }
 
    const env = loadAdoEnv('update-comment');
    if (!env) return;
 
    const client = new AdoClient({ collectionUri: env.collectionUri, project: env.project, token: env.token, authType: env.authType });
    const prIdNum = parseInt(env.prId, 10);
 
    await updateThreadStatus(client, env.repository, prIdNum, threadId, args['status'] ?? 'Fixed');
 
    const commentId = parseInt(args['commentId'] ?? '0', 10);
    if (args['content'] && commentId > 0) {
        await updateCommentContent(client, env.repository, prIdNum, threadId, commentId, args['content']);
    }
}
 
// Always exit 0 — silent failure behaviour
main().catch((err) => {
    console.warn(`update-comment: ${err instanceof Error ? err.message : String(err)}`);
}).finally(() => {
    process.exit(0);
});