From 00ac3102f971759f62eaa91a7ad5057e3efba0b3 Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Mon, 19 Apr 2021 19:09:51 +0200 Subject: [PATCH] Fix "No commits between" error (#243) --- source/app/action/index.mjs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index 41374b0b..e87b3895 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -320,16 +320,23 @@ } catch (error) { console.debug(error) - if (/A pull request already exists/.test(error)) { - info(`Pull request from ${committer.head} to ${committer.branch}`, "(already existing)") - const q = `repo:${github.context.repo.owner}/${github.context.repo.repo}+type:pr+state:open+Auto-generated metrics for run #${github.context.runId}+in:title` - const prs = (await committer.rest.search.issuesAndPullRequests({q})).data.items.filter(({user:{login}}) => login === "github-actions[bot]") - if (prs.length < 1) - throw new Error("0 matching prs. Cannot proceed.") - if (prs.length > 1) - throw new Error(`Found more than one matching prs: ${prs.map(({number}) => `#${number}`).join(", ")}. Cannot proceed.`) - ;({number} = prs.shift()) - } + //Check if pull request has already been created previously + if (/A pull request already exists/.test(error)) { + info(`Pull request from ${committer.head} to ${committer.branch}`, "(already existing)") + const q = `repo:${github.context.repo.owner}/${github.context.repo.repo}+type:pr+state:open+Auto-generated metrics for run #${github.context.runId}+in:title` + const prs = (await committer.rest.search.issuesAndPullRequests({q})).data.items.filter(({user:{login}}) => login === "github-actions[bot]") + if (prs.length < 1) + throw new Error("0 matching prs. Cannot proceed.") + if (prs.length > 1) + throw new Error(`Found more than one matching prs: ${prs.map(({number}) => `#${number}`).join(", ")}. Cannot proceed.`) + ;({number} = prs.shift()) + } + //Check if pull request could not been created because there are no diff between head and base + else if (/No commits between/.test(error)) { + info(`Pull request from ${committer.head} to ${committer.branch}`, "(no diff)") + committer.merge = false + number = "(none)" + } else throw error }