From 0c20d182a201cf338d700038dc1e1c1b74ad1668 Mon Sep 17 00:00:00 2001 From: omkarkhatavkar Date: Thu, 15 Feb 2024 19:04:58 +0530 Subject: [PATCH] remove the PRT labels for new commits --- .github/workflows/prt_labels.yml | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/prt_labels.yml diff --git a/.github/workflows/prt_labels.yml b/.github/workflows/prt_labels.yml new file mode 100644 index 00000000000..3ef16ab4b0a --- /dev/null +++ b/.github/workflows/prt_labels.yml @@ -0,0 +1,45 @@ +name: Remove the PRT label, for the new commit + +on: + pull_request: + types: ["synchronize"] + +jobs: + prt_labels_remover: + name: remove the PRT label when amendments or new commits added to PR + runs-on: ubuntu-latest + if: "(contains(github.event.pull_request.labels.*.name, 'PRT-Passed') || contains(github.event.pull_request.labels.*.name, 'PRT-Failed'))" + steps: + - name: Fetch the PRT status + id: prt + uses: omkarkhatavkar/wait-for-status-checks@main + with: + ref: ${{ github.head_ref }} + context: 'Robottelo-Runner' + wait-interval: 2 + count: 5 + + - name: remove the PRT Passed/Failed label, for new commit + if: always() && ${{steps.prt.outputs.result}} == 'not_found' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.CHERRYPICK_PAT }} + script: | + const prNumber = '${{ github.event.number }}'; + const issue = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + const labelsToRemove = ['PRT-Failed', 'PRT-Passed']; + const labelsToRemoveFiltered = labelsToRemove.filter(label => issue.data.labels.some(({ name }) => name === label)); + if (labelsToRemoveFiltered.length > 0) { + await Promise.all(labelsToRemoveFiltered.map(async label => { + await github.rest.issues.removeLabel({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + name: label + }); + })); + }