Skip to content

Commit

Permalink
docs: rename repository probot/dco -> dcoapp/app
Browse files Browse the repository at this point in the history
closes #161
  • Loading branch information
gr2m committed Jan 18, 2022
1 parent 3a036b7 commit 2d79bc9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ISC License

Copyright (c) [probot/dco contributors](https://github.com/probot/dco/graphs/contributors)
Copyright (c) [dcoapp/app contributors](https://github.com/dcoapp/app/graphs/contributors)

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Probot: DCO

[![Greenkeeper badge](https://badges.greenkeeper.io/probot/dco.svg)](https://greenkeeper.io/)
[![Greenkeeper badge](https://badges.greenkeeper.io/dcoapp/app.svg)](https://greenkeeper.io/)

a GitHub Integration built with [probot](https://github.com/probot/probot) that enforces the [Developer Certificate of Origin](https://developercertificate.org/) (DCO) on Pull Requests. It requires all commit messages to contain the `Signed-off-by` line with an email address that matches the commit author.

Expand Down
154 changes: 77 additions & 77 deletions index.js
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\`\`\``;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "a GitHub App that enforces the DCO on Pull Requests",
"author": "Brandon Keepers",
"license": "ISC",
"repository": "github:probot/dco",
"repository": "github:dcoapp/app",
"scripts": {
"start": "probot run ./index.js",
"test": "jest --coverage",
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object {
"context": "DCO",
"description": "The sign-off is missing.",
"state": "failure",
"target_url": "https://github.com/probot/dco#how-it-works",
"target_url": "https://github.com/dcoapp/app#how-it-works",
}
`;

Expand Down Expand Up @@ -78,6 +78,6 @@ Object {
"context": "DCO",
"description": "The sign-off is missing.",
"state": "failure",
"target_url": "https://github.com/probot/dco#how-it-works",
"target_url": "https://github.com/dcoapp/app#how-it-works",
}
`;

0 comments on commit 2d79bc9

Please sign in to comment.