Skip to content

Commit 1d28f56

Browse files
authored
fix: set fallback value for description payload (#655)
* fix: set fallback value for `description` payload In case the payload `body` somehow returns undefined or null, we set the fallback value to an empty string. * chore: update changelog * chore: add tests for `description` validator Add tests if the value of the `description` is `undefined` or `null`.
1 parent 7594d40 commit 1d28f56

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

__tests__/unit/validators/description.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ test('isMergeable is false if the PR body is empty', async () => {
2828
let descriptionValidation = await description.processValidate(createMockPR(''), settings)
2929
expect(descriptionValidation.status).toBe('fail')
3030

31+
descriptionValidation = await description.processValidate(createMockPR(undefined), settings)
32+
expect(descriptionValidation.status).toBe('fail')
33+
34+
descriptionValidation = await description.processValidate(createMockPR(null), settings)
35+
expect(descriptionValidation.status).toBe('fail')
36+
3137
descriptionValidation = await description.processValidate(createMockPR('Some Description'), settings)
3238
expect(descriptionValidation.status).toBe('pass')
3339
})

docs/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CHANGELOG
22
=====================================
3-
| August 20, 2022: fix: supported events for `request_review` action `#623 <https://github.com/mergeability/mergeable/pull/651>`_
3+
| August 25, 2022: fix: set fallback value for `description` payload `#655 <https://github.com/mergeability/mergeable/pull/655>`_
4+
| August 20, 2022: fix: supported events for `request_review` action `#651 <https://github.com/mergeability/mergeable/pull/651>`_
45
| August 2, 2022: feat: Add newest_only commit validation setting `#649 <https://github.com/mergeability/mergeable/pull/649>`_
56
| April 7, 2022: feat: Support adding deployment labels from values `#631 <https://github.com/mergeability/mergeable/pull/631>`_
67
| March 22, 2022: fix: pass comment instance to removeErrorComments `#626 <https://github.com/mergeability/mergeable/pull/626>`_

lib/validators/description.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Description extends Validator {
4040
}
4141

4242
async validate (context, validationSettings) {
43-
const description = this.getPayload(context).body
43+
const description = this.getPayload(context).body || ''
4444

4545
return this.processOptions(
4646
validationSettings,

0 commit comments

Comments
 (0)