Skip to content

Commit

Permalink
fix: invalid version error (#129)
Browse files Browse the repository at this point in the history
* fix invalid version error

* build dist
  • Loading branch information
Eomm authored Dec 13, 2021
1 parent 35d9279 commit b4111b1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit b4111b1

Please sign in to comment.