#!/usr/bin/env node

// Add a comment to a Linear issue
// Usage: linear-comment.js <identifier> <body>

import { getClient } from "./lib.js";

const args = process.argv.slice(2);
const identifier = args[0];
const body = args.slice(1).join(" ");

if (!identifier || !body) {
	console.log("Usage: linear-comment.js <identifier> <body>");
	console.log("\nExamples:");
	console.log('  linear-comment.js ATT-1234 "This is fixed in the latest PR"');
	process.exit(1);
}

const client = getClient();

const results = await client.searchIssues(identifier, { first: 1 });
const issue = results.nodes[0];
if (!issue) {
	console.error(`Issue '${identifier}' not found.`);
	process.exit(1);
}

await client.createComment({ issueId: issue.id, body });
console.log(`Comment added to ${issue.identifier}.`);
