fix: use REST API for issue/PR detection

gh pr view --json number falsely matches issues. Use gh api
repos/{repo}/issues/{n} with has("pull_request") for reliable detection.
This commit is contained in:
snomiao
2026-04-10 21:35:23 +00:00
parent 76ef88f18b
commit d96d582ce2

View File

@@ -171,12 +171,11 @@ function resolveTarget(input: string): {
function detectType(number: string, repo: string): TargetType {
try {
execSync(`gh pr view ${number} --repo ${repo} --json number`, {
encoding: 'utf-8',
timeout: 15000,
stdio: ['pipe', 'pipe', 'pipe']
})
return 'pr'
const result = execSync(
`gh api repos/${repo}/issues/${number} --jq 'has("pull_request")'`,
{ encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'] }
)
return result.trim() === 'true' ? 'pr' : 'issue'
} catch {
return 'issue'
}