Skip to content

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

Package listing

@kody/gitlab

src/projects/get.ts

26 lines · 810 B · TypeScript
import { normalizeProjectLocator, pickAuthInput, request } from '../core.ts'
import { asRecord, slimProject } from '../shape.ts'

/**
 * Fetch one GitLab project by numeric id, `namespace/project` path, or project URL.
 *
 * @example
 * import getGitlabProject from 'kody:@kody/gitlab/projects/get'
 * const project = await getGitlabProject({ project: 'example-group/example-project' })
 */
export default async function getGitlabProject(params: Record<string, unknown> = {}) {
	const auth = pickAuthInput(params)
	const { projectId, projectPath } = normalizeProjectLocator(params)

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

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