From f088ce6c4992a7201d10b6bc9e8758b071fd84a1 Mon Sep 17 00:00:00 2001 From: Bill Glesias Date: Fri, 12 Jan 2024 09:01:52 -0500 Subject: [PATCH] chore: fix the get-binary-release-data script to try and locate all possible references that might be pull requests for a given commit. Also added debug messaging in the case this script needs to be debugged without spamming the console. (#28692) --- .../get-binary-release-data.js | 63 +++++++++++++------ 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/scripts/semantic-commits/get-binary-release-data.js b/scripts/semantic-commits/get-binary-release-data.js index 156731075d25..ad22d17d35c0 100644 --- a/scripts/semantic-commits/get-binary-release-data.js +++ b/scripts/semantic-commits/get-binary-release-data.js @@ -2,10 +2,12 @@ const Bluebird = require('bluebird') const childProcess = require('child_process') const _ = require('lodash') const { Octokit } = require('@octokit/core') +const debugLib = require('debug') const { getCurrentReleaseData } = require('./get-current-release-data') const { getNextVersionForBinary } = require('../get-next-version') const { getLinkedIssues } = require('./get-linked-issues') +const debug = debugLib('scripts:semantic-commits:get-binary-release-data') const ensureAuth = () => { if (!process.env.GH_TOKEN) { @@ -80,8 +82,6 @@ const fetchPullRequest = async (octokit, pullNumber) => { return pullRequest } catch (err) { - console.log(`Error while fetching PR #${pullNumber}:`, err) - const { rateLimitHit, retryAfter } = parseRateLimit(err) if (rateLimitHit) { @@ -133,29 +133,54 @@ const getReleaseData = async (latestReleaseInfo) => { return } - const ref = references.find((r) => !r.raw.includes('revert #')) + const refs = references.filter((r) => !r.raw.includes('revert #')) - if (!ref) { + if (!refs.length) { console.log('Commit does not have an associated pull request number...') return } - const pullRequest = await fetchPullRequest(octokit, ref.issue) - const associatedIssues = pullRequest.body ? getLinkedIssues(pullRequest.body) : [] - - commits.push({ - commitMessage: semanticResult.header, - semanticType, - prNumber: ref.issue, - associatedIssues, - }) - - prsInRelease.push(`https://github.com/cypress-io/cypress/pull/${ref.issue}`) - - associatedIssues.forEach((issueNumber) => { - issuesInRelease.push(`https://github.com/cypress-io/cypress/issues/${issueNumber}`) - }) + for (const [idx, ref] of refs.entries()) { + let pullRequest + + try { + pullRequest = await fetchPullRequest(octokit, ref.issue) + debug(`Pull request #${ref.issue} found!`) + } catch (err) { + debug(`Error while fetching PR #${ ref.issue}:`, err) + // If we have tried to fetch all other references and all of them failed, + // print the failure of the last reference and exit + if (idx === refs.length) { + debug(`all references exhausted and no PR could be found!`) + console.log(`Error while fetching PR #${ ref.issue}:`, err) + throw err + } else { + // otherwise, we still might be able to link a PR to the commit + debug(`Other references need to be tried. Continuing to see if we can find a corresponding pull request.`) + } + + continue + } + + const associatedIssues = pullRequest.body ? getLinkedIssues(pullRequest.body) : [] + + commits.push({ + commitMessage: semanticResult.header, + semanticType, + prNumber: ref.issue, + associatedIssues, + }) + + prsInRelease.push(`https://github.com/cypress-io/cypress/pull/${ref.issue}`) + + associatedIssues.forEach((issueNumber) => { + issuesInRelease.push(`https://github.com/cypress-io/cypress/issues/${issueNumber}`) + }) + + // since we found our pull request, we don't need to check the rest of the references + break + } })) console.log('Next release version is', nextVersion)