Skip to content

Commit 6103bb1

Browse files
fix: Standardize getModuleVersionChanges return type (#176)
* fix: Standardize getModuleVersionChanges return type Avoid returning false (which as far as I can see was not being used in any case) and always return an object. * test: Add test case for diff with no package.json changes * test: Improve test name
1 parent 964c2ff commit 6103bb1

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

dist/index.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -6340,7 +6340,7 @@ module.exports = SemVer
63406340

63416341
const SemVer = __nccwpck_require__(8088)
63426342
const parse = __nccwpck_require__(5925)
6343-
const {re, t} = __nccwpck_require__(9523)
6343+
const { re, t } = __nccwpck_require__(9523)
63446344

63456345
const coerce = (version, options) => {
63466346
if (version instanceof SemVer) {
@@ -6383,8 +6383,9 @@ const coerce = (version, options) => {
63836383
re[t.COERCERTL].lastIndex = -1
63846384
}
63856385

6386-
if (match === null)
6386+
if (match === null) {
63876387
return null
6388+
}
63886389

63896390
return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options)
63906391
}
@@ -6448,7 +6449,7 @@ module.exports = eq
64486449
/***/ 5925:
64496450
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
64506451

6451-
const {MAX_LENGTH} = __nccwpck_require__(2293)
6452+
const { MAX_LENGTH } = __nccwpck_require__(2293)
64526453
const { re, t } = __nccwpck_require__(9523)
64536454
const SemVer = __nccwpck_require__(8088)
64546455

@@ -6507,7 +6508,7 @@ const SEMVER_SPEC_VERSION = '2.0.0'
65076508

65086509
const MAX_LENGTH = 256
65096510
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
6510-
/* istanbul ignore next */ 9007199254740991
6511+
/* istanbul ignore next */ 9007199254740991
65116512

65126513
// Max safe segment length for coercion.
65136514
const MAX_SAFE_COMPONENT_LENGTH = 16
@@ -6516,7 +6517,7 @@ module.exports = {
65166517
SEMVER_SPEC_VERSION,
65176518
MAX_LENGTH,
65186519
MAX_SAFE_INTEGER,
6519-
MAX_SAFE_COMPONENT_LENGTH
6520+
MAX_SAFE_COMPONENT_LENGTH,
65206521
}
65216522

65226523

@@ -6562,7 +6563,7 @@ const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a)
65626563

65636564
module.exports = {
65646565
compareIdentifiers,
6565-
rcompareIdentifiers
6566+
rcompareIdentifiers,
65666567
}
65676568

65686569

@@ -6577,9 +6578,9 @@ const opts = ['includePrerelease', 'loose', 'rtl']
65776578
const parseOptions = options =>
65786579
!options ? {}
65796580
: typeof options !== 'object' ? { loose: true }
6580-
: opts.filter(k => options[k]).reduce((options, k) => {
6581-
options[k] = true
6582-
return options
6581+
: opts.filter(k => options[k]).reduce((o, k) => {
6582+
o[k] = true
6583+
return o
65836584
}, {})
65846585
module.exports = parseOptions
65856586

@@ -6601,7 +6602,7 @@ let R = 0
66016602

66026603
const createToken = (name, value, isGlobal) => {
66036604
const index = R++
6604-
debug(index, value)
6605+
debug(name, index, value)
66056606
t[name] = index
66066607
src[index] = value
66076608
re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
@@ -6769,8 +6770,8 @@ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
67696770
// Star ranges basically just allow anything at all.
67706771
createToken('STAR', '(<|>)?=?\\s*\\*')
67716772
// >=0.0.0 is like a star
6772-
createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$')
6773-
createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$')
6773+
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$')
6774+
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$')
67746775

67756776

67766777
/***/ }),
@@ -9380,6 +9381,7 @@ ${changedExcludedPackages.join(', ')}. Skipping.`)
93809381
function isAMajorReleaseBump(change) {
93819382
const from = change.delete
93829383
const to = change.insert
9384+
93839385
if (!from || !to) {
93849386
return false
93859387
}
@@ -9568,7 +9570,7 @@ const getModuleVersionChanges = (prDiff) => {
95689570
const parsedDiffFiles = parse(prDiff)
95699571
const packageJsonChanges = parsedDiffFiles.find((file) => file.newPath === 'package.json')
95709572
if (!packageJsonChanges) {
9571-
return false
9573+
return {}
95729574
}
95739575

95749576
const moduleChanges = {}

src/moduleVersionChanges.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const getModuleVersionChanges = (prDiff) => {
4545
const parsedDiffFiles = parse(prDiff)
4646
const packageJsonChanges = parsedDiffFiles.find((file) => file.newPath === 'package.json')
4747
if (!packageJsonChanges) {
48-
return false
48+
return {}
4949
}
5050

5151
const moduleChanges = {}

test/action.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,27 @@ tap.test('should check submodules semver when target is set', async () => {
288288
sinon.assert.notCalled(stubs.approveStub)
289289
sinon.assert.notCalled(stubs.mergeStub)
290290
})
291+
292+
tap.test('should merge if no changes were made to package.json', async () => {
293+
const PR_NUMBER = Math.random()
294+
const { action, stubs } = buildStubbedAction({
295+
payload: {
296+
pull_request: {
297+
number: PR_NUMBER,
298+
user: { login: BOT_NAME },
299+
}
300+
},
301+
inputs: {
302+
PR_NUMBER,
303+
TARGET: 'main',
304+
EXCLUDE_PKGS: ['react'],
305+
}
306+
})
307+
308+
stubs.prDiffStub.resolves(diffs.noPackageJsonChanges)
309+
310+
await action()
311+
312+
sinon.assert.called(stubs.approveStub)
313+
sinon.assert.called(stubs.mergeStub)
314+
})

test/moduleChanges.js

+14
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ index d3dfd3d..bd28161 100644
147147
- "github-action-merge-dependabot": "1.2.3",
148148
+ "github-action-merge-dependabot": "2.1.0",
149149
`,
150+
noPackageJsonChanges: `
151+
diff --git a/test/action.test.js b/test/action.test.js
152+
index e8c6572..751e69d 100644
153+
--- a/test/action.test.js
154+
+++ b/test/action.test.js
155+
@@ -9,6 +9,7 @@ const core = require('@actions/core')
156+
const github = require('@actions/github')
157+
const toolkit = require('actions-toolkit')
158+
159+
+
160+
const { diffs } = require('./moduleChanges')
161+
const actionLog = require('../src/log')
162+
const actionUtil = require('../src/util')
163+
`
150164
}
151165

152166
const moduleChanges = {}

0 commit comments

Comments
 (0)