From 978e11bd396fe252429b2bd2a33d1dc38d6f1d6e Mon Sep 17 00:00:00 2001 From: Mridul Seth Date: Thu, 21 May 2026 17:30:40 +0200 Subject: [PATCH] [CI] fix label bot reporting already-present labels as newly added --- .github/workflows/pr-vibe-check.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-vibe-check.yml b/.github/workflows/pr-vibe-check.yml index f344f802f..cc0e61205 100644 --- a/.github/workflows/pr-vibe-check.yml +++ b/.github/workflows/pr-vibe-check.yml @@ -28,6 +28,10 @@ jobs: check-pr: name: Check Labels runs-on: ubuntu-slim + permissions: + # Read access for `actions/checkout` and `gh pr view`. + contents: read + pull-requests: read outputs: all_labels: ${{ steps.all-labels.outputs.all_labels }} new_labels: ${{ steps.new-labels.outputs.new_labels }} @@ -56,12 +60,18 @@ jobs: id: new-labels env: all_labels: ${{ steps.all-labels.outputs.all_labels }} + GH_TOKEN: ${{ github.token }} run: | - EXISTING_LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'; + # Query the labels currently on the PR rather than reading them from + # the event payload. The payload is a snapshot taken when the event + # was created, so labels the author adds right after opening the PR + # (a common case) would be missing from it and wrongly reported as + # newly added by the bot. See issue #584. + EXISTING_LABELS="$(gh pr view ${PR_NUM} --json labels --jq '.labels[].name')"; new_labels=(); for label in ${all_labels[@]}; do - if [[ "$EXISTING_LABELS" == *"${label}"* ]]; then - echo "${label} is already added to the current PR."; + if grep -qxF "${label}" <<< "$EXISTING_LABELS"; then + echo "${label} is already added to the current PR."; else echo "Found a new label to be added: ${label}"; new_labels+=("${label}");