actions: Comment information about DCO signing when failing

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-02-04 16:00:39 +01:00
parent 3bc7465f71
commit 0fdba0af76
+60
View File
@@ -0,0 +1,60 @@
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]")) {
console.log(`already commented on PR #${pull.number}, skipping`);
continue;
}
console.log(`creating comment on PR #${pull.number}`);
const body = `Thanks for the contribution!\nAll 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.`;
await github.rest.issues.createComment({
repo,
owner,
issue_number: pull.number,
body,
});
}