MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / fetchPrStatus

Function fetchPrStatus

source code/utils/ghPrStatus.ts:48–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46 * Also returns null if the PR's head branch is the default branch (e.g., main/master).
47 */
48export async function fetchPrStatus(): Promise<PrStatus | null> {
49 const isGit = await getIsGit()
50 if (!isGit) return null
51
52 // Skip on the default branch — `gh pr view` returns the most recently
53 // merged PR there, which is misleading.
54 const [branch, defaultBranch] = await Promise.all([
55 getBranch(),
56 getDefaultBranch(),
57 ])
58 if (branch === defaultBranch) return null
59
60 const { stdout, code } = await execFileNoThrow(
61 'gh',
62 [
63 'pr',
64 'view',
65 '--json',
66 'number,url,reviewDecision,isDraft,headRefName,state',
67 ],
68 { timeout: GH_TIMEOUT_MS, preserveOutputOnError: false },
69 )
70
71 if (code !== 0 || !stdout.trim()) return null
72
73 try {
74 const data = jsonParse(stdout) as {
75 number: number
76 url: string
77 reviewDecision: string
78 isDraft: boolean
79 headRefName: string
80 state: string
81 }
82
83 // Don't show PR status for PRs from the default branch (e.g., main, master)
84 // This can happen when someone opens a PR from main to another branch
85 if (
86 data.headRefName === defaultBranch ||
87 data.headRefName === 'main' ||
88 data.headRefName === 'master'
89 ) {
90 return null
91 }
92
93 // Don't show PR status for merged or closed PRs — `gh pr view` returns
94 // the most recently associated PR for a branch, which may be merged/closed.
95 // The status line should only display open PRs.
96 if (data.state === 'MERGED' || data.state === 'CLOSED') {
97 return null
98 }
99
100 return {
101 number: data.number,
102 url: data.url,
103 reviewState: deriveReviewState(data.isDraft, data.reviewDecision),
104 }
105 } catch {

Callers 1

pollFunction · 0.85

Calls 5

getBranchFunction · 0.85
getDefaultBranchFunction · 0.85
execFileNoThrowFunction · 0.85
jsonParseFunction · 0.85
deriveReviewStateFunction · 0.85

Tested by

no test coverage detected