Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Commit 1813dbe

Browse files
committed
fix(lint): return 'paginate' call - it's async!
1 parent 80289e0 commit 1813dbe

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

‎lib/lint.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,26 @@ const format = require('./format')
1010
* status check
1111
*/
1212
async function commitlint(context) {
13-
const{ github }=context
13+
// 1. Extract necessary info
1414
const pull = context.issue()
1515
const { sha } = context.payload.pull_request.head
1616
const repo = context.repo()
1717

18+
// GH API
19+
const { paginate, issues, repos, pullRequests } = context.github
20+
1821
// Hold this PR info
1922
const statusInfo = { ...repo, sha, context: 'commitlint' }
2023

2124
// Pending
22-
await github.repos.createStatus({
25+
await repos.createStatus({
2326
...statusInfo,
2427
state: 'pending',
2528
description: 'Waiting for the status to be reported'
2629
})
2730

2831
// Paginate all PR commits
29-
github.paginate(github.pullRequests.getCommits(pull), async ({ data }) => {
32+
returnpaginate(pullRequests.getCommits(pull), async ({ data }) => {
3033
// empty summary
3134
const report = { valid: true, commits: {} }
3235
const { rules } = await load(config)
@@ -46,15 +49,15 @@ async function commitlint(context) {
4649
const { summary, message } = format(report)
4750

4851
// Final status
49-
await github.repos.createStatus({
52+
await repos.createStatus({
5053
...statusInfo,
5154
state: report.valid ? 'success' : 'failure',
5255
description: summary
5356
})
5457

5558
// Write a comment with the details (if any)
56-
if (message!=='') {
57-
await github.issues.createComment({ ...pull, body: message })
59+
if (message) {
60+
await issues.createComment({ ...pull, body: message })
5861
}
5962
})
6063
}

‎test/lint.test.js‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ beforeEach(() => {
1919
issues: { createComment: jest.fn() },
2020
repos: { createStatus: jest.fn() },
2121
pullRequests: {
22-
getCommits: jest.fn().mockReturnValue({
23-
data: [{ sha: 'abcd', commit: { message: 'bad message' } }]
24-
})
22+
getCommits: jest
23+
.fn()
24+
.mockReturnValueOnce({
25+
data: [{ sha: 'abcd', commit: { message: 'good: message' } }]
26+
})
27+
.mockReturnValue({
28+
data: [{ sha: 'abcd', commit: { message: 'bad message' } }]
29+
})
2530
},
2631
paginate: (fn, cb) => cb(fn)
2732
}
@@ -43,7 +48,12 @@ test('fetching the list of commits', async () => {
4348
)
4449
})
4550

46-
// test('comment with errors/warnings', async () => {
47-
// await robot.receive(events.opened)
48-
// expect(github.issues.createComment).toHaveBeenCalled()
49-
// })
51+
test('comment with errors/warnings', async () => {
52+
// Good message
53+
await robot.receive(events.opened)
54+
expect(github.issues.createComment).not.toHaveBeenCalled()
55+
56+
// Bad message
57+
await robot.receive(events.opened)
58+
expect(github.issues.createComment).toHaveBeenCalled()
59+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /