Merge pull request #9367 from backstage/jhaals/actions

actions: Comment information about DCO signing when failing
This commit is contained in:
Ben Lambert
2022-02-08 15:38:33 +01:00
committed by GitHub
+65
View File
@@ -0,0 +1,65 @@
name: Verify DCO
on:
schedule:
- cron: '*/15 * * * *'
jobs:
dco-helper:
runs-on: ubuntu-latest
steps:
- name: Verify DCO status for open pull requests
uses: actions/github-script@v5
with:
script: |
const owner = "backstage";
const repo = "backstage";
const pulls = await github.paginate(github.rest.pulls.list, {
state: "open",
owner,
repo,
});
for (const pull of pulls) {
// Pick out the PRs that have the DCO check
const checks = await github.rest.checks.listForRef({
owner,
repo,
ref: pull.head.sha,
check_name: "DCO",
status: "completed",
});
// Skip if there are no checks
if (!checks.data.check_runs.length) {
continue;
}
// Skip if the conclusion is not action_required
if (checks.data.check_runs[0].conclusion !== "action_required") {
console.log(`No checks found for PR #${pull.number}, skipping`);
continue;
}
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number: pull.number,
});
if (comments.find((c) =>
c.user.login === "github-actions[bot]" &&
c.body.includes("<!-- dco -->")
)
) {
console.log(`already commented on PR #${pull.number}, skipping`);
continue;
}
console.log(`creating comment on PR #${pull.number}`);
const body = `
Thanks for the contribution!
All commits need to be DCO signed before merging. Please refer to the the [DCO section in CONTRIBUTING.md](https://github.com/backstage/backstage/blob/master/CONTRIBUTING.md#developer-certificate-of-origin) or the [DCO](${checks.data.check_runs[0].html_url}) status for more info.
<!-- dco -->`;
await github.rest.issues.createComment({
repo,
owner,
issue_number: pull.number,
body,
});
}