Skip to content

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

Package listing

@kody/gitlab

src/merge-requests/get.ts

29 lines · 923 B · TypeScript
import { normalizeMergeRequestLocator, pickAuthInput, request } from '../core.ts'
import { asRecord, slimMergeRequest } from '../shape.ts'

/**
 * Fetch one GitLab merge request by project + iid, or by merge request URL.
 *
 * @example
 * import getGitlabMergeRequest from 'kody:@kody/gitlab/merge-requests/get'
 * const mr = await getGitlabMergeRequest({
 *   project: 'example-group/example-project',
 *   mergeRequestIid: 4,
 * })
 */
export default async function getGitlabMergeRequest(params: Record<string, unknown> = {}) {
	const auth = pickAuthInput(params)
	const { projectId, projectPath, mergeRequestIid } = normalizeMergeRequestLocator(params)

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

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