← Public packages
@kody/github
Call GitHub REST, GraphQL, and pull requests with a GitHub OAuth App or a personal access token.
src/pr/get-info.ts
40 lines · 1.3 KB · TypeScriptimport { pickAuthInput, request } from '../core.ts'
import { normalizePrLocator } from './pr-input.ts'
/**
* Fetch pull request details.
*
* @param params - PR locator (`prUrl` or `owner`/`repo`/`prNumber`) plus optional
* `integrationName` or `secretName`.
* @returns PR number, title, state, draft flag, and URLs.
* @example
* import getPrInfo from 'kody:@kody/github/pr/get-info'
* const pr = await getPrInfo({ owner: 'example-org', repo: 'example', prNumber: 1 })
* // => { number: 1, title: '...', state: 'open', draft: false }
*/
export default async function getPrInfo(params: Record<string, unknown> = {}) {
const auth = pickAuthInput(params)
const { owner, repo, prNumber } = normalizePrLocator(params)
const response = await request<Record<string, unknown>>({
...auth,
path: `/repos/${owner}/${repo}/pulls/${prNumber}`,
throwOnError: true,
})
const pr = response.data!
return {
nodeId: pr.node_id as string,
number: pr.number as number,
title: pr.title as string,
state: pr.state as 'open' | 'closed',
draft: pr.draft as boolean,
url: pr.html_url as string,
repository: `${owner}/${repo}`,
createdAt: pr.created_at as string,
updatedAt: pr.updated_at as string,
mergedAt: pr.merged_at as string | null,
user: (pr.user as { login?: string } | undefined)?.login as string,
auth: response.auth,
}
}