@@ -6311,7 +6311,7 @@ class SemVer {
6311
6311
if (identifier) {
6312
6312
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
6313
6313
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
6314
- if (compareIdentifiers( this.prerelease[0], identifier) === 0 ) {
6314
+ if (this.prerelease[0] === identifier ) {
6315
6315
if (isNaN(this.prerelease[1])) {
6316
6316
this.prerelease = [identifier, 0]
6317
6317
}
@@ -9299,7 +9299,7 @@ const toolkit = __nccwpck_require__(2183)
9299
9299
const packageInfo = __nccwpck_require__(4147)
9300
9300
const { githubClient } = __nccwpck_require__(3386)
9301
9301
const { logInfo, logWarning, logError } = __nccwpck_require__(653)
9302
- const { getInputs, getPackageName } = __nccwpck_require__(6254)
9302
+ const { isValidSemver, isCommitHash, getInputs, getPackageName } = __nccwpck_require__(6254)
9303
9303
const { targetOptions } = __nccwpck_require__(5013)
9304
9304
const {
9305
9305
getModuleVersionChanges,
@@ -9384,6 +9384,10 @@ function isAMajorReleaseBump(change) {
9384
9384
const from = change.delete
9385
9385
const to = change.insert
9386
9386
9387
+ if (isCommitHash(from) && isCommitHash(to)) {
9388
+ return false
9389
+ }
9390
+
9387
9391
const diff = semverDiff(semverCoerce(from), semverCoerce(to))
9388
9392
return diff === targetOptions.major
9389
9393
}
@@ -9395,11 +9399,18 @@ function parsePrTitle(pullRequest) {
9395
9399
if (!match) {
9396
9400
throw new Error('Error while parsing PR title, expected: `bump <package> from <old-version> to <new-version>`')
9397
9401
}
9398
- const [, oldVersion, newVersion] = match
9399
9402
9400
9403
const packageName = getPackageName(pullRequest.head.ref)
9401
9404
9402
- return { [packageName]: { delete: semverCoerce(oldVersion).raw, insert: semverCoerce(newVersion).raw } }
9405
+ const [, oldVersion, newVersion] = match.map(t => t.replace(/`/g, ''))
9406
+ const isValid = isValidSemver(oldVersion) && isValidSemver(newVersion)
9407
+
9408
+ return {
9409
+ [packageName]: {
9410
+ delete: isValid ? semverCoerce(oldVersion)?.raw : oldVersion,
9411
+ insert: isValid ? semverCoerce(newVersion)?.raw : newVersion
9412
+ }
9413
+ }
9403
9414
}
9404
9415
9405
9416
@@ -9539,19 +9550,13 @@ exports.logWarning = log(warning)
9539
9550
9540
9551
const semverDiff = __nccwpck_require__(4297)
9541
9552
const semverCoerce = __nccwpck_require__(3466)
9542
- const semverValid = __nccwpck_require__(9601)
9543
9553
const { parse } = __nccwpck_require__(153)
9554
+ const { isCommitHash, isValidSemver } = __nccwpck_require__(6254)
9544
9555
9545
9556
const { semanticVersionOrder } = __nccwpck_require__(5013)
9546
- const { logWarning } = __nccwpck_require__(653)
9547
9557
9548
9558
const expression = /"([^\s]+)":\s*"([^\s]+)"/
9549
9559
9550
- function hasBadChars(version) {
9551
- // recognize submodules title likes 'Bump dotbot from `aa93350` to `acaaaac`'
9552
- return /^[^^~*-0-9+x]/.test(version)
9553
- }
9554
-
9555
9560
const checkModuleVersionChanges = (moduleChanges, target) => {
9556
9561
for (const module in moduleChanges) {
9557
9562
const from = moduleChanges[module].delete
@@ -9561,9 +9566,12 @@ const checkModuleVersionChanges = (moduleChanges, target) => {
9561
9566
return false
9562
9567
}
9563
9568
9564
- if ((!semverValid(from) && hasBadChars(from)) || (!semverValid(to) && hasBadChars(to))) {
9565
- logWarning(`Module "${module}" contains invalid semver versions from: ${from} to: ${to}`)
9566
- return false
9569
+ if (isCommitHash(from) && isCommitHash(to)) {
9570
+ return true
9571
+ }
9572
+
9573
+ if (!isValidSemver(from) || !isValidSemver(to)) {
9574
+ throw new Error(`Module "${module}" contains invalid semver versions from: ${from} to: ${to}`)
9567
9575
}
9568
9576
9569
9577
const diff = semverDiff(semverCoerce(from), semverCoerce(to))
@@ -9625,6 +9633,8 @@ module.exports = {
9625
9633
"use strict";
9626
9634
9627
9635
9636
+ const semverValid = __nccwpck_require__(9601)
9637
+ const semverCoerce = __nccwpck_require__(3466)
9628
9638
const core = __nccwpck_require__(2186)
9629
9639
9630
9640
const { getTargetInput } = __nccwpck_require__(5013)
@@ -9667,6 +9677,8 @@ exports.getInputs = () => ({
9667
9677
* Get a package name from a branch name.
9668
9678
* Dependabot branch names are in format "dependabot/npm_and_yarn/pkg-0.0.1"
9669
9679
* or "dependabot/github_actions/fastify/github-action-merge-dependabot-2.6.0"
9680
+ * @param {String} branchName
9681
+ * @returns Package name extracted from branch
9670
9682
*/
9671
9683
exports.getPackageName = (branchName) => {
9672
9684
const nameWithVersion = branchName.split('/').pop().split('-')
@@ -9680,6 +9692,34 @@ exports.getPackageName = (branchName) => {
9680
9692
return packageName
9681
9693
}
9682
9694
9695
+ /**
9696
+ * Checks if the string is a SHA1 commit hash.
9697
+ * Usually github commit hashes are 7 chars long, but in case this change someday
9698
+ * it's checking for the maximum length of a SHA1 hash (40 hexadecimal chars)
9699
+ * @param {String} version
9700
+ * @returns Boolean indicating whether version
9701
+ */
9702
+ exports.isCommitHash = function(version) {
9703
+ return /^[a-f0-9]{5,40}$/.test(version)
9704
+ }
9705
+
9706
+ /**
9707
+ * Checks if a version is a valid semver version.
9708
+ * Uses loose: true and replace `v`, `~`, `^` charactes to make function a bit
9709
+ * less restrictive regarding the accepted inputs
9710
+ * @param {String} version
9711
+ * @returns Boolean indicating whether version is valid
9712
+ */
9713
+ exports.isValidSemver = function (version) {
9714
+ const isNumber = !isNaN(+version)
9715
+
9716
+ if (isNumber) {
9717
+ return semverValid(semverCoerce(version))
9718
+ }
9719
+
9720
+ return semverValid(version.replace(/[\^~v]/g, ''), { loose: true })
9721
+ }
9722
+
9683
9723
9684
9724
/***/ }),
9685
9725
@@ -9815,7 +9855,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
9815
9855
/***/ ((module) => {
9816
9856
9817
9857
"use strict";
9818
- module.exports = JSON.parse('{"name":"github-action-merge-dependabot","version":"3.1.4","description":"A GitHub action to automatically merge and approve Dependabot pull requests","main":"src/index.js","scripts":{"build":"ncc build src/index.js","lint":"eslint .","test":"tap","prepare":"husky install"},"author":{"name":"Salman Mitha","email":"SalmanMitha@gmail.com"},"contributors":["Simone Busoli <simone.busoli@nearform.com>"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/fastify/github-action-merge-dependabot.git"},"bugs":{"url":"https://github.com/fastify/github-action-merge-dependabot/issues"},"homepage":"https://github.com/fastify/github-action-merge-dependabot#readme","dependencies":{"@actions/core":"^1.6.0","@actions/github":"^5.0.1","actions-toolkit":"github:nearform/actions-toolkit","gitdiff-parser":"^0.2.2","semver":"^7.3.7"},"devDependencies":{"@vercel/ncc":"^0.33.4","eslint":"^8.14.0","husky":"^7.0.4","prettier":"^2.6.2","proxyquire":"^2.1.3","sinon":"^13.0.2","tap":"^16.1.0"}}');
9858
+ module.exports = JSON.parse('{"name":"github-action-merge-dependabot","version":"3.1.4","description":"A GitHub action to automatically merge and approve Dependabot pull requests","main":"src/index.js","scripts":{"build":"ncc build src/index.js","lint":"eslint .","test":"tap test/**.test.js","prepare":"husky install"},"author":{"name":"Salman Mitha","email":"SalmanMitha@gmail.com"},"contributors":["Simone Busoli <simone.busoli@nearform.com>"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/fastify/github-action-merge-dependabot.git"},"bugs":{"url":"https://github.com/fastify/github-action-merge-dependabot/issues"},"homepage":"https://github.com/fastify/github-action-merge-dependabot#readme","dependencies":{"@actions/core":"^1.7.0","@actions/github":"^5.0.1","actions-toolkit":"github:nearform/actions-toolkit","gitdiff-parser":"^0.2.2","semver":"^7.3.7"},"devDependencies":{"@vercel/ncc":"^0.33.4","eslint":"^8.14.0","husky":"^7.0.4","prettier":"^2.6.2","proxyquire":"^2.1.3","sinon":"^13.0.2","tap":"^16.1.0"}}');
9819
9859
9820
9860
/***/ })
9821
9861
0 commit comments