From 7a8ed9cc52aa87c8a7f20e934198f8741747224b Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Thu, 3 Aug 2023 18:17:03 +0200 Subject: [PATCH 01/11] add an action to check labels --- .github/workflows/label-checker.yml | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/label-checker.yml diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml new file mode 100644 index 00000000000..9d508cac847 --- /dev/null +++ b/.github/workflows/label-checker.yml @@ -0,0 +1,33 @@ +--- +name: Label Checker +on: + pull_request: + types: + - opened + - synchronize + - reopened + - labeled + - unlabeled + +jobs: + + check_labels: + name: Check labels + runs-on: ubuntu-latest + steps: + - uses: docker://agilepathway/pull-request-label-checker:latest + with: + none_of: deprecated,enhancement,pr: clean,pr: breaking, pr: new feature, pr: fix, refactoring, pr: test + + name: Post Comment + uses: actions/github-script@v4 + with: + script: | + // Use the GitHub API to post the comment + // $COMMENT_TEXT contains the comment content + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: ':warning: @'+context.repo.owner+': your PR does not include any descriptive label :warning:' + }); \ No newline at end of file From 86b037a9d7458f178fd728fbb6944782588e1add Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Sun, 6 Aug 2023 16:58:05 +0200 Subject: [PATCH 02/11] fix check and add comment to action --- .github/workflows/label-checker.yml | 37 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index 9d508cac847..3f86a006e13 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -9,25 +9,34 @@ on: - labeled - unlabeled + jobs: check_labels: name: Check labels runs-on: ubuntu-latest steps: - - uses: docker://agilepathway/pull-request-label-checker:latest + - name: Check Labels and Add Comment + id: check_labels_and_comment + uses: actions/github-script@v4 with: - none_of: deprecated,enhancement,pr: clean,pr: breaking, pr: new feature, pr: fix, refactoring, pr: test + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Get PR info: id and labels + const prNumber = context.payload.pull_request.number; + const labels = context.payload.pull_request.labels.map(label => label.name); + + // If no descriptive label is set, add a comment in the PR and make the action check fail + if (!labels.includes('enhancement') && !labels.includes('deprecated') && !labels.includes('refactoring') && !labels.includes('pr: breaking') && !labels.includes('pr: clean') && !labels.includes('pr: fix') && !labels.includes('pr: new feature') && !labels.includes('pr: test')) { + const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any descriptive label :label:
Make sure to add an appropriate [PR label](https://github.com/sofa-framework/sofa/labels) before merge.
:warning: :warning: :warning:'; + github.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }); + core.setFailed('Invalid PR label') + } - name: Post Comment - uses: actions/github-script@v4 - with: - script: | - // Use the GitHub API to post the comment - // $COMMENT_TEXT contains the comment content - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: ':warning: @'+context.repo.owner+': your PR does not include any descriptive label :warning:' - }); \ No newline at end of file + // Add all PR labels in log + console.log('Labels:', labels.join(', ')); \ No newline at end of file From 0fb5ddc2d2d662a7ad673ea38ef8e6b9a7d44df0 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 7 Aug 2023 20:25:42 +0200 Subject: [PATCH 03/11] Update label-checker.yml --- .github/workflows/label-checker.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index 3f86a006e13..c0a28f5227a 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -26,8 +26,11 @@ jobs: const prNumber = context.payload.pull_request.number; const labels = context.payload.pull_request.labels.map(label => label.name); + // Array of labels to check for + const validLabels = ['enhancement', 'deprecated', 'refactoring', 'pr: breaking', 'pr: clean', 'pr: fix', 'pr: new feature', 'pr: test']; + // If no descriptive label is set, add a comment in the PR and make the action check fail - if (!labels.includes('enhancement') && !labels.includes('deprecated') && !labels.includes('refactoring') && !labels.includes('pr: breaking') && !labels.includes('pr: clean') && !labels.includes('pr: fix') && !labels.includes('pr: new feature') && !labels.includes('pr: test')) { + if (!validLabels.every(label => labels.includes(label))) { const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any descriptive label :label:
Make sure to add an appropriate [PR label](https://github.com/sofa-framework/sofa/labels) before merge.
:warning: :warning: :warning:'; github.issues.createComment({ issue_number: prNumber, @@ -39,4 +42,4 @@ jobs: } // Add all PR labels in log - console.log('Labels:', labels.join(', ')); \ No newline at end of file + console.log('Labels:', labels.join(', ')); From 76b6e5e0a194a74043aea6a61d74d772cfa992e1 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Mon, 21 Aug 2023 16:08:26 +0200 Subject: [PATCH 04/11] add a check for pr status --- .github/workflows/label-checker.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index c0a28f5227a..52990c939b9 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -26,7 +26,7 @@ jobs: const prNumber = context.payload.pull_request.number; const labels = context.payload.pull_request.labels.map(label => label.name); - // Array of labels to check for + // Array of possible labels providing a description const validLabels = ['enhancement', 'deprecated', 'refactoring', 'pr: breaking', 'pr: clean', 'pr: fix', 'pr: new feature', 'pr: test']; // If no descriptive label is set, add a comment in the PR and make the action check fail @@ -38,7 +38,22 @@ jobs: repo: context.repo.repo, body: comment }); - core.setFailed('Invalid PR label') + core.setFailed('Invalid descriptive PR label') + } + + // Array of possible labels defining the status of the PR + const statusLabels = ['pr: status wip', 'pr: status to review', 'pr: status ready']; + + // If no descriptive label is set, add a comment in the PR and make the action check fail + if (!statusLabels.every(label => labels.includes(label))) { + const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any status label :label:
Make sure to add one (wip, to review or ready).
:warning: :warning: :warning:'; + github.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }); + core.setFailed('Invalid status PR label') } // Add all PR labels in log From 0716a1cf5ab0cbbe54048a8ab019b499c8abec75 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Thu, 31 Aug 2023 20:33:27 +0200 Subject: [PATCH 05/11] Test new format --- .github/workflows/label-checker.yml | 33 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index 52990c939b9..dfb39d6c702 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -26,26 +26,45 @@ jobs: const prNumber = context.payload.pull_request.number; const labels = context.payload.pull_request.labels.map(label => label.name); - // Array of possible labels providing a description - const validLabels = ['enhancement', 'deprecated', 'refactoring', 'pr: breaking', 'pr: clean', 'pr: fix', 'pr: new feature', 'pr: test']; + // Define an array of descriptive labels + const descriptiveLabels = [ + 'enhancement', + 'deprecated', + 'refactoring', + 'pr: breaking', + 'pr: clean', + 'pr: fix', + 'pr: new feature', + 'pr: test' + ]; + + // Check if any descriptive label is included in the 'labels' array + const hasDescriptiveLabel = labels.some(label => descriptiveLabels.includes(label)); // If no descriptive label is set, add a comment in the PR and make the action check fail - if (!validLabels.every(label => labels.includes(label))) { - const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any descriptive label :label:
Make sure to add an appropriate [PR label](https://github.com/sofa-framework/sofa/labels) before merge.
:warning: :warning: :warning:'; + if (!hasDescriptiveLabel) { + const comment = ':warning: :warning: :warning:
@' + context.repo.owner + ' your PR does not include any descriptive label :label:
Make sure to add an appropriate [PR label](https://github.com/sofa-framework/sofa/labels) before merge.
:warning: :warning: :warning:'; github.issues.createComment({ issue_number: prNumber, owner: context.repo.owner, repo: context.repo.repo, body: comment }); - core.setFailed('Invalid descriptive PR label') + core.setFailed('Invalid PR label'); } // Array of possible labels defining the status of the PR - const statusLabels = ['pr: status wip', 'pr: status to review', 'pr: status ready']; + const statusLabels = [ + 'pr: status wip', + 'pr: status to review', + 'pr: status ready' + ]; + + // Check if any status label is included in the 'labels' array + const hasStatusLabel = labels.some(label => statusLabels.includes(label)); // If no descriptive label is set, add a comment in the PR and make the action check fail - if (!statusLabels.every(label => labels.includes(label))) { + if (!hasStatusLabel) { const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any status label :label:
Make sure to add one (wip, to review or ready).
:warning: :warning: :warning:'; github.issues.createComment({ issue_number: prNumber, From 88141843ef6b65ab9469df5aae7a3815d3870b7e Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Thu, 31 Aug 2023 20:43:34 +0200 Subject: [PATCH 06/11] Test new format and add a warning when multiple pr status are set --- .github/workflows/label-checker.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index dfb39d6c702..682bd86f5b1 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -60,11 +60,14 @@ jobs: 'pr: status ready' ]; - // Check if any status label is included in the 'labels' array - const hasStatusLabel = labels.some(label => statusLabels.includes(label)); + // Filter the labels array to get only the status labels + const matchingStatusLabels = labels.filter(label => statusLabels.includes(label)); + + // Count the number of entries in 'matchingLabels' + const matchingLabelsCount = matchingStatusLabels.length; // If no descriptive label is set, add a comment in the PR and make the action check fail - if (!hasStatusLabel) { + if (matchingLabelsCount === 0) { const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any status label :label:
Make sure to add one (wip, to review or ready).
:warning: :warning: :warning:'; github.issues.createComment({ issue_number: prNumber, @@ -73,7 +76,14 @@ jobs: body: comment }); core.setFailed('Invalid status PR label') - } + } else if (matchingLabelsCount > 1) { + const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does includes too many status labels :label:
Make sure to keep only one (wip, to review or ready).
:warning: :warning: :warning:'; + github.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }); // Add all PR labels in log console.log('Labels:', labels.join(', ')); From 91a56b3788cf1e7d2b683b9378bd4d83c67142f6 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Thu, 31 Aug 2023 20:46:49 +0200 Subject: [PATCH 07/11] Test new format and add a warning when multiple pr status are set --- .github/workflows/label-checker.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index 682bd86f5b1..03e81bfc373 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -83,7 +83,9 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, body: comment - }); + }); + core.setFailed('Invalid status PR label') + } // Add all PR labels in log console.log('Labels:', labels.join(', ')); From 8f862e12e6b7b5b77ae27c870c9c2712ab302cd7 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Thu, 31 Aug 2023 20:50:22 +0200 Subject: [PATCH 08/11] Improve style --- .github/workflows/label-checker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index 03e81bfc373..60b2d5b3f64 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -43,7 +43,7 @@ jobs: // If no descriptive label is set, add a comment in the PR and make the action check fail if (!hasDescriptiveLabel) { - const comment = ':warning: :warning: :warning:
@' + context.repo.owner + ' your PR does not include any descriptive label :label:
Make sure to add an appropriate [PR label](https://github.com/sofa-framework/sofa/labels) before merge.
:warning: :warning: :warning:'; + const comment = ':warning: :warning: :warning:
@' + context.repo.owner + ' your PR does not include any **descriptive** label :label:
Make sure to add an appropriate [PR label](https://github.com/sofa-framework/sofa/labels) before merge.
:warning: :warning: :warning:'; github.issues.createComment({ issue_number: prNumber, owner: context.repo.owner, @@ -68,7 +68,7 @@ jobs: // If no descriptive label is set, add a comment in the PR and make the action check fail if (matchingLabelsCount === 0) { - const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any status label :label:
Make sure to add one (wip, to review or ready).
:warning: :warning: :warning:'; + const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does not include any **status** label :label:
Make sure to add one (wip, to review or ready).
:warning: :warning: :warning:'; github.issues.createComment({ issue_number: prNumber, owner: context.repo.owner, @@ -77,7 +77,7 @@ jobs: }); core.setFailed('Invalid status PR label') } else if (matchingLabelsCount > 1) { - const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does includes too many status labels :label:
Make sure to keep only one (wip, to review or ready).
:warning: :warning: :warning:'; + const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does includes **too many status labels** :label:
Make sure to keep only one (wip, to review or ready).
:warning: :warning: :warning:'; github.issues.createComment({ issue_number: prNumber, owner: context.repo.owner, From a2a5a474a67c1b589ee344e9f20542175650f3d3 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Thu, 31 Aug 2023 21:01:56 +0200 Subject: [PATCH 09/11] Correct failure message --- .github/workflows/label-checker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index 60b2d5b3f64..f7b7c4384f1 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -75,7 +75,7 @@ jobs: repo: context.repo.repo, body: comment }); - core.setFailed('Invalid status PR label') + core.setFailed('Missing status PR label') } else if (matchingLabelsCount > 1) { const comment = ':warning: :warning: :warning:
@'+context.repo.owner+' your PR does includes **too many status labels** :label:
Make sure to keep only one (wip, to review or ready).
:warning: :warning: :warning:'; github.issues.createComment({ @@ -84,7 +84,7 @@ jobs: repo: context.repo.repo, body: comment }); - core.setFailed('Invalid status PR label') + core.setFailed('Too many status PR labels') } // Add all PR labels in log From 693445472e8076e85f16dda55a99e62c13b840a3 Mon Sep 17 00:00:00 2001 From: Hugo Talbot Date: Thu, 31 Aug 2023 23:04:16 +0200 Subject: [PATCH 10/11] Enforce a delay --- .github/workflows/label-checker.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index f7b7c4384f1..5c44370b508 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -16,6 +16,10 @@ jobs: name: Check labels runs-on: ubuntu-latest steps: + - name: Delay for 3 Seconds + run: | + echo "Waiting for 3 seconds in case other labels get changed" + sleep 3 - name: Check Labels and Add Comment id: check_labels_and_comment uses: actions/github-script@v4 From fcb4f7dd3d108ce44523d4855589db9cf3020749 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 1 Sep 2023 17:20:22 +0200 Subject: [PATCH 11/11] Increase the delayed start of the action Co-authored-by: erik pernod --- .github/workflows/label-checker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml index 5c44370b508..7e8a4ca6708 100644 --- a/.github/workflows/label-checker.yml +++ b/.github/workflows/label-checker.yml @@ -16,10 +16,10 @@ jobs: name: Check labels runs-on: ubuntu-latest steps: - - name: Delay for 3 Seconds + - name: Delay for 10 Seconds run: | - echo "Waiting for 3 seconds in case other labels get changed" - sleep 3 + echo "Waiting for 10 seconds in case other labels get changed" + sleep 10 - name: Check Labels and Add Comment id: check_labels_and_comment uses: actions/github-script@v4