better undefined resolution

This commit is contained in:
Jacob Heider 2023-01-11 18:50:57 -05:00
parent 95ecc17d79
commit d919815397
No known key found for this signature in database
GPG key ID: A98011B5713535BF

View file

@ -52,7 +52,9 @@ export async function find_pr(repo: string, ref: string): Promise<number | undef
const res = await queryGraphQL<CommitQuery>(prQuery(repo))
const node = res.repository?.ref?.target?.history?.edges.find(n => n.node.oid === ref)
return node?.node.associatedPullRequests.nodes[0].number
const nodes = node?.node.associatedPullRequests.nodes
if (!nodes || nodes.length === 0) return
return nodes[0].number
}
async function queryGraphQL<T>(query: string): Promise<T> {