All files / scripts delete-comment.ts

100% Statements 14/14
91.66% Branches 11/12
100% Functions 3/3
100% Lines 13/13

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                            6x 6x 6x   6x 2x 2x     4x 4x   3x 3x       6x 1x   6x    
#!/usr/bin/env node
/**
 * Standalone CLI script called by the AI agent to delete PR comments.
 * Fails silently — always exits 0.
 *
 * Usage:
 *   node delete-comment.js --thread-id 123 --comment-id 456
 */
 
import { AdoClient } from '../ado-api/client';
import { deleteComment } 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);
    const commentId = parseInt(args['commentId'] ?? '0', 10);
 
    if (!threadId || !commentId) {
        console.warn('delete-comment: --thread-id and --comment-id are required');
        return;
    }
 
    const env = loadAdoEnv('delete-comment');
    if (!env) return;
 
    const client = new AdoClient({ collectionUri: env.collectionUri, project: env.project, token: env.token, authType: env.authType });
    await deleteComment(client, env.repository, parseInt(env.prId, 10), threadId, commentId);
}
 
// Always exit 0 — silent failure behaviour
main().catch((err) => {
    console.warn(`delete-comment: ${err instanceof Error ? err.message : String(err)}`);
}).finally(() => {
    process.exit(0);
});