Searching for a pull request based on Sha uses an incorrect query
Closed this issue · 3 comments
We've been using this action for a while now in our company (Self Hosted Github Enterprise). Recently we noticed that releases where failing for Pull request that did not contain a merge commit with a PR number.
After some digging, I was able to narrow it down to this function:
async function searchPRByCommit(commitSHA, config) {
// Query GitHub to see if the commit sha is related to a PR
// Rebase merge will not have the information in the commit message
try {
const q = `type:pull-request is:merged ${commitSHA}`
const data = await config.octokit.rest.search.issuesAndPullRequests({ q })
if (data.data.total_count < 1) {
throw new Error('No results found querying for the PR')
}
// We should only find one PR with the commit SHA that was merged so take the first one
const pr = data.data.items[0]
return pr
} catch (fetchError) {
throw new Error(`Failed to find PR by commit SHA ${commitSHA}: ${fetchError.message}`)
}
}
according to the Github documentation found here it should be type:pr
instead of type:pull-request
. We have seen various builds that seemingly worked using type:pull-request and can't determine if this API has had any breaking changes. Given that both the latest public version as well as older API versions seem to support type:pr
I created a PR to update it.
@jefflinse I’d hate to add on to the pressure but would you have time to look at this issue and the associate pull request?
@Ghislain89 Thanks for pinging me about this, I've admittedly neglected this project and just need to find some time to work through the backlog.
I'll review your PR tomorrow and follow up.
Thanks! Really appreciate it!