From f28fd3b8bbc7905cf4c0a2965e70e0841c438b55 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Thu, 25 Dec 2025 14:43:43 +0530 Subject: [PATCH 1/2] add one more label --- .github/workflows/sync-pr-labels.yml | 67 +++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index b270f80..86110be 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -189,7 +189,72 @@ jobs: console.log('No file-based labels matched'); } - # STEP 3: Contributor-based labels + # STEP 3: PR size labels + - name: Apply PR size label + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.payload.pull_request.number; + + // Get PR details to calculate size + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + + const additions = pr.data.additions; + const deletions = pr.data.deletions; + const totalChanges = additions + deletions; + + console.log(`PR has ${additions} additions and ${deletions} deletions (${totalChanges} total changes)`); + + // Determine size label based on total changes + let sizeLabel = ''; + if (totalChanges <= 10) { + sizeLabel = 'size/XS'; + } else if (totalChanges <= 50) { + sizeLabel = 'size/S'; + } else if (totalChanges <= 200) { + sizeLabel = 'size/M'; + } else if (totalChanges <= 500) { + sizeLabel = 'size/L'; + } else { + sizeLabel = 'size/XL'; + } + + console.log(`Applying size label: ${sizeLabel}`); + + // Remove any existing size labels first + const currentLabels = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber + }); + + const sizeLabelsToRemove = currentLabels.data + .map(label => label.name) + .filter(name => name.startsWith('size/')); + + for (const label of sizeLabelsToRemove) { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + name: label + }); + } + + // Apply the new size label + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + labels: [sizeLabel] + }); + + # STEP 4: Contributor-based labels - name: Apply contributor-based labels uses: actions/github-script@v7 env: From 14b9783649dacddc65ad012f0ab8af1fad8d3cab Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Thu, 25 Dec 2025 15:54:47 +0530 Subject: [PATCH 2/2] Security risk removed - Deleted the actions/checkout@v4 step. The workflow doesn't need to checkout any code since it only uses GitHub API calls for labeling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Permissions corrected - Changed issues: read → issues: write since labeling operations require write access to the issues API --- .github/workflows/sync-pr-labels.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index 86110be..8e137cf 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -9,18 +9,13 @@ on: permissions: contents: read pull-requests: write - issues: read + issues: write jobs: sync-labels: if: ${{ github.repository_owner == 'AOSSIE-Org' }} runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Get PR details id: pr-details uses: actions/github-script@v7