import { execSync } from 'node:child_process';
export const defaultGitLabExecutor = (command) => {
    return execSync(command, { encoding: 'utf-8', timeout: 30000 });
};
export class GitLabThreadFetchGateway {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    fetchThreads(projectPath, mergeRequestNumber) {
        const encodedProject = projectPath.replace(/\//g, '%2F');
        const response = this.executor(`glab api projects/${encodedProject}/merge_requests/${mergeRequestNumber}/discussions`);
        const discussions = JSON.parse(response);
        const threads = [];
        for (const discussion of discussions) {
            const firstNote = discussion.notes[0];
            if (!firstNote?.resolvable)
                continue;
            threads.push({
                id: discussion.id,
                file: firstNote.position?.new_path ?? null,
                line: firstNote.position?.new_line ?? null,
                status: firstNote.resolved ? 'resolved' : 'open',
                body: firstNote.body,
            });
        }
        return threads;
    }
}
//# sourceMappingURL=threadFetch.gitlab.gateway.js.map