Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
fix(lint): return 'paginate' call - it's async!
Browse files Browse the repository at this point in the history
  • Loading branch information
z0al committed Feb 15, 2018
1 parent 80289e0 commit 1813dbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
15 changes: 9 additions & 6 deletions lib/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ const format = require('./format')
* status check
*/
async function commitlint(context) {
const { github } = context
// 1. Extract necessary info
const pull = context.issue()
const { sha } = context.payload.pull_request.head
const repo = context.repo()

// GH API
const { paginate, issues, repos, pullRequests } = context.github

// Hold this PR info
const statusInfo = { ...repo, sha, context: 'commitlint' }

// Pending
await github.repos.createStatus({
await repos.createStatus({
...statusInfo,
state: 'pending',
description: 'Waiting for the status to be reported'
})

// Paginate all PR commits
github.paginate(github.pullRequests.getCommits(pull), async ({ data }) => {
return paginate(pullRequests.getCommits(pull), async ({ data }) => {
// empty summary
const report = { valid: true, commits: {} }
const { rules } = await load(config)
Expand All @@ -46,15 +49,15 @@ async function commitlint(context) {
const { summary, message } = format(report)

// Final status
await github.repos.createStatus({
await repos.createStatus({
...statusInfo,
state: report.valid ? 'success' : 'failure',
description: summary
})

// Write a comment with the details (if any)
if (message !== '') {
await github.issues.createComment({ ...pull, body: message })
if (message) {
await issues.createComment({ ...pull, body: message })
}
})
}
Expand Down
24 changes: 17 additions & 7 deletions test/lint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ beforeEach(() => {
issues: { createComment: jest.fn() },
repos: { createStatus: jest.fn() },
pullRequests: {
getCommits: jest.fn().mockReturnValue({
data: [{ sha: 'abcd', commit: { message: 'bad message' } }]
})
getCommits: jest
.fn()
.mockReturnValueOnce({
data: [{ sha: 'abcd', commit: { message: 'good: message' } }]
})
.mockReturnValue({
data: [{ sha: 'abcd', commit: { message: 'bad message' } }]
})
},
paginate: (fn, cb) => cb(fn)
}
Expand All @@ -43,7 +48,12 @@ test('fetching the list of commits', async () => {
)
})

// test('comment with errors/warnings', async () => {
// await robot.receive(events.opened)
// expect(github.issues.createComment).toHaveBeenCalled()
// })
test('comment with errors/warnings', async () => {
// Good message
await robot.receive(events.opened)
expect(github.issues.createComment).not.toHaveBeenCalled()

// Bad message
await robot.receive(events.opened)
expect(github.issues.createComment).toHaveBeenCalled()
})

0 comments on commit 1813dbe

Please sign in to comment.