From 0fdba0af76d5c11cd2d7a2131d7b150a4c231a7c Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Fri, 4 Feb 2022 16:00:39 +0100 Subject: [PATCH 1/6] 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, + }); + } From 88f5a56b6016f717c1fb7dd11546e21156b21167 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Mon, 7 Feb 2022 10:34:24 +0100 Subject: [PATCH 2/6] Update .github/workflows/verify_dco.yaml Signed-off-by: Johan Haals Co-authored-by: Adam Harvey --- .github/workflows/verify_dco.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml index 8d071afd4c..27ed7317a0 100644 --- a/.github/workflows/verify_dco.yaml +++ b/.github/workflows/verify_dco.yaml @@ -50,7 +50,7 @@ jobs: } 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.`; + 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, From 1239b113b97dafdf90b33b5ad9d029c814690847 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Mon, 7 Feb 2022 10:35:45 +0100 Subject: [PATCH 3/6] format Signed-off-by: Johan Haals --- .github/workflows/verify_dco.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml index 27ed7317a0..28c22b0b66 100644 --- a/.github/workflows/verify_dco.yaml +++ b/.github/workflows/verify_dco.yaml @@ -1,7 +1,7 @@ name: Verify DCO on: schedule: - - cron: '*/15 * * * *' + - cron: '*/15 * * * *' jobs: dco-helper: From f1a5d816965d3c9886d3b37f2e181aed8f838613 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 8 Feb 2022 10:33:38 +0100 Subject: [PATCH 4/6] include dco-helper tag in comment Signed-off-by: Johan Haals --- .github/workflows/verify_dco.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml index 28c22b0b66..341ff55fbd 100644 --- a/.github/workflows/verify_dco.yaml +++ b/.github/workflows/verify_dco.yaml @@ -43,14 +43,17 @@ jobs: repo, issue_number: pull.number, }); - - if (comments.find((c) => c.user.login === "github-actions[bot]")) { + 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!\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.`; + 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, From b740b0c7d8e5faa8d84e11a086ea5c6310c61dad Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 8 Feb 2022 10:43:36 +0100 Subject: [PATCH 5/6] switch to markdown comment tag Signed-off-by: Johan Haals --- .github/workflows/verify_dco.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml index 341ff55fbd..42954e3b9a 100644 --- a/.github/workflows/verify_dco.yaml +++ b/.github/workflows/verify_dco.yaml @@ -45,15 +45,14 @@ jobs: }); if (comments.find((c) => c.user.login === "github-actions[bot]" && - c.body.includes("") + 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!\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.`; + 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, From 0da410b9055a309aad72e66ba7d474a5950cdc3d Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 8 Feb 2022 14:18:30 +0100 Subject: [PATCH 6/6] Multiline message body Signed-off-by: Johan Haals Co-authored-by: Ben Lambert --- .github/workflows/verify_dco.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml index 42954e3b9a..e2da767394 100644 --- a/.github/workflows/verify_dco.yaml +++ b/.github/workflows/verify_dco.yaml @@ -52,7 +52,10 @@ jobs: 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.`; + 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,