Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/gitlab

src/issues/get.ts

26 lines · 811 B · TypeScript
import { normalizeIssueLocator, pickAuthInput, request } from '../core.ts'
import { asRecord, slimIssue } from '../shape.ts'

/**
 * Fetch one GitLab issue by project + iid, or by issue URL.
 *
 * @example
 * import getGitlabIssue from 'kody:@kody/gitlab/issues/get'
 * const issue = await getGitlabIssue({ project: 'example-group/example-project', issueIid: 12 })
 */
export default async function getGitlabIssue(params: Record<string, unknown> = {}) {
	const auth = pickAuthInput(params)
	const { projectId, projectPath, issueIid } = normalizeIssueLocator(params)

	const response = await request<Record<string, unknown>>({
		...auth,
		path: `/projects/${projectId}/issues/${issueIid}`,
		throwOnError: true,
	})

	return {
		...slimIssue(asRecord(response.data)),
		projectPath,
		auth: response.auth,
	}
}