From b4111b1288aea4d5b0d0ef97f1ba068b6581fa25 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Mon, 13 Dec 2021 17:15:45 +0100 Subject: [PATCH] fix: invalid version error (#129) * fix invalid version error * build dist --- dist/index.js | 6 +++++- src/action.js | 6 +++++- test/action.test.js | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 98cb9e20..83c71306 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9026,6 +9026,7 @@ function wrappy (fn, cb) { const core = __nccwpck_require__(2186) const github = __nccwpck_require__(5438) const semverMajor = __nccwpck_require__(6688) +const semverCoerce = __nccwpck_require__(3466) const { githubClient } = __nccwpck_require__(3386) const checkTargetMatchToPR = __nccwpck_require__(7186) @@ -9064,6 +9065,7 @@ module.exports = async function run() { } if (TARGET !== targetOptions.any) { + logInfo(`Checking if PR title [${pr.title}] has target ${TARGET}`) const isTargetMatchToPR = checkTargetMatchToPR(pr.title, TARGET) if (!isTargetMatchToPR) { @@ -9113,7 +9115,9 @@ function isMajorRelease(pullRequest) { const match = expression.exec(pullRequest.title) if (match) { const [, oldVersion, newVersion] = match - if (semverMajor(oldVersion) !== semverMajor(newVersion)) { + const oldVersionSemver = semverCoerce(oldVersion) + const newVersionSemver = semverCoerce(newVersion) + if (semverMajor(oldVersionSemver) !== semverMajor(newVersionSemver)) { return true } } diff --git a/src/action.js b/src/action.js index ae5f1520..5a898834 100644 --- a/src/action.js +++ b/src/action.js @@ -3,6 +3,7 @@ const core = require('@actions/core') const github = require('@actions/github') const semverMajor = require('semver/functions/major') +const semverCoerce = require('semver/functions/coerce') const { githubClient } = require('./github-client') const checkTargetMatchToPR = require('./checkTargetMatchToPR') @@ -41,6 +42,7 @@ module.exports = async function run() { } if (TARGET !== targetOptions.any) { + logInfo(`Checking if PR title [${pr.title}] has target ${TARGET}`) const isTargetMatchToPR = checkTargetMatchToPR(pr.title, TARGET) if (!isTargetMatchToPR) { @@ -90,7 +92,9 @@ function isMajorRelease(pullRequest) { const match = expression.exec(pullRequest.title) if (match) { const [, oldVersion, newVersion] = match - if (semverMajor(oldVersion) !== semverMajor(newVersion)) { + const oldVersionSemver = semverCoerce(oldVersion) + const newVersionSemver = semverCoerce(newVersion) + if (semverMajor(oldVersionSemver) !== semverMajor(newVersionSemver)) { return true } } diff --git a/test/action.test.js b/test/action.test.js index 4359e8ff..11f59ce1 100644 --- a/test/action.test.js +++ b/test/action.test.js @@ -232,6 +232,28 @@ tap.test('should not merge github-action-merge-dependabot major release', async sinon.assert.notCalled(stubs.mergeStub) }) +tap.test('should not merge github-action-merge-dependabot major release with semver-like title', async t => { + const PR_NUMBER = Math.random() + const { action, stubs } = buildStubbedAction({ + payload: { + pull_request: { + number: PR_NUMBER, + title: 'Bump fastify/github-action-merge-dependabot from 2.7.1 to 3', + user: { login: BOT_NAME }, + head: { ref: 'dependabot/github_actions/fastify/github-action-merge-dependabot-3' }, + } + }, + inputs: { PR_NUMBER, TARGET: 'any', EXCLUDE_PKGS: [], } + }) + + await action() + + sinon.assert.calledOnce(stubs.coreStub.setFailed) + t.match(stubs.coreStub.setFailed.firstCall.args[0], /^Cannot automerge github-action-merge-dependabot 3 major release./) + sinon.assert.notCalled(stubs.approveStub) + sinon.assert.notCalled(stubs.mergeStub) +}) + tap.test('should review and merge', async () => { const PR_NUMBER = Math.random() const { action, stubs } = buildStubbedAction({