-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: rename repository
probot/dco
-> dcoapp/app
closes #161
- Loading branch information
Showing
5 changed files
with
82 additions
and
82 deletions.
There are no files selected for viewing
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
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,176 +1,176 @@ | ||
const getDCOStatus = require('./lib/dco.js') | ||
const requireMembers = require('./lib/requireMembers.js') | ||
const getDCOStatus = require("./lib/dco.js"); | ||
const requireMembers = require("./lib/requireMembers.js"); | ||
|
||
/** | ||
* @param { {app: import('probot').Probot}} app | ||
*/ | ||
module.exports = ({ app }) => { | ||
app.on( | ||
[ | ||
'pull_request.opened', | ||
'pull_request.synchronize', | ||
'check_run.rerequested' | ||
"pull_request.opened", | ||
"pull_request.synchronize", | ||
"check_run.rerequested", | ||
], | ||
check | ||
) | ||
); | ||
|
||
async function check (context) { | ||
const timeStart = new Date() | ||
async function check(context) { | ||
const timeStart = new Date(); | ||
|
||
const config = await context.config('dco.yml', { | ||
const config = await context.config("dco.yml", { | ||
require: { | ||
members: true | ||
} | ||
}) | ||
const requireForMembers = config.require.members | ||
members: true, | ||
}, | ||
}); | ||
const requireForMembers = config.require.members; | ||
|
||
const pr = context.payload.pull_request | ||
const pr = context.payload.pull_request; | ||
|
||
const compare = await context.octokit.repos.compareCommits( | ||
context.repo({ | ||
base: pr.base.sha, | ||
head: pr.head.sha | ||
head: pr.head.sha, | ||
}) | ||
) | ||
); | ||
|
||
const commits = compare.data.commits | ||
const commits = compare.data.commits; | ||
const dcoFailed = await getDCOStatus( | ||
commits, | ||
requireMembers(requireForMembers, context), | ||
context.payload.pull_request.html_url | ||
) | ||
); | ||
|
||
if (!dcoFailed.length) { | ||
await context.octokit.checks | ||
.create( | ||
context.repo({ | ||
name: 'DCO', | ||
name: "DCO", | ||
head_branch: pr.head.ref, | ||
head_sha: pr.head.sha, | ||
status: 'completed', | ||
status: "completed", | ||
started_at: timeStart, | ||
conclusion: 'success', | ||
conclusion: "success", | ||
completed_at: new Date(), | ||
output: { | ||
title: 'DCO', | ||
summary: 'All commits are signed off!' | ||
} | ||
title: "DCO", | ||
summary: "All commits are signed off!", | ||
}, | ||
}) | ||
) | ||
.catch(function checkFails (error) { | ||
.catch(function checkFails(error) { | ||
if (error.status === 403) { | ||
context.log.info( | ||
'resource not accessible, creating status instead' | ||
) | ||
"resource not accessible, creating status instead" | ||
); | ||
// create status | ||
const params = { | ||
sha: pr.head.sha, | ||
context: 'DCO', | ||
state: 'success', | ||
description: 'All commits are signed off!', | ||
target_url: 'https://github.com/probot/dco#how-it-works' | ||
} | ||
context: "DCO", | ||
state: "success", | ||
description: "All commits are signed off!", | ||
target_url: "https://github.com/dcoapp/app#how-it-works", | ||
}; | ||
return context.octokit.repos.createCommitStatus( | ||
context.repo(params) | ||
) | ||
); | ||
} | ||
|
||
throw error | ||
}) | ||
throw error; | ||
}); | ||
} else { | ||
let summary = [] | ||
let summary = []; | ||
dcoFailed.forEach(function (commit) { | ||
summary.push( | ||
`Commit sha: [${commit.sha.substr(0, 7)}](${commit.url}), Author: ${ | ||
commit.author | ||
}, Committer: ${commit.committer}; ${commit.message}` | ||
) | ||
}) | ||
summary = summary.join('\n') | ||
); | ||
}); | ||
summary = summary.join("\n"); | ||
if (dcoFailed.length === 1) { | ||
summary = handleOneCommit(pr, dcoFailed) + `\n\n${summary}` | ||
summary = handleOneCommit(pr, dcoFailed) + `\n\n${summary}`; | ||
} else { | ||
summary = | ||
handleMultipleCommits(pr, commits.length, dcoFailed) + | ||
`\n\n${summary}` | ||
`\n\n${summary}`; | ||
} | ||
|
||
await context.octokit.checks | ||
.create( | ||
context.repo({ | ||
name: 'DCO', | ||
name: "DCO", | ||
head_branch: pr.head.ref, | ||
head_sha: pr.head.sha, | ||
status: 'completed', | ||
status: "completed", | ||
started_at: timeStart, | ||
conclusion: 'action_required', | ||
conclusion: "action_required", | ||
completed_at: new Date(), | ||
output: { | ||
title: 'DCO', | ||
summary | ||
title: "DCO", | ||
summary, | ||
}, | ||
actions: [ | ||
{ | ||
label: 'Set DCO to pass', | ||
description: 'would set status to passing', | ||
identifier: 'override' | ||
} | ||
] | ||
label: "Set DCO to pass", | ||
description: "would set status to passing", | ||
identifier: "override", | ||
}, | ||
], | ||
}) | ||
) | ||
.catch(function checkFails (error) { | ||
.catch(function checkFails(error) { | ||
if (error.status === 403) { | ||
context.log.info( | ||
'resource not accessible, creating status instead' | ||
) | ||
"resource not accessible, creating status instead" | ||
); | ||
// create status | ||
const description = dcoFailed[ | ||
dcoFailed.length - 1 | ||
].message.substring(0, 140) | ||
].message.substring(0, 140); | ||
const params = { | ||
sha: pr.head.sha, | ||
context: 'DCO', | ||
state: 'failure', | ||
context: "DCO", | ||
state: "failure", | ||
description, | ||
target_url: 'https://github.com/probot/dco#how-it-works' | ||
} | ||
target_url: "https://github.com/dcoapp/app#how-it-works", | ||
}; | ||
return context.octokit.repos.createCommitStatus( | ||
context.repo(params) | ||
) | ||
); | ||
} | ||
|
||
throw error | ||
}) | ||
throw error; | ||
}); | ||
} | ||
} | ||
|
||
// This option is only presented to users with Write Access to the repo | ||
app.on('check_run.requested_action', setStatusPass) | ||
async function setStatusPass (context) { | ||
const timeStart = new Date() | ||
app.on("check_run.requested_action", setStatusPass); | ||
async function setStatusPass(context) { | ||
const timeStart = new Date(); | ||
|
||
await context.octokit.checks.create( | ||
context.repo({ | ||
name: 'DCO', | ||
name: "DCO", | ||
head_branch: context.payload.check_run.check_suite.head_branch, | ||
head_sha: context.payload.check_run.head_sha, | ||
status: 'completed', | ||
status: "completed", | ||
started_at: timeStart, | ||
conclusion: 'success', | ||
conclusion: "success", | ||
completed_at: new Date(), | ||
output: { | ||
title: 'DCO', | ||
summary: 'Commit sign-off was manually approved.' | ||
} | ||
title: "DCO", | ||
summary: "Commit sign-off was manually approved.", | ||
}, | ||
}) | ||
) | ||
); | ||
} | ||
} | ||
}; | ||
|
||
function handleOneCommit (pr, dcoFailed) { | ||
return `You only have one commit incorrectly signed off! To fix, first ensure you have a local copy of your branch by [checking out the pull request locally via command line](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally). Next, head to your local branch and run: \n\`\`\`bash\ngit commit --amend --no-edit --signoff\n\`\`\`\nNow your commits will have your sign off. Next run \n\`\`\`bash\ngit push --force-with-lease origin ${pr.head.ref}\n\`\`\`` | ||
function handleOneCommit(pr, dcoFailed) { | ||
return `You only have one commit incorrectly signed off! To fix, first ensure you have a local copy of your branch by [checking out the pull request locally via command line](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally). Next, head to your local branch and run: \n\`\`\`bash\ngit commit --amend --no-edit --signoff\n\`\`\`\nNow your commits will have your sign off. Next run \n\`\`\`bash\ngit push --force-with-lease origin ${pr.head.ref}\n\`\`\``; | ||
} | ||
|
||
function handleMultipleCommits (pr, commitLength, dcoFailed) { | ||
return `You have ${dcoFailed.length} commits incorrectly signed off. To fix, first ensure you have a local copy of your branch by [checking out the pull request locally via command line](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally). Next, head to your local branch and run: \n\`\`\`bash\ngit rebase HEAD~${commitLength} --signoff\n\`\`\`\n Now your commits will have your sign off. Next run \n\`\`\`bash\ngit push --force-with-lease origin ${pr.head.ref}\n\`\`\`` | ||
function handleMultipleCommits(pr, commitLength, dcoFailed) { | ||
return `You have ${dcoFailed.length} commits incorrectly signed off. To fix, first ensure you have a local copy of your branch by [checking out the pull request locally via command line](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally). Next, head to your local branch and run: \n\`\`\`bash\ngit rebase HEAD~${commitLength} --signoff\n\`\`\`\n Now your commits will have your sign off. Next run \n\`\`\`bash\ngit push --force-with-lease origin ${pr.head.ref}\n\`\`\``; | ||
} |
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