diff --git a/.github/workflows/automated-review.yml b/.github/workflows/automated-review.yml index bc9a10bfc274ef..0168627ffdf3e9 100644 --- a/.github/workflows/automated-review.yml +++ b/.github/workflows/automated-review.yml @@ -49,8 +49,12 @@ jobs: -H "Accept: application/vnd.github.v3+json" \ -X POST -d "$comment_body" \ "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" + new_comment_id=$(echo $new_comment_response | jq -r '.id') + echo "existing_comment_id=$new_comment_id" fi + echo "COMMENT_ID=$existing_comment_id" >> $GITHUB_ENV + - name: Get Changed Files from Pull Request env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -62,32 +66,40 @@ jobs: - name: Output Changed Files run: echo ${{ env.CHANGED_FILES }} - - name: Set up Python environment - uses: actions/setup-python@v3 - with: - python-version: 3.x + - name: Install case-police + run: npm install -g case-police if: ${{ !cancelled() && env.CHANGED_FILES != '' }} - - name: Create virtual environment - run: python -m venv venv + - name: Case Police + run: case-police ${{ env.CHANGED_FILES }} --disable DoS > case_police_output.txt || echo "Case Police failed" if: ${{ !cancelled() && env.CHANGED_FILES != '' }} + continue-on-error: true - - name: Activate virtual environment - run: source venv/bin/activate - if: ${{ !cancelled() && env.CHANGED_FILES != '' }} + - name: Case Police fails + if: failure() + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Read the saved comment ID + comment_id=${COMMENT_ID} - - name: Install codespell - run: pip install codespell - if: ${{ !cancelled() && env.CHANGED_FILES != '' }} + # Fetch the existing comment + existing_comment=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${{ github.repository }}/issues/comments/$comment_id") - - name: Install case-police - run: npm install -g case-police - if: ${{ !cancelled() && env.CHANGED_FILES != '' }} + # Extract the body of the existing comment + existing_comment_body=$(echo $existing_comment | jq -r '.body') - - name: Install alex - run: npm install -g alex - if: ${{ !cancelled() && env.CHANGED_FILES != '' }} + # Prepare the new comment body with case-police output + case_police_output=$(cat case_police_output.txt) + new_comment_body=$(echo "$existing_comment_body" | sed "s/.*/$case_police_output/") - - name: Case Police - run: case-police ${{ env.CHANGED_FILES }} --disable DoS - if: ${{ !cancelled() && env.CHANGED_FILES != '' }} \ No newline at end of file + # Format the new comment body as JSON + updated_comment_body=$(jq -n --arg body "$new_comment_body" '{body: $body}') + + # Update the comment + curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + -X PATCH -d "$updated_comment_body" \ + "https://api.github.com/repos/${{ github.repository }}/issues/comments/$comment_id"