Files
orca/src/main/gitlab/gl-utils.ts
T

65 lines
1.7 KiB
TypeScript

import { execFile } from 'child_process'
import { promisify } from 'util'
import { gitExecFileAsync, glabExecFileAsync } from '../git/runner'
import { parseGlabApiResponse, type GlabApiResponse } from './glab-api-response'
// Why: legacy generic execFile wrapper - only used by callers that don't need
// WSL-aware routing. Repo-scoped callers should use the runner exports below.
export const execFileAsync = promisify(execFile)
export { glabExecFileAsync, gitExecFileAsync }
export { classifyGlabError, classifyListIssuesError } from './glab-error-classification'
export {
DEFAULT_GITLAB_HOSTS,
_getProjectRefCacheSize,
_resetKnownHostsCache,
_resetProjectRefCache,
getGlabKnownHosts,
getIssueProjectRef,
getProjectRef,
getProjectRefForRemote,
glabHostnameArgs,
glabRepoExecOptions,
parseGlabAuthStatusHosts,
parseGitLabProjectRef,
resolveIssueSource
} from './gitlab-project-ref-resolution'
export type {
LocalGitExecOptions,
ProjectRef,
ResolvedIssueSource
} from './gitlab-project-ref-resolution'
export { parseGlabApiResponse, type GlabApiResponse } from './glab-api-response'
const MAX_CONCURRENT = 4
let running = 0
const queue: (() => void)[] = []
export function acquire(): Promise<void> {
if (running < MAX_CONCURRENT) {
running += 1
return Promise.resolve()
}
return new Promise((resolve) =>
queue.push(() => {
running += 1
resolve()
})
)
}
export function release(): void {
running -= 1
const next = queue.shift()
if (next) {
next()
}
}
export async function glabApiWithHeaders(
args: string[],
options?: { cwd?: string }
): Promise<GlabApiResponse> {
const { stdout } = await glabExecFileAsync(['api', '-i', ...args], options)
return parseGlabApiResponse(stdout)
}