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

Commit 80289e0

Browse files
committed
test: migrate to Jest
1 parent ef04292 commit 80289e0

File tree

8 files changed

+4063
-870
lines changed

8 files changed

+4063
-870
lines changed

lib/format.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
*
44
* @param {Object} report
55
*/
6-
const format = report => {
7-
const { commits } = report
8-
6+
function format({ commits }) {
97
// Keep errors/warnings count
108
let errorsCount = 0
119
let warnsCount = 0
@@ -34,11 +32,19 @@ There were the following issues with this Pull Request
3432
3533
${message}
3634
37-
You may need to [change the commit messages](https://help.github.com/articles/changing-a-commit-message/) to comply with the repository contributing guidelines.
35+
You may need to [change the commit messages][ref] to comply with the \
36+
repository contributing guidelines.
3837
3938
--------
4039
41-
🤖 This comment was generated by [**commitlint[bot]**](https://github.com/ahmed-taj/commitlint-bot). Please report issues [here](https://github.com/ahmed-taj/commitlint-bot/issues). Happy coding!
40+
🤖 This comment was generated by [**commitlint[bot]**][repo]. Please report \
41+
issues [here][issues].
42+
43+
Happy coding!
44+
45+
[ref]: https://help.github.com/articles/changing-a-commit-message/
46+
[repo]: https://github.com/ahmed-taj/commitlint-bot
47+
[issues]: https://github.com/ahmed-taj/commitlint-bot/issues
4248
`
4349
}
4450
return { summary, message }

lib/lint.js

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ const format = require('./format')
99
* Runs commitlint against all commits of the pull request and sets an appropriate
1010
* status check
1111
*/
12-
const commitlint = async ({ github, payload }) => {
13-
const { name, owner } = payload.repository
14-
const { number } = payload.pull_request
12+
async function commitlint(context) {
13+
const { github } = context
14+
const pull = context.issue()
15+
const { sha } = context.payload.pull_request.head
16+
const repo = context.repo()
1517

1618
// Hold this PR info
17-
const statusInfo = {
18-
sha: payload.pull_request.head.sha,
19-
repo: name,
20-
owner: owner.login,
21-
context: 'commitlint'
22-
}
19+
const statusInfo = { ...repo, sha, context: 'commitlint' }
2320

2421
// Pending
2522
await github.repos.createStatus({
@@ -29,44 +26,37 @@ const commitlint = async ({ github, payload }) => {
2926
})
3027

3128
// Paginate all PR commits
32-
github.paginate(
33-
github.pullRequests.getCommits({ repo: name, owner: owner.login, number }),
34-
async commits => {
35-
// empty summary
36-
const report = { valid: true, commits: {} }
37-
const { rules } = await load(config)
38-
39-
// Iterates over all commits
40-
for (const d of commits.data) {
41-
const { valid, errors, warnings } = await lint(d.commit.message, rules)
42-
if (!valid) {
43-
report.valid = false
44-
}
29+
github.paginate(github.pullRequests.getCommits(pull), async ({ data }) => {
30+
// empty summary
31+
const report = { valid: true, commits: {} }
32+
const { rules } = await load(config)
33+
34+
// Iterates over all commits
35+
for (const d of data) {
36+
const { valid, errors, warnings } = await lint(d.commit.message, rules)
37+
if (!valid) {
38+
report.valid = false
39+
}
4540

46-
if (errors.length > 0 || warnings.length > 0) {
47-
report.commits[d.sha] = { errors, warnings }
48-
}
41+
if (errors.length > 0 || warnings.length > 0) {
42+
report.commits[d.sha] = { errors, warnings }
4943
}
44+
}
5045

51-
const { summary, message } = format(report)
46+
const { summary, message } = format(report)
5247

53-
// Final status
54-
await github.repos.createStatus({
55-
...statusInfo,
56-
state: report.valid ? 'success' : 'failure',
57-
description: summary
58-
})
59-
// Write a comment with the details (if any)
60-
if (message) {
61-
await github.issues.createComment({
62-
repo: name,
63-
owner: owner.login,
64-
number,
65-
body: message
66-
})
67-
}
48+
// Final status
49+
await github.repos.createStatus({
50+
...statusInfo,
51+
state: report.valid ? 'success' : 'failure',
52+
description: summary
53+
})
54+
55+
// Write a comment with the details (if any)
56+
if (message !== '') {
57+
await github.issues.createComment({ ...pull, body: message })
6858
}
69-
)
59+
})
7060
}
7161

7262
module.exports = commitlint

0 commit comments

Comments
 (0)