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

Commit 964642d

Browse files
committed
feat: remove old comments
1 parent c44093c commit 964642d

11 files changed

+8946
-7420
lines changed

.vs/slnx.sqlite

1.45 MB
Binary file not shown.

.vs/slnx.sqlite-journal

16.5 KB
Binary file not shown.

README.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# commitlint [bot]
22

3-
4-
[![Travis](https://img.shields.io/travis/ahmed-taj/commitlint-bot.svg)](https://travis-ci.org/ahmed-taj/commitlint-bot)
3+
[![Travis](https://img.shields.io/travis/z0al/commitlint-bot.svg)](https://travis-ci.org/z0al/commitlint-bot)
54
[![npm](https://img.shields.io/npm/v/commitlint-bot.svg)](https://www.npmjs.com/package/commitlint-bot)
65

76
<p align="center">
@@ -15,9 +14,9 @@ and sets an appropriate status check.
1514

1615
## Usage
1716

18-
1. Browse to [GitHub Apps - commitlint][apps]
19-
2. Accept the permissions
20-
3. Allow access to repositories
17+
1. Browse to [GitHub Apps - commitlint][apps]
18+
2. Accept the permissions
19+
3. Allow access to repositories
2120

2221
On the next pull request, a status check from `commitlint` will appear:
2322

@@ -38,30 +37,29 @@ For best results, enable branch protection (in the repository's settings) and re
3837

3938
## What is missing?
4039

41-
We don't currently support custom configuration (i.e. `.commitlint.yml` or `.commitlint.json`), but [we will](https://github.com/ahmed-taj/commitlint-bot/issues/1)
40+
We don't currently support custom configuration (i.e. `.commitlint.yml` or `.commitlint.json`), but [we will](https://github.com/z0al/commitlint-bot/issues/1)
4241

4342
## Development
4443

45-
1. Setup the repo:
44+
1. Setup the repo:
4645

4746
```shell
48-
git clone https://github.com/ahmed-taj/commitlint-bot.git
47+
git clone https://github.com/z0al/commitlint-bot.git
4948
cd commitlint-bot
5049
npm install
5150
```
5251

53-
2. Create your own [GitHub app][]
54-
3. Store the private key as `private-key.pem` somewhere safe, and point to its location in `.env`
55-
4. Start the app with `APP_ID=1234 npm start` where `1234` is your GitHub app's ID
56-
5. Update your GitHub app's Webhook URL to your localtunnel.me URL
52+
2. Create your own [GitHub app][]
53+
3. Store the private key as `private-key.pem` somewhere safe, and point to its location in `.env`
54+
4. Start the app with `APP_ID=1234 npm start` where `1234` is your GitHub app's ID
55+
5. Update your GitHub app's Webhook URL to your localtunnel.me URL
5756

58-
[GitHub app]: https://probot.github.io/docs/development/#configure-a-github-app
57+
[github app]: https://probot.github.io/docs/development/#configure-a-github-app
5958

6059
## Deployment
6160

6261
See [docs/deploy.md](./docs/deploy.md) for more info.
6362

64-
6563
## Credits
6664

6765
Robot designed by [Freepik](https://www.freepik.com/free-vector/fun-pack-of-robots-avatars_1258314.htm).
@@ -74,4 +72,4 @@ Give it a star(:star:) :point_up_2:
7472

7573
## License
7674

77-
MIT © [Ahmed T. Ali](https://github.com/ahmed-taj)
75+
MIT © [Ahmed T. Ali](https://github.com/z0al)

app.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"name": "commitlint-bot",
3-
"description": "A GitHub App that runs commitlint for you",
4-
"keywords": ["validate", "commit", "pr", "conventional", "git", "probot-app"],
5-
"repository": "https://github.com/ahmed-taj/commitlint-bot",
6-
"env": {
7-
"PRIVATE_KEY": {
8-
"description": "the private key of your GitHub App."
9-
},
10-
"APP_ID": {
11-
"description": "the ID of your GitHub App"
12-
},
13-
"WEBHOOK_SECRET": {
14-
"description": "the secret configured for your GitHub App"
15-
}
16-
}
2+
"name": "commitlint-bot",
3+
"description": "A GitHub App that runs commitlint for you",
4+
"keywords": ["validate", "commit", "pr", "conventional", "git", "probot-app"],
5+
"repository": "https://github.com/z0al/commitlint-bot",
6+
"env": {
7+
"PRIVATE_KEY": {
8+
"description": "the private key of your GitHub App."
9+
},
10+
"APP_ID": {
11+
"description": "the ID of your GitHub App"
12+
},
13+
"WEBHOOK_SECRET": {
14+
"description": "the secret configured for your GitHub App"
15+
}
16+
}
1717
}

index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Ours
2-
const commitlint = require('./lib/lint')
2+
const commitlint = require("./lib/lint");
33

44
module.exports = robot => {
5-
// For more information on building apps:
6-
// https://probot.github.io/docs/
7-
robot.on('pull_request.opened', commitlint)
8-
robot.on('pull_request.synchronize', commitlint)
9-
}
5+
// For more information on building apps:
6+
// https://probot.github.io/docs/
7+
robot.on("pull_request.opened", commitlint);
8+
robot.on("pull_request.synchronize", commitlint);
9+
};

lib/comments.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/**
2-
* Checks for a previous bot comment, if found returns the commen
2+
* Checks for a previous bot comment, if found returns the comment
33
*/
4-
async function checkComments(issues,pull){
5-
const comments = await issues.getComments(pull)
6-
return comment = comments.data.find(comment => comment.user.login === process.env.APP_NAME + '[bot]')
4+
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+
));
79
}
810

9-
module.exports = checkComments
11+
module.exports = checkComments;

lib/format.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ issues [here][issues].
1414
Happy coding!
1515
1616
[ref]: https://help.github.com/articles/changing-a-commit-message/
17-
[repo]: https://github.com/ahmed-taj/commitlint-bot
18-
[issues]: https://github.com/ahmed-taj/commitlint-bot/issues
19-
`
17+
[repo]: https://github.com/z0al/commitlint-bot
18+
[issues]: https://github.com/z0al/commitlint-bot/issues
19+
`;
2020

2121
/**
2222
* Formats array of commits warnings/errors as GitHub comment
2323
*
2424
* @param {Array} report
2525
*/
2626
function format(commits) {
27-
let message = ''
27+
let message = "";
2828

29-
commits.forEach(c => {
30-
message += `* Commit: ${c.sha}\n`
31-
message += c.errors.map(e => ` - ✖ ${e.message}\n`).join('')
32-
message += c.warnings.map(w => ` - ⚠ ${w.message}\n`).join('')
33-
})
29+
commits.forEach(c => {
30+
message += `* Commit: ${c.sha}\n`;
31+
message += c.errors.map(e => ` - ✖ ${e.message}\n`).join("");
32+
message += c.warnings.map(w => ` - ⚠ ${w.message}\n`).join("");
33+
});
3434

35-
return template.replace('<PLACEHOLDER>', message)
35+
return template.replace("<PLACEHOLDER>", message);
3636
}
3737

38-
module.exports = format
38+
module.exports = format;

lib/lint.js

+66-57
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,87 @@
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(d.commit.message, rules);
45+
if (!valid) {
46+
report.valid = false;
47+
}
4848

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

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

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

65-
// Write a comment with the details (if any)
66-
if (errorsCount > 0 || warnsCount > 0) {
67-
const message = format(report.commits)
68-
const comment = await checkComments(issues,pull)
69-
if(comment){ // edits previous bot comment if found
70-
await issues.editComment({...pull,id:comment.id,body:message})
71-
}else{ // if no previous comment create a new one
72-
await issues.createComment({ ...pull, body: message })
73-
}
74-
}
75-
})
65+
// Get commit
66+
const comment = await checkComments(issues, pull);
67+
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+
});
7685
}
7786

78-
module.exports = commitlint
87+
module.exports = commitlint;

0 commit comments

Comments
 (0)