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

Commit dfba0b7

Browse files
committed
build(deps): upgrade commitlint
1 parent 5fc75a8 commit dfba0b7

File tree

9 files changed

+7458
-8949
lines changed

9 files changed

+7458
-8949
lines changed

lib/comments.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* Checks for a previous bot comment, if found returns the comment
33
*/
44
async function checkComments(issues, pull) {
5-
const comments = await issues.getComments(pull);
6-
return (comment = comments.data.find(
7-
comment => comment.user.login === process.env.APP_NAME + "[bot]"
8-
));
5+
const comments = await issues.getComments(pull);
6+
return (comment = comments.data.find(
7+
comment => comment.user.login === process.env.APP_NAME + '[bot]'
8+
));
99
}
1010

1111
module.exports = checkComments;

lib/config.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/**
2-
* commitlint Conventional Commits rules
3-
*
2+
* commitlint Conventional Commits rules
3+
*
44
* https://conventionalcommits.org
55
*/
6-
module.exports = {
7-
rules: {
8-
// A longer commit body MAY be provided after the short description. The
9-
// body MUST begin one blank line after the description.
10-
'body-leading-blank': [2, 'always'],
11-
// A description MUST immediately follow the type/scope prefix.
12-
'subject-empty': [2, 'never'],
13-
// commits MUST be prefixed with a type, which consists of a verb, feat,
14-
// fix, etc., followed by a colon and a space.
15-
'type-empty': [2, 'never']
16-
}
17-
}
6+
module.exports = require('@commitlint/config-conventional');

lib/format.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ Happy coding!
3131
* @param {Array} report
3232
*/
3333
function format(commits) {
34-
let details = "";
35-
let message = commits.map(c => `* ${c.sha}`).join("\n")
36-
37-
commits.forEach(c => {
38-
details += `* Commit: ${c.sha}\n`;
39-
details += c.errors.map(e => ` - ✖ ${e.message}\n`).join("");
40-
details += c.warnings.map(w => ` - ⚠ ${w.message}\n`).join("");
41-
});
42-
43-
return template
44-
.replace("<PLACEHOLDER>", message)
45-
.replace("<DETAILS>", details);
34+
let details = '';
35+
let message = commits.map(c => `* ${c.sha}`).join('\n');
36+
37+
commits.forEach(c => {
38+
details += `* Commit: ${c.sha}\n`;
39+
details += c.errors.map(e => ` - ✖ ${e.message}\n`).join('');
40+
details += c.warnings.map(w => ` - ⚠ ${w.message}\n`).join('');
41+
});
42+
43+
return template
44+
.replace('<PLACEHOLDER>', message)
45+
.replace('<DETAILS>', details);
4646
}
4747

4848
module.exports = format;

lib/lint.js

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,94 @@
11
// Packages
2-
const { lint, load } = require("@commitlint/core");
2+
const { lint, load } = require('@commitlint/core');
33

44
// Ours
5-
const config = require("./config");
6-
const format = require("./format");
7-
const checkComments = require("./comments");
5+
const config = require('./config');
6+
const format = require('./format');
7+
const checkComments = require('./comments');
88

99
/**
1010
* Runs commitlint against all commits of the pull request and sets an appropriate
1111
* status check
1212
*/
1313
async function commitlint(context) {
14-
// 1. Extract necessary info
15-
const pull = context.issue();
16-
const { sha } = context.payload.pull_request.head;
17-
const repo = context.repo();
14+
// 1. Extract necessary info
15+
const pull = context.issue();
16+
const { sha } = context.payload.pull_request.head;
17+
const repo = context.repo();
1818

19-
// GH API
20-
const { paginate, issues, repos, pullRequests } = context.github;
19+
// GH API
20+
const { paginate, issues, repos, pullRequests } = context.github;
2121

22-
// Hold this PR info
23-
const statusInfo = { ...repo, sha, context: "commitlint" };
22+
// Hold this PR info
23+
const statusInfo = { ...repo, sha, context: 'commitlint' };
2424

25-
// Pending
26-
await repos.createStatus({
27-
...statusInfo,
28-
state: "pending",
29-
description: "Waiting for the status to be reported"
30-
});
25+
// Pending
26+
await repos.createStatus({
27+
...statusInfo,
28+
state: 'pending',
29+
description: 'Waiting for the status to be reported'
30+
});
3131

32-
// Paginate all PR commits
33-
return paginate(pullRequests.getCommits(pull), async ({ data }) => {
34-
// empty summary
35-
const report = { valid: true, commits: [] };
36-
const { rules } = await load(config);
32+
// Paginate all PR commits
33+
return paginate(pullRequests.getCommits(pull), async ({ data }) => {
34+
// empty summary
35+
const report = { valid: true, commits: [] };
36+
const { rules } = await load(config);
3737

38-
// Keep counters
39-
let errorsCount = 0;
40-
let warnsCount = 0;
38+
// Keep counters
39+
let errorsCount = 0;
40+
let warnsCount = 0;
4141

42-
// Iterates over all commits
43-
for (const d of data) {
44-
const { valid, errors, warnings } = await lint(d.commit.message, rules);
45-
if (!valid) {
46-
report.valid = false;
47-
}
42+
// Iterates over all commits
43+
for (const d of data) {
44+
const { valid, errors, warnings } = await lint(
45+
d.commit.message,
46+
rules
47+
);
48+
if (!valid) {
49+
report.valid = false;
50+
}
4851

49-
if (errors.length > 0 || warnings.length > 0) {
50-
// Update counts
51-
errorsCount += errors.length;
52-
warnsCount += warnings.length;
52+
if (errors.length > 0 || warnings.length > 0) {
53+
// Update counts
54+
errorsCount += errors.length;
55+
warnsCount += warnings.length;
5356

54-
report.commits.push({ sha: d.sha, errors, warnings });
55-
}
56-
}
57+
report.commits.push({ sha: d.sha, errors, warnings });
58+
}
59+
}
5760

58-
// Final status
59-
await repos.createStatus({
60-
...statusInfo,
61-
state: report.valid ? "success" : "failure",
62-
description: `found ${errorsCount} problems, ${warnsCount} warnings`
63-
});
61+
// Final status
62+
await repos.createStatus({
63+
...statusInfo,
64+
state: report.valid ? 'success' : 'failure',
65+
description: `found ${errorsCount} problems, ${warnsCount} warnings`
66+
});
6467

65-
// Get commit
66-
const comment = await checkComments(issues, pull);
68+
// Get commit
69+
const comment = await checkComments(issues, pull);
6770

68-
// Write a comment with the details (if any)
69-
if (errorsCount > 0 || warnsCount > 0) {
70-
const message = format(report.commits);
71-
if (comment) {
72-
// edits previous bot comment if found
73-
await issues.editComment({ ...pull, id: comment.id, body: message });
74-
} else {
75-
// if no previous comment create a new one
76-
await issues.createComment({ ...pull, body: message });
77-
}
78-
} else {
79-
if (comment) {
80-
// edits previous bot comment if found
81-
await issues.deleteComment({ ...pull, comment_id: comment.id });
82-
}
83-
}
84-
});
71+
// Write a comment with the details (if any)
72+
if (errorsCount > 0 || warnsCount > 0) {
73+
const message = format(report.commits);
74+
if (comment) {
75+
// edits previous bot comment if found
76+
await issues.editComment({
77+
...pull,
78+
id: comment.id,
79+
body: message
80+
});
81+
} else {
82+
// if no previous comment create a new one
83+
await issues.createComment({ ...pull, body: message });
84+
}
85+
} else {
86+
if (comment) {
87+
// edits previous bot comment if found
88+
await issues.deleteComment({ ...pull, comment_id: comment.id });
89+
}
90+
}
91+
});
8592
}
8693

8794
module.exports = commitlint;

0 commit comments

Comments
 (0)