diff --git a/.github/workflows/push_event.yml b/.github/workflows/push_event.yml new file mode 100644 index 00000000000..cfa9931bee1 --- /dev/null +++ b/.github/workflows/push_event.yml @@ -0,0 +1,37 @@ +# running specific actions related to push events +name: Remove PRT labels for new commit +on: + push: + +jobs: + remove-prt-labels: + name: Remove PRT labels for new commit + runs-on: ubuntu-latest + steps: + - name: Remove the previous PRT Result labels + if: contains(github.event.pull_request.labels.*.name, 'PRT') + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.CHERRYPICK_PAT }} + script: | + if ('${{github.event_name}}' === 'push') { + // Your code to handle the event due to new commit + const prNumber = ${{ github.event.number }}; + const issue = await github.rest.issues.get({ + owner: context.issue.owner, + repo: context.issue.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 + }); + })); + } + }