Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Standardize getModuleVersionChanges return type #176

Merged
merged 3 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6340,7 +6340,7 @@ module.exports = SemVer

const SemVer = __nccwpck_require__(8088)
const parse = __nccwpck_require__(5925)
const {re, t} = __nccwpck_require__(9523)
const { re, t } = __nccwpck_require__(9523)

const coerce = (version, options) => {
if (version instanceof SemVer) {
Expand Down Expand Up @@ -6383,8 +6383,9 @@ const coerce = (version, options) => {
re[t.COERCERTL].lastIndex = -1
}

if (match === null)
if (match === null) {
return null
}

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

const {MAX_LENGTH} = __nccwpck_require__(2293)
const { MAX_LENGTH } = __nccwpck_require__(2293)
const { re, t } = __nccwpck_require__(9523)
const SemVer = __nccwpck_require__(8088)

Expand Down Expand Up @@ -6507,7 +6508,7 @@ const SEMVER_SPEC_VERSION = '2.0.0'

const MAX_LENGTH = 256
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
/* istanbul ignore next */ 9007199254740991
/* istanbul ignore next */ 9007199254740991

// Max safe segment length for coercion.
const MAX_SAFE_COMPONENT_LENGTH = 16
Expand All @@ -6516,7 +6517,7 @@ module.exports = {
SEMVER_SPEC_VERSION,
MAX_LENGTH,
MAX_SAFE_INTEGER,
MAX_SAFE_COMPONENT_LENGTH
MAX_SAFE_COMPONENT_LENGTH,
}


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

module.exports = {
compareIdentifiers,
rcompareIdentifiers
rcompareIdentifiers,
}


Expand All @@ -6577,9 +6578,9 @@ const opts = ['includePrerelease', 'loose', 'rtl']
const parseOptions = options =>
!options ? {}
: typeof options !== 'object' ? { loose: true }
: opts.filter(k => options[k]).reduce((options, k) => {
options[k] = true
return options
: opts.filter(k => options[k]).reduce((o, k) => {
o[k] = true
return o
}, {})
module.exports = parseOptions

Expand All @@ -6601,7 +6602,7 @@ let R = 0

const createToken = (name, value, isGlobal) => {
const index = R++
debug(index, value)
debug(name, index, value)
t[name] = index
src[index] = value
re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
Expand Down Expand Up @@ -6769,8 +6770,8 @@ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
// Star ranges basically just allow anything at all.
createToken('STAR', '(<|>)?=?\\s*\\*')
// >=0.0.0 is like a star
createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$')
createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$')
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$')
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$')


/***/ }),
Expand Down Expand Up @@ -9380,6 +9381,7 @@ ${changedExcludedPackages.join(', ')}. Skipping.`)
function isAMajorReleaseBump(change) {
const from = change.delete
const to = change.insert

if (!from || !to) {
return false
}
Expand Down Expand Up @@ -9568,7 +9570,7 @@ const getModuleVersionChanges = (prDiff) => {
const parsedDiffFiles = parse(prDiff)
const packageJsonChanges = parsedDiffFiles.find((file) => file.newPath === 'package.json')
if (!packageJsonChanges) {
return false
return {}
}

const moduleChanges = {}
Expand Down
2 changes: 1 addition & 1 deletion src/moduleVersionChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const getModuleVersionChanges = (prDiff) => {
const parsedDiffFiles = parse(prDiff)
const packageJsonChanges = parsedDiffFiles.find((file) => file.newPath === 'package.json')
if (!packageJsonChanges) {
return false
return {}
}

const moduleChanges = {}
Expand Down
24 changes: 24 additions & 0 deletions test/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,27 @@ tap.test('should check submodules semver when target is set', async () => {
sinon.assert.notCalled(stubs.approveStub)
sinon.assert.notCalled(stubs.mergeStub)
})

tap.test('should merge if no changes were made to package.json', async () => {
const PR_NUMBER = Math.random()
const { action, stubs } = buildStubbedAction({
payload: {
pull_request: {
number: PR_NUMBER,
user: { login: BOT_NAME },
}
},
inputs: {
PR_NUMBER,
TARGET: 'main',
EXCLUDE_PKGS: ['react'],
}
})

stubs.prDiffStub.resolves(diffs.noPackageJsonChanges)

await action()

sinon.assert.called(stubs.approveStub)
sinon.assert.called(stubs.mergeStub)
})
14 changes: 14 additions & 0 deletions test/moduleChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ index d3dfd3d..bd28161 100644
- "github-action-merge-dependabot": "1.2.3",
+ "github-action-merge-dependabot": "2.1.0",
`,
noPackageJsonChanges: `
diff --git a/test/action.test.js b/test/action.test.js
index e8c6572..751e69d 100644
--- a/test/action.test.js
+++ b/test/action.test.js
@@ -9,6 +9,7 @@ const core = require('@actions/core')
const github = require('@actions/github')
const toolkit = require('actions-toolkit')

+
const { diffs } = require('./moduleChanges')
const actionLog = require('../src/log')
const actionUtil = require('../src/util')
`
}

const moduleChanges = {}
Expand Down