Skip to content

Commit

Permalink
fix: Send correct payload for changing labels (#715)
Browse files Browse the repository at this point in the history
* fix: issues labels

* Update changelog.rst
  • Loading branch information
robinmayerhofer authored May 11, 2023
1 parent 27dd124 commit d9fb002
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
36 changes: 18 additions & 18 deletions __tests__/unit/actions/labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('check that replace replaces existing labels', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: settings.replace })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(settings.replace)
})

test('check that add appends to existing labels', async () => {
Expand All @@ -25,7 +25,7 @@ test('check that add appends to existing labels', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['another label', 'test label', 'production', 'deploy'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['another label', 'test label', 'production', 'deploy'])
})

test('check that delete removes from existing labels', async () => {
Expand All @@ -38,7 +38,7 @@ test('check that delete removes from existing labels', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['another label', 'test label'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['another label', 'test label'])
})

test('check the order of replace, add, delete', async () => {
Expand All @@ -54,7 +54,7 @@ test('check the order of replace, add, delete', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['test present', 'addition'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['test present', 'addition'])
})

test('check that settings can be a single value', async () => {
Expand All @@ -69,7 +69,7 @@ test('check that settings can be a single value', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['replace', 'addition'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['replace', 'addition'])
})

test('check that unknown mode throw errors', async () => {
Expand All @@ -93,7 +93,7 @@ test('check that labels setting accepts an array', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.addLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.addLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.addLabels.mock.calls[0][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
})

test('check that labels setting defaults to add mode', async () => {
Expand All @@ -106,7 +106,7 @@ test('check that labels setting defaults to add mode', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.addLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.addLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.addLabels.mock.calls[0][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
})

test('check that set mode works', async () => {
Expand All @@ -120,7 +120,7 @@ test('check that set mode works', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
})

test('check that delete mode works', async () => {
Expand All @@ -134,7 +134,7 @@ test('check that delete mode works', async () => {

await labels.afterValidate(context, settings)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(1)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['test2', 'label1'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['test2', 'label1'])
})

test('check that issues from scheduler are labelled', async () => {
Expand All @@ -152,9 +152,9 @@ test('check that issues from scheduler are labelled', async () => {
}]
await labels.afterValidate(context, settings, '', schedulerResult)
expect(context.octokit.issues.addLabels.mock.calls.length).toBe(3)
expect(context.octokit.issues.addLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.addLabels.mock.calls[1][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.addLabels.mock.calls[2][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.addLabels.mock.calls[0][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
expect(context.octokit.issues.addLabels.mock.calls[1][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
expect(context.octokit.issues.addLabels.mock.calls[2][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
})

test('check that labels from scheduler are deleted', async () => {
Expand All @@ -173,9 +173,9 @@ test('check that labels from scheduler are deleted', async () => {
}]
await labels.afterValidate(context, settings, '', schedulerResult)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(3)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['test2', 'label1'] })
expect(context.octokit.issues.setLabels.mock.calls[1][0].labels).toStrictEqual({ labels: ['test2', 'label1'] })
expect(context.octokit.issues.setLabels.mock.calls[2][0].labels).toStrictEqual({ labels: ['test2', 'label1'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['test2', 'label1'])
expect(context.octokit.issues.setLabels.mock.calls[1][0].labels).toStrictEqual(['test2', 'label1'])
expect(context.octokit.issues.setLabels.mock.calls[2][0].labels).toStrictEqual(['test2', 'label1'])
})

test('check that labels from scheduler are set', async () => {
Expand All @@ -194,9 +194,9 @@ test('check that labels from scheduler are set', async () => {
}]
await labels.afterValidate(context, settings, '', schedulerResult)
expect(context.octokit.issues.setLabels.mock.calls.length).toBe(3)
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.setLabels.mock.calls[1][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.setLabels.mock.calls[2][0].labels).toStrictEqual({ labels: ['testLabel', '2ndTestLabel'] })
expect(context.octokit.issues.setLabels.mock.calls[0][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
expect(context.octokit.issues.setLabels.mock.calls[1][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
expect(context.octokit.issues.setLabels.mock.calls[2][0].labels).toStrictEqual(['testLabel', '2ndTestLabel'])
})

const createMockContext = (labels = [], eventName = undefined) => {
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CHANGELOG
=====================================
| May 11, 2023: fix: Send correct payload for changing labels `#715 <https://github.com/mergeability/mergeable/pull/715>`_
| April 25, 2023: feat: Add author validator `#710 <https://github.com/mergeability/mergeable/pull/710>`_
| March 13, 2023: fix: Replace delete with remove in changeset validator `#705 <https://github.com/mergeability/mergeable/pull/705>`_
| March 7, 2023: fix: Extend checks supported events `#700 <https://github.com/mergeability/mergeable/pull/700>`_
Expand Down
4 changes: 2 additions & 2 deletions lib/github/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class GithubAPI {

try {
return await context.octokit.issues.addLabels(
context.repo({ issue_number: issueNumber, labels: { labels: labels } })
context.repo({ issue_number: issueNumber, labels: labels })
)
} catch (err) {
return checkCommonError(err, context, callFn)
Expand All @@ -153,7 +153,7 @@ class GithubAPI {

try {
return await context.octokit.issues.setLabels(
context.repo({ issue_number: issueNumber, labels: { labels: labels } })
context.repo({ issue_number: issueNumber, labels: labels })
)
} catch (err) {
return checkCommonError(err, context, callFn)
Expand Down

0 comments on commit d9fb002

Please sign in to comment.