Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ path = [
"test/fixtures/pull_request.opened.json",
"test/fixtures/pull_request_review.submitted.json",
"test/fixtures/pull_request_review_comment.created.json",
"test/fixtures/merge_group.checks_requested.json",
"test/fixtures/push.not-signed-off.json",
"test/fixtures/push.signed-off.json",
]
Expand Down
1 change: 1 addition & 0 deletions app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ default_events:
- pull_request_review
- pull_request_review_comment
- push
- merge_group
Comment thread
tykeal marked this conversation as resolved.
# - release
# - repository
# - repository_import
Expand Down
58 changes: 49 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ module.exports = (app) => {
check
);

async function check(context, pr = context.payload.pull_request) {
async function check(
context,
pr = context.payload.pull_request,
{ reportSha, reportRef, baseSha, headSha } = {}
) {
const timeStart = new Date();
const sha = reportSha || pr.head.sha;
const ref = (reportRef || pr.head.ref).replace(/^refs\/heads\//, "");

const config = await context.config("dco.yml", {
require: {
Expand All @@ -34,8 +40,8 @@ module.exports = (app) => {

const compare = await context.octokit.rest.repos.compareCommits(
context.repo({
base: pr.base.sha,
head: pr.head.sha,
base: baseSha || pr.base.sha,
head: headSha || pr.head.sha,
})
);

Expand All @@ -52,8 +58,8 @@ module.exports = (app) => {
.create(
context.repo({
name: "DCO",
head_branch: pr.head.ref,
head_sha: pr.head.sha,
head_branch: ref,
head_sha: sha,
status: "completed",
started_at: timeStart,
conclusion: "success",
Expand All @@ -71,7 +77,7 @@ module.exports = (app) => {
context.log.info("resource not accessible, creating status instead");
// create status
const params = {
sha: pr.head.sha,
sha,
context: "DCO",
state: "success",
description: "All commits are signed off!",
Expand Down Expand Up @@ -100,8 +106,8 @@ module.exports = (app) => {
.create(
context.repo({
name: "DCO",
head_branch: pr.head.ref,
head_sha: pr.head.sha,
head_branch: ref,
head_sha: sha,
status: "completed",
started_at: timeStart,
conclusion: "action_required",
Expand Down Expand Up @@ -130,7 +136,7 @@ module.exports = (app) => {
140
);
const params = {
sha: pr.head.sha,
sha,
context: "DCO",
state: "failure",
description,
Expand All @@ -143,6 +149,40 @@ module.exports = (app) => {
}
}

app.on("merge_group.checks_requested", async (context) => {
Comment thread
vercel[bot] marked this conversation as resolved.
const mergeGroup = context.payload.merge_group;
const match = mergeGroup.head_ref.match(
Comment thread
vercel[bot] marked this conversation as resolved.
/(?:^|\/)gh-readonly-queue\/.+\/pr-(\d+)-/
);
if (!match) return;
const prNumber = parseInt(match[1], 10);

let pr;
try {
({ data: pr } = await context.octokit.rest.pulls.get(
context.repo({ pull_number: prNumber })
));
} catch (error) {
if (error.status === 404 || error.status === 403) {
context.log.info(
`merge_group: could not fetch PR #${prNumber}: ${error.message}`
);
return;
}
throw error;
}

await check(context, pr, {
// Report the check result on the merge group's temporary merge commit.
reportSha: mergeGroup.head_sha,
reportRef: mergeGroup.head_ref,
// Compare the full merge group range so all batched PRs are validated.
// headSha equals reportSha: both target the merge group head commit.
baseSha: mergeGroup.base_sha,
headSha: mergeGroup.head_sha,
});
});

function isRecheckCommand(body) {
if (!body) return false;
return body
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Object {
}
`;

exports[`dco merge_group event falls back to status API when check-runs returns 403 1`] = `
Object {
"context": "DCO",
"description": "The sign-off is missing.",
"state": "failure",
"target_url": "https://github.com/probot/dco#how-it-works",
}
`;

exports[`dco pull_request event allowRemediationCommits.thirdParty: true creates a failing check with remidiation instructions 1`] = `
Object {
"actions": Array [
Expand Down
62 changes: 62 additions & 0 deletions test/fixtures/merge_group.checks_requested.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"action": "checks_requested",
"merge_group": {
"head_sha": "abc123def456abc123def456abc123def456abc1",
"head_ref": "refs/heads/gh-readonly-queue/master/pr-113-e76ed6025cec8879c75454a6efd6081d46de4c94",
"base_sha": "607c64cd8e37eb2db939f99a17bee5c7d1a90a31",
"base_ref": "refs/heads/master",
"head_commit": {
"id": "abc123def456abc123def456abc123def456abc1",
"tree_id": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"message": "Merge pull request #113 into master",
"timestamp": "2017-09-22T23:21:03Z",
"author": {
"name": "GitHub",
"email": "noreply@github.com"
},
"committer": {
"name": "GitHub",
"email": "noreply@github.com"
}
}
},
"repository": {
"id": 68474533,
"name": "test",
"full_name": "robotland/test",
"owner": {
"login": "robotland",
"id": 11724939,
"avatar_url": "https://avatars2.githubusercontent.com/u/11724939?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/robotland",
"html_url": "https://github.com/robotland",
"type": "Organization",
"site_admin": false
},
"private": false,
"html_url": "https://github.com/robotland/test",
"description": "a trainable robot that responds to activity on GitHub",
"fork": false,
"url": "https://api.github.com/repos/robotland/test",
"default_branch": "master"
},
"organization": {
"login": "robotland",
"id": 11724939,
"url": "https://api.github.com/orgs/robotland"
},
"sender": {
"login": "bkeepers",
"id": 173,
"avatar_url": "https://avatars0.githubusercontent.com/u/173?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bkeepers",
"html_url": "https://github.com/bkeepers",
"type": "User",
"site_admin": true
},
"installation": {
"id": 13055
}
}
Loading