diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml new file mode 100644 index 0000000000..e2da767394 --- /dev/null +++ b/.github/workflows/verify_dco.yaml @@ -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("") + ) + ) { + 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. + `; + await github.rest.issues.createComment({ + repo, + owner, + issue_number: pull.number, + body, + }); + }