From 0fdba0af76d5c11cd2d7a2131d7b150a4c231a7c Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Fri, 4 Feb 2022 16:00:39 +0100 Subject: [PATCH] actions: Comment information about DCO signing when failing Signed-off-by: Johan Haals --- .github/workflows/verify_dco.yaml | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/verify_dco.yaml diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml new file mode 100644 index 0000000000..8d071afd4c --- /dev/null +++ b/.github/workflows/verify_dco.yaml @@ -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, + }); + }