import { execSync } from 'node:child_process';
export const defaultGitHubExecutor = (command) => {
    return execSync(command, { encoding: 'utf-8', timeout: 30000 });
};
export class GitHubThreadFetchGateway {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    fetchThreads(projectPath, mergeRequestNumber) {
        const [owner, name] = projectPath.split('/');
        const query = `query {
      repository(owner: "${owner}", name: "${name}") {
        pullRequest(number: ${mergeRequestNumber}) {
          reviewThreads(first: 100) {
            nodes { id isResolved path line comments(first: 1) { nodes { body } } }
          }
        }
      }
    }`;
        const response = this.executor(`gh api graphql -f query='${query}'`);
        const data = JSON.parse(response);
        const nodes = data.data.repository.pullRequest.reviewThreads.nodes;
        return nodes.map((node) => ({
            id: node.id,
            file: node.path,
            line: node.line,
            status: node.isResolved ? 'resolved' : 'open',
            body: node.comments.nodes[0]?.body ?? '',
        }));
    }
}
//# sourceMappingURL=threadFetch.github.gateway.js.map