This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
8,946 additions
and
7,420 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{ | ||
"name": "commitlint-bot", | ||
"description": "A GitHub App that runs commitlint for you", | ||
"keywords": ["validate", "commit", "pr", "conventional", "git", "probot-app"], | ||
"repository": "https://github.com/ahmed-taj/commitlint-bot", | ||
"env": { | ||
"PRIVATE_KEY": { | ||
"description": "the private key of your GitHub App." | ||
}, | ||
"APP_ID": { | ||
"description": "the ID of your GitHub App" | ||
}, | ||
"WEBHOOK_SECRET": { | ||
"description": "the secret configured for your GitHub App" | ||
} | ||
} | ||
"name": "commitlint-bot", | ||
"description": "A GitHub App that runs commitlint for you", | ||
"keywords": ["validate", "commit", "pr", "conventional", "git", "probot-app"], | ||
"repository": "https://github.com/z0al/commitlint-bot", | ||
"env": { | ||
"PRIVATE_KEY": { | ||
"description": "the private key of your GitHub App." | ||
}, | ||
"APP_ID": { | ||
"description": "the ID of your GitHub App" | ||
}, | ||
"WEBHOOK_SECRET": { | ||
"description": "the secret configured for your GitHub App" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// Ours | ||
const commitlint = require('./lib/lint') | ||
const commitlint = require("./lib/lint"); | ||
|
||
module.exports = robot => { | ||
// For more information on building apps: | ||
// https://probot.github.io/docs/ | ||
robot.on('pull_request.opened', commitlint) | ||
robot.on('pull_request.synchronize', commitlint) | ||
} | ||
// For more information on building apps: | ||
// https://probot.github.io/docs/ | ||
robot.on("pull_request.opened", commitlint); | ||
robot.on("pull_request.synchronize", commitlint); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
/** | ||
* Checks for a previous bot comment, if found returns the commen | ||
* Checks for a previous bot comment, if found returns the comment | ||
*/ | ||
async function checkComments(issues,pull){ | ||
const comments = await issues.getComments(pull) | ||
return comment = comments.data.find(comment => comment.user.login === process.env.APP_NAME + '[bot]') | ||
async function checkComments(issues, pull) { | ||
const comments = await issues.getComments(pull); | ||
return (comment = comments.data.find( | ||
comment => comment.user.login === process.env.APP_NAME + "[bot]" | ||
)); | ||
} | ||
|
||
module.exports = checkComments | ||
module.exports = checkComments; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,87 @@ | ||
// Packages | ||
const { lint, load } = require('@commitlint/core') | ||
const { lint, load } = require("@commitlint/core"); | ||
|
||
// Ours | ||
const config = require('./config') | ||
const format = require('./format') | ||
const checkComments = require('./comments') | ||
const config = require("./config"); | ||
const format = require("./format"); | ||
const checkComments = require("./comments"); | ||
|
||
/** | ||
* Runs commitlint against all commits of the pull request and sets an appropriate | ||
* status check | ||
*/ | ||
async function commitlint(context) { | ||
// 1. Extract necessary info | ||
const pull = context.issue() | ||
const { sha } = context.payload.pull_request.head | ||
const repo = context.repo() | ||
// 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 | ||
// GH API | ||
const { paginate, issues, repos, pullRequests } = context.github; | ||
|
||
// Hold this PR info | ||
const statusInfo = { ...repo, sha, context: 'commitlint' } | ||
// Hold this PR info | ||
const statusInfo = { ...repo, sha, context: "commitlint" }; | ||
|
||
// Pending | ||
await repos.createStatus({ | ||
...statusInfo, | ||
state: 'pending', | ||
description: 'Waiting for the status to be reported' | ||
}) | ||
// Pending | ||
await repos.createStatus({ | ||
...statusInfo, | ||
state: "pending", | ||
description: "Waiting for the status to be reported" | ||
}); | ||
|
||
// Paginate all PR commits | ||
return paginate(pullRequests.getCommits(pull), async ({ data }) => { | ||
// empty summary | ||
const report = { valid: true, commits: [] } | ||
const { rules } = await load(config) | ||
// Paginate all PR commits | ||
return paginate(pullRequests.getCommits(pull), async ({ data }) => { | ||
// empty summary | ||
const report = { valid: true, commits: [] }; | ||
const { rules } = await load(config); | ||
|
||
// Keep counters | ||
let errorsCount = 0 | ||
let warnsCount = 0 | ||
// Keep counters | ||
let errorsCount = 0; | ||
let warnsCount = 0; | ||
|
||
// Iterates over all commits | ||
for (const d of data) { | ||
const { valid, errors, warnings } = await lint(d.commit.message, rules) | ||
if (!valid) { | ||
report.valid = false | ||
} | ||
// Iterates over all commits | ||
for (const d of data) { | ||
const { valid, errors, warnings } = await lint(d.commit.message, rules); | ||
if (!valid) { | ||
report.valid = false; | ||
} | ||
|
||
if (errors.length > 0 || warnings.length > 0) { | ||
// Update counts | ||
errorsCount += errors.length | ||
warnsCount += warnings.length | ||
if (errors.length > 0 || warnings.length > 0) { | ||
// Update counts | ||
errorsCount += errors.length; | ||
warnsCount += warnings.length; | ||
|
||
report.commits.push({ sha: d.sha, errors, warnings }) | ||
} | ||
} | ||
report.commits.push({ sha: d.sha, errors, warnings }); | ||
} | ||
} | ||
|
||
// Final status | ||
await repos.createStatus({ | ||
...statusInfo, | ||
state: report.valid ? 'success' : 'failure', | ||
description: `found ${errorsCount} problems, ${warnsCount} warnings` | ||
}) | ||
// Final status | ||
await repos.createStatus({ | ||
...statusInfo, | ||
state: report.valid ? "success" : "failure", | ||
description: `found ${errorsCount} problems, ${warnsCount} warnings` | ||
}); | ||
|
||
// Write a comment with the details (if any) | ||
if (errorsCount > 0 || warnsCount > 0) { | ||
const message = format(report.commits) | ||
const comment = await checkComments(issues,pull) | ||
if(comment){ // edits previous bot comment if found | ||
await issues.editComment({...pull,id:comment.id,body:message}) | ||
}else{ // if no previous comment create a new one | ||
await issues.createComment({ ...pull, body: message }) | ||
} | ||
} | ||
}) | ||
// Get commit | ||
const comment = await checkComments(issues, pull); | ||
|
||
// Write a comment with the details (if any) | ||
if (errorsCount > 0 || warnsCount > 0) { | ||
const message = format(report.commits); | ||
if (comment) { | ||
// edits previous bot comment if found | ||
await issues.editComment({ ...pull, id: comment.id, body: message }); | ||
} else { | ||
// if no previous comment create a new one | ||
await issues.createComment({ ...pull, body: message }); | ||
} | ||
} else { | ||
if (comment) { | ||
// edits previous bot comment if found | ||
await issues.deleteComment({ ...pull, comment_id: comment.id }); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
module.exports = commitlint | ||
module.exports = commitlint; |
Oops, something went wrong.