-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat: add support to dependabot's compatibility score #287
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -30,6 +30,7 @@ module.exports = async function run({ | |||||
APPROVE_ONLY, | ||||||
TARGET, | ||||||
PR_NUMBER, | ||||||
COMPATIBILITY_SCORE, | ||||||
} = getInputs(inputs) | ||||||
|
||||||
try { | ||||||
|
@@ -64,6 +65,20 @@ module.exports = async function run({ | |||||
) | ||||||
} | ||||||
|
||||||
const targetScore = +COMPATIBILITY_SCORE | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved the coercion to the input utility
Suggested change
|
||||||
const compatScore = +dependabotMetadata.compatibilityScore | ||||||
|
||||||
if ( | ||||||
!isNaN(targetScore) && | ||||||
!isNaN(compatScore) && | ||||||
compatScore < targetScore | ||||||
) { | ||||||
core.setFailed( | ||||||
`Compatibility score is lower than allowed. Expected at least ${targetScore} but received ${compatScore}` | ||||||
) | ||||||
return | ||||||
} | ||||||
|
||||||
if ( | ||||||
TARGET !== updateTypes.any && | ||||||
updateTypesPriority.indexOf(updateType) > | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -45,5 +45,6 @@ exports.getInputs = inputs => { | |||||
APPROVE_ONLY: /true/i.test(inputs['approve-only']), | ||||||
TARGET: mapUpdateType(inputs['target']), | ||||||
PR_NUMBER: inputs['pr-number'], | ||||||
COMPATIBILITY_SCORE: inputs['compatibility-score'], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -466,3 +466,96 @@ tap.test('should forbid minor when target is patch', async () => { | |||||
sinon.assert.notCalled(stubs.approveStub) | ||||||
sinon.assert.notCalled(stubs.mergeStub) | ||||||
}) | ||||||
|
||||||
tap.test( | ||||||
'should not allow merge with compatibility score lower than target score', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since in documentation stated "security updates may include compatibility scores", I would also add test for case when compat score is not provided |
||||||
async () => { | ||||||
const PR_NUMBER = Math.random() | ||||||
|
||||||
const { action, stubs } = buildStubbedAction({ | ||||||
payload: { | ||||||
pull_request: { | ||||||
number: PR_NUMBER, | ||||||
user: { login: BOT_NAME }, | ||||||
}, | ||||||
}, | ||||||
inputs: { | ||||||
PR_NUMBER, | ||||||
'compatibility-score': 90, | ||||||
}, | ||||||
dependabotMetadata: createDependabotMetadata({ | ||||||
updateType: updateTypes.minor, | ||||||
compatibilityScore: 80, | ||||||
}), | ||||||
}) | ||||||
|
||||||
await action() | ||||||
|
||||||
sinon.assert.calledWithExactly( | ||||||
stubs.coreStub.setFailed, | ||||||
`Compatibility score is lower than allowed. Expected at least 90 but received 80` | ||||||
) | ||||||
sinon.assert.notCalled(stubs.approveStub) | ||||||
sinon.assert.notCalled(stubs.mergeStub) | ||||||
} | ||||||
) | ||||||
|
||||||
tap.test( | ||||||
'should allow merge with compatibility score higher than target score', | ||||||
async () => { | ||||||
const PR_NUMBER = Math.random() | ||||||
|
||||||
const { action, stubs } = buildStubbedAction({ | ||||||
payload: { | ||||||
pull_request: { | ||||||
number: PR_NUMBER, | ||||||
user: { login: BOT_NAME }, | ||||||
}, | ||||||
}, | ||||||
inputs: { | ||||||
PR_NUMBER, | ||||||
'compatibility-score': 90, | ||||||
}, | ||||||
dependabotMetadata: createDependabotMetadata({ | ||||||
updateType: updateTypes.minor, | ||||||
compatibilityScore: 91, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be a float?
Suggested change
|
||||||
}), | ||||||
}) | ||||||
|
||||||
await action() | ||||||
|
||||||
sinon.assert.notCalled(stubs.coreStub.setFailed) | ||||||
sinon.assert.called(stubs.approveStub) | ||||||
sinon.assert.called(stubs.mergeStub) | ||||||
} | ||||||
) | ||||||
|
||||||
tap.test( | ||||||
'should allow merge when compatScore is equal to targetScore', | ||||||
async () => { | ||||||
const PR_NUMBER = Math.random() | ||||||
|
||||||
const { action, stubs } = buildStubbedAction({ | ||||||
payload: { | ||||||
pull_request: { | ||||||
number: PR_NUMBER, | ||||||
user: { login: BOT_NAME }, | ||||||
}, | ||||||
}, | ||||||
inputs: { | ||||||
PR_NUMBER, | ||||||
'compatibility-score': 90, | ||||||
}, | ||||||
dependabotMetadata: createDependabotMetadata({ | ||||||
updateType: updateTypes.minor, | ||||||
compatibilityScore: 90, | ||||||
}), | ||||||
}) | ||||||
|
||||||
await action() | ||||||
|
||||||
sinon.assert.notCalled(stubs.coreStub.setFailed) | ||||||
sinon.assert.called(stubs.approveStub) | ||||||
sinon.assert.called(stubs.mergeStub) | ||||||
} | ||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.