From 5e1558ecfab7dd4a72167d89968f027e158c5ed2 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Sat, 7 Jan 2023 20:18:45 +0100 Subject: [PATCH] Update labeling --- .github/workflows/project-labelling.yml | 55 ++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/.github/workflows/project-labelling.yml b/.github/workflows/project-labelling.yml index bdd14f26..0e0dba37 100644 --- a/.github/workflows/project-labelling.yml +++ b/.github/workflows/project-labelling.yml @@ -5,8 +5,11 @@ on: types: [created, moved, deleted] jobs: - automate-issues-labels: + process-labels: + name: Add/remove the project label and set the matrix variable runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.setVariables.outputs.matrix }} steps: - name: Fetch project data run: | @@ -14,6 +17,7 @@ jobs: curl --request GET --url '${{ github.event.project_card.project_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' >> $GITHUB_ENV echo 'EOF' >> $GITHUB_ENV + ### Add or remove the project label ### - name: Add the project label uses: andymckay/labeler@master if: ${{ contains(github.event.action, 'created') || contains(github.event.action, 'moved') }} @@ -24,4 +28,51 @@ jobs: uses: andymckay/labeler@master if: ${{ contains(github.event.action, 'deleted') }} with: - remove-labels: "Project: ${{ fromJSON(env.PROJECT_DATA).name }}" \ No newline at end of file + remove-labels: "Project: ${{ fromJSON(env.PROJECT_DATA).name }}" + + ### Fetch project columns ### + - name: Fetch all columns + run: | + echo 'ALL_COLUMNS_DATA<> $GITHUB_ENV + curl --request GET --url '${{ fromJSON(env.PROJECT_DATA).columns_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' | jq --compact-output '["Status: " + .[].name]' >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Set the matrix variable + id: setVariables + run: | + echo "matrix=${{ toJSON(env.ALL_COLUMNS_DATA) }}" >> $GITHUB_OUTPUT + + remove-labels: + name: Remove the status label + runs-on: ubuntu-latest + needs: process-labels + strategy: + matrix: + label: ${{fromJson(needs.process-labels.outputs.matrix)}} + + steps: + # One by one, as there was an issue with removing multiple labels at once + - name: Remove the status label + uses: andymckay/labeler@master + if: ${{ contains(github.event.action, 'deleted') || contains(github.event.action, 'moved') }} + with: + remove-labels: ${{ matrix.label }} + + add-labels: + name: Add the status label + runs-on: ubuntu-latest + needs: remove-labels + steps: + # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#project_card + - name: Fetch column info + run: | + echo 'COLUMN_DATA<> $GITHUB_ENV + curl --request GET --url '${{ github.event.project_card.column_url }}' --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Add the status label + uses: andymckay/labeler@master + if: ${{ contains(github.event.action, 'created') || contains(github.event.action, 'moved') }} + with: + add-labels: "Status: ${{ fromJSON(env.COLUMN_DATA).name }}" + \ No newline at end of file