From a1d99ad5bc42ae210fb08c952815bc1adddf4d01 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Tue, 27 Jan 2026 02:30:45 +0530 Subject: [PATCH 01/12] try using another api for checking --- .github/workflows/sync-pr-labels.yml | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index 8e137cf..59897a1 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -270,23 +270,14 @@ jobs: const contributorLabels = []; - // Check if contributor is a member of the organization - try { - await github.rest.orgs.checkMembershipForUser({ - org: context.repo.owner, - username: prAuthor - }); - contributorLabels.push('member'); - } catch (error) { - // Not a member - if (commits.data.length <= 1) { - contributorLabels.push('first-time-contributor'); - } else { - contributorLabels.push('external-contributor'); - } + // Determine contributor type based on commit count + if (commits.data.length <= 1) { + contributorLabels.push('first-time-contributor'); + } else { + contributorLabels.push('external-contributor'); } - // Check if PR author is a collaborator + // Maintainer check try { const permissionLevel = await github.rest.repos.getCollaboratorPermissionLevel({ owner: context.repo.owner, @@ -294,7 +285,7 @@ jobs: username: prAuthor }); - if (permissionLevel.data.permission === 'admin' || permissionLevel.data.permission === 'maintain') { + if (['admin', 'maintain'].includes(permissionLevel.data.permission)) { contributorLabels.push('maintainer'); } } catch (error) { From 64198962a0fedc376706934c80cb306edaa496b5 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Tue, 27 Jan 2026 21:55:46 +0530 Subject: [PATCH 02/12] change logic for pr label on step 4 --- .github/workflows/sync-pr-labels.yml | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index 59897a1..6ea2e55 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -1,8 +1,6 @@ name: Sync PR Labels on: - pull_request: - types: [opened, reopened, synchronize, edited] pull_request_target: types: [opened, reopened, synchronize, edited] @@ -249,7 +247,7 @@ jobs: labels: [sizeLabel] }); - # STEP 4: Contributor-based labels + # STEP 4: Contributor-based labels(in this later we can add logic of team p as discussed on discord) - name: Apply contributor-based labels uses: actions/github-script@v7 env: @@ -270,14 +268,8 @@ jobs: const contributorLabels = []; - // Determine contributor type based on commit count - if (commits.data.length <= 1) { - contributorLabels.push('first-time-contributor'); - } else { - contributorLabels.push('external-contributor'); - } - - // Maintainer check + // First check if maintainer + let isMaintainer = false; try { const permissionLevel = await github.rest.repos.getCollaboratorPermissionLevel({ owner: context.repo.owner, @@ -287,11 +279,21 @@ jobs: if (['admin', 'maintain'].includes(permissionLevel.data.permission)) { contributorLabels.push('maintainer'); + isMaintainer = true; } } catch (error) { console.log('Could not check collaborator status'); } + // If not maintainer, check contributor type + if (!isMaintainer) { + if (commits.data.length <= 1) { + contributorLabels.push('first-time-contributor'); + } else { + contributorLabels.push('external-contributor'); + } + } + if (contributorLabels.length > 0) { console.log(`Applying contributor-based labels: ${contributorLabels.join(', ')}`); From 2c8ad5eed545a52996cd01d9a835407143113eea Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Tue, 27 Jan 2026 21:56:10 +0530 Subject: [PATCH 03/12] change to mainatainer --- .github/workflows/sync-pr-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index 6ea2e55..f09d309 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -278,7 +278,7 @@ jobs: }); if (['admin', 'maintain'].includes(permissionLevel.data.permission)) { - contributorLabels.push('maintainer'); + contributorLabels.push('Org-Member'); isMaintainer = true; } } catch (error) { From 61400ec724fd28efd3033c61ed6a831a7323266f Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 28 Jan 2026 00:38:19 +0530 Subject: [PATCH 04/12] update contributor label logic to use 'repeat-contributor' for multiple contributions --- .github/workflows/setup-labels.yml | 203 +++++++++++++++++++++++++++ .github/workflows/sync-pr-labels.yml | 2 +- 2 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/setup-labels.yml diff --git a/.github/workflows/setup-labels.yml b/.github/workflows/setup-labels.yml new file mode 100644 index 0000000..4f9940f --- /dev/null +++ b/.github/workflows/setup-labels.yml @@ -0,0 +1,203 @@ +name: Setup Repository Labels + +on: + workflow_dispatch: # Manual trigger + push: + branches: [main, master] + paths: + - '.github/workflows/setup-labels.yml' + +permissions: + issues: write + +jobs: + create-labels: + runs-on: ubuntu-latest + steps: + - name: Create all required labels + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Define all labels with colors and descriptions + const requiredLabels = [ + // ==================== CONTRIBUTOR LABELS ==================== + { + name: 'Org-Member', + color: '0E8A16', + description: 'Member of the organization with admin/maintain permissions' + }, + { + name: 'first-time-contributor', + color: '7057FF', + description: 'First contribution to this repository' + }, + { + name: 'repeat-contributor', + color: '6F42C1', + description: 'External contributor with multiple contributions' + }, + + // ==================== ISSUE TRACKING LABELS ==================== + { + name: 'no-issue-linked', + color: 'D73A4A', + description: 'PR is not linked to any issue' + }, + + // ==================== FILE TYPE LABELS ==================== + { + name: 'documentation', + color: '0075CA', + description: 'Changes to documentation files' + }, + { + name: 'frontend', + color: 'FEF2C0', + description: 'Changes to frontend code' + }, + { + name: 'backend', + color: 'BFD4F2', + description: 'Changes to backend code' + }, + { + name: 'javascript', + color: 'F1E05A', + description: 'JavaScript/TypeScript code changes' + }, + { + name: 'python', + color: '3572A5', + description: 'Python code changes' + }, + { + name: 'configuration', + color: 'EDEDED', + description: 'Configuration file changes' + }, + { + name: 'github-actions', + color: '2088FF', + description: 'GitHub Actions workflow changes' + }, + { + name: 'dependencies', + color: '0366D6', + description: 'Dependency file changes' + }, + { + name: 'tests', + color: 'C5DEF5', + description: 'Test file changes' + }, + { + name: 'docker', + color: '0DB7ED', + description: 'Docker-related changes' + }, + { + name: 'ci-cd', + color: '6E5494', + description: 'CI/CD pipeline changes' + }, + + // ==================== SIZE LABELS ==================== + { + name: 'size/XS', + color: '00FF00', + description: 'Extra small PR (≤10 lines changed)' + }, + { + name: 'size/S', + color: '77FF00', + description: 'Small PR (11-50 lines changed)' + }, + { + name: 'size/M', + color: 'FFFF00', + description: 'Medium PR (51-200 lines changed)' + }, + { + name: 'size/L', + color: 'FF9900', + description: 'Large PR (201-500 lines changed)' + }, + { + name: 'size/XL', + color: 'FF0000', + description: 'Extra large PR (>500 lines changed)' + } + ]; + + console.log('='.repeat(60)); + console.log('šŸ·ļø REPOSITORY LABEL SETUP'); + console.log('='.repeat(60)); + console.log(`Total labels to create: ${requiredLabels.length}\n`); + + // Get existing labels + const { data: existingLabels } = await github.rest.issues.listLabelsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo + }); + + const existingLabelNames = existingLabels.map(label => label.name); + + let created = 0; + let updated = 0; + let skipped = 0; + let failed = 0; + + // Process each label + for (const label of requiredLabels) { + try { + if (!existingLabelNames.includes(label.name)) { + // Create new label + await github.rest.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: label.name, + color: label.color, + description: label.description + }); + console.log(`āœ… Created: ${label.name} (#${label.color})`); + created++; + } else { + // Update existing label (in case color/description changed) + const existingLabel = existingLabels.find(l => l.name === label.name); + if (existingLabel.color !== label.color || existingLabel.description !== label.description) { + await github.rest.issues.updateLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: label.name, + color: label.color, + description: label.description + }); + console.log(`šŸ”„ Updated: ${label.name} (#${label.color})`); + updated++; + } else { + console.log(`ā­ļø Skipped: ${label.name} (already exists)`); + skipped++; + } + } + } catch (error) { + console.log(`āŒ Failed: ${label.name} - ${error.message}`); + failed++; + } + } + + // Summary + console.log('\n' + '='.repeat(60)); + console.log('šŸ“Š SUMMARY'); + console.log('='.repeat(60)); + console.log(`āœ… Created: ${created}`); + console.log(`šŸ”„ Updated: ${updated}`); + console.log(`ā­ļø Skipped: ${skipped}`); + console.log(`āŒ Failed: ${failed}`); + console.log('='.repeat(60)); + + if (created > 0 || updated > 0) { + console.log('\nšŸŽ‰ Label setup complete! Your repository is ready.'); + } else { + console.log('\n✨ All labels are already up to date.'); + } diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index f09d309..f5b5298 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -290,7 +290,7 @@ jobs: if (commits.data.length <= 1) { contributorLabels.push('first-time-contributor'); } else { - contributorLabels.push('external-contributor'); + contributorLabels.push('repeat-contributor'); } } From a0ab0a931833f54b66710ab17d411b97613db46b Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 28 Jan 2026 01:48:04 +0530 Subject: [PATCH 05/12] refactor label setup logic to use pagination for existing labels and improve failure handling --- .github/workflows/setup-labels.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/setup-labels.yml b/.github/workflows/setup-labels.yml index 4f9940f..bbed15e 100644 --- a/.github/workflows/setup-labels.yml +++ b/.github/workflows/setup-labels.yml @@ -135,11 +135,15 @@ jobs: console.log('='.repeat(60)); console.log(`Total labels to create: ${requiredLabels.length}\n`); - // Get existing labels - const { data: existingLabels } = await github.rest.issues.listLabelsForRepo({ - owner: context.repo.owner, - repo: context.repo.repo - }); + // Get existing labels with pagination + const existingLabels = await github.paginate( + github.rest.issues.listLabelsForRepo, + { + owner: context.repo.owner, + repo: context.repo.repo, + per_page: 100 + } + ); const existingLabelNames = existingLabels.map(label => label.name); @@ -196,7 +200,10 @@ jobs: console.log(`āŒ Failed: ${failed}`); console.log('='.repeat(60)); - if (created > 0 || updated > 0) { + // Fail the step if any labels failed to create/update + if (failed > 0) { + core.setFailed(`Label setup failed! ${failed} label(s) could not be created or updated.`); + } else if (created > 0 || updated > 0) { console.log('\nšŸŽ‰ Label setup complete! Your repository is ready.'); } else { console.log('\n✨ All labels are already up to date.'); From 495069a3d8c9aa14deb2abe213d0d127d48e2563 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 28 Jan 2026 01:50:56 +0530 Subject: [PATCH 06/12] Update release-drafter.yml --- .github/release-drafter.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 5df0eb4..32a9c30 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -54,7 +54,8 @@ categories: - title: 'šŸ‘„ Contributors' labels: - 'first-time-contributor' - - 'external-contributor' + - 'repeat-contributor' + - 'Org-Member' change-template: '- $TITLE @$AUTHOR (#$NUMBER)' change-title-escapes: '\<*_&' From 44f80adeba4d9d5ee7884cbb76f23d4dff683813 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 28 Jan 2026 16:38:34 +0530 Subject: [PATCH 07/12] minor cosmetic change --- .github/workflows/setup-labels.yml | 6 +++--- .github/workflows/sync-pr-labels.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/setup-labels.yml b/.github/workflows/setup-labels.yml index bbed15e..e7c1e56 100644 --- a/.github/workflows/setup-labels.yml +++ b/.github/workflows/setup-labels.yml @@ -23,19 +23,19 @@ jobs: const requiredLabels = [ // ==================== CONTRIBUTOR LABELS ==================== { - name: 'Org-Member', + name: 'org-Member', color: '0E8A16', description: 'Member of the organization with admin/maintain permissions' }, { name: 'first-time-contributor', color: '7057FF', - description: 'First contribution to this repository' + description: 'First PR of an external contributor' }, { name: 'repeat-contributor', color: '6F42C1', - description: 'External contributor with multiple contributions' + description: 'PR from an external contributor who already had PRs merged' }, // ==================== ISSUE TRACKING LABELS ==================== diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index f5b5298..2bdd4d9 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -278,7 +278,7 @@ jobs: }); if (['admin', 'maintain'].includes(permissionLevel.data.permission)) { - contributorLabels.push('Org-Member'); + contributorLabels.push('org-Member'); isMaintainer = true; } } catch (error) { From 118cd777da21d96206687acdc58f35e595883af6 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 28 Jan 2026 16:44:29 +0530 Subject: [PATCH 08/12] lowercase for consistency. --- .github/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 32a9c30..51e4c3e 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -55,7 +55,7 @@ categories: labels: - 'first-time-contributor' - 'repeat-contributor' - - 'Org-Member' + - 'org-Member' change-template: '- $TITLE @$AUTHOR (#$NUMBER)' change-title-escapes: '\<*_&' From b5949e1200229fa31fb84b5dfc6a520ceb268b86 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 28 Jan 2026 16:51:08 +0530 Subject: [PATCH 09/12] refactor size label handling to improve efficiency and logging --- .github/workflows/sync-pr-labels.yml | 31 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index 2bdd4d9..b253334 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -217,29 +217,40 @@ jobs: sizeLabel = 'size/XL'; } - console.log(`Applying size label: ${sizeLabel}`); + console.log(`Calculated size label: ${sizeLabel}`); - // Remove any existing size labels first + // Get current labels on the PR const currentLabels = await github.rest.issues.listLabelsOnIssue({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber }); - const sizeLabelsToRemove = currentLabels.data + const existingSizeLabels = 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 - }); + // Check if the size label needs to be changed + if (existingSizeLabels.length === 1 && existingSizeLabels[0] === sizeLabel) { + console.log(`Size label ${sizeLabel} is already correct, no changes needed`); + return; + } + + // Remove outdated size labels only if they differ + if (existingSizeLabels.length > 0) { + console.log(`Removing outdated size labels: ${existingSizeLabels.join(', ')}`); + for (const label of existingSizeLabels) { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + name: label + }); + } } // Apply the new size label + console.log(`Applying new size label: ${sizeLabel}`); await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, From f50c4cfbc971775384624d1b14758aa9f333c96c Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Mon, 2 Feb 2026 17:22:25 +0530 Subject: [PATCH 10/12] some cosematic addressed --- .github/release-drafter.yml | 2 +- .github/workflows/setup-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 51e4c3e..e5a173b 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -55,7 +55,7 @@ categories: labels: - 'first-time-contributor' - 'repeat-contributor' - - 'org-Member' + - 'org-member' change-template: '- $TITLE @$AUTHOR (#$NUMBER)' change-title-escapes: '\<*_&' diff --git a/.github/workflows/setup-labels.yml b/.github/workflows/setup-labels.yml index e7c1e56..fb98bf8 100644 --- a/.github/workflows/setup-labels.yml +++ b/.github/workflows/setup-labels.yml @@ -23,7 +23,7 @@ jobs: const requiredLabels = [ // ==================== CONTRIBUTOR LABELS ==================== { - name: 'org-Member', + name: 'org-member', color: '0E8A16', description: 'Member of the organization with admin/maintain permissions' }, From f29a36ab5ea8e912d7798505c26023a0cffb40e3 Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 11 Feb 2026 23:08:47 +0530 Subject: [PATCH 11/12] add CodeRabbit review status labels to sync PR labels workflow --- .github/workflows/sync-pr-labels.yml | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index b253334..1bb0e88 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -319,6 +319,114 @@ jobs: console.log(`Error applying contributor labels: ${error.message}`); } + # STEP 5: CodeRabbit review status labels + - name: Check CodeRabbit review status + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.payload.pull_request.number; + + try { + console.log(`Checking CodeRabbit review threads for PR #${prNumber}`); + + // GraphQL query to fetch review threads and resolution status + const query = ` + query($owner: String!, $repo: String!, $prNumber: Int!) { + repository(owner: $owner, name: $repo) { + pullRequest(number: $prNumber) { + reviewThreads(first: 100) { + nodes { + isResolved + comments(first: 20) { + nodes { + author { + login + } + } + } + } + } + } + } + } + `; + + const result = await github.graphql(query, { + owner: context.repo.owner, + repo: context.repo.repo, + prNumber: prNumber + }); + + const threads = result.repository.pullRequest.reviewThreads.nodes; + + console.log(`Total review threads found: ${threads.length}`); + + // Filter unresolved CodeRabbit threads + const unresolvedCodeRabbitThreads = threads.filter(thread => + !thread.isResolved && + thread.comments.nodes.some(comment => + comment.author && + comment.author.login && + comment.author.login.toLowerCase().includes("coderabbit") + ) + ); + + const hasUnresolvedComments = unresolvedCodeRabbitThreads.length > 0; + + console.log(`Unresolved CodeRabbit threads: ${unresolvedCodeRabbitThreads.length}`); + + // Get current labels + const currentLabels = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber + }); + + const existingLabel = currentLabels.data.find( + label => label.name === "unresolved-code-rabbit-review" + ); + + // Apply label if unresolved comments exist + if (hasUnresolvedComments && !existingLabel) { + + console.log("Applying unresolved-code-rabbit-review label"); + + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + labels: ["unresolved-code-rabbit-review"] + }); + + } + + // Remove label if all comments resolved + if (!hasUnresolvedComments && existingLabel) { + + console.log("Removing unresolved-code-rabbit-review label"); + + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + name: "unresolved-code-rabbit-review" + }); + + } + + if ( + (hasUnresolvedComments && existingLabel) || + (!hasUnresolvedComments && !existingLabel) + ) { + console.log("Label already in correct state. No changes needed."); + } + + } catch (error) { + console.log(`Error checking CodeRabbit review status: ${error.message}`); + core.setFailed(error.message); + } + # Summary step - name: Label sync summary uses: actions/github-script@v7 From 446a9622dde54a56c9441583366176949d53940a Mon Sep 17 00:00:00 2001 From: kpj2006 <24ucs074@lnmiit.ac.in> Date: Wed, 11 Feb 2026 23:13:09 +0530 Subject: [PATCH 12/12] Revert "add CodeRabbit review status labels to sync PR labels workflow" This reverts commit f29a36ab5ea8e912d7798505c26023a0cffb40e3. --- .github/workflows/sync-pr-labels.yml | 108 --------------------------- 1 file changed, 108 deletions(-) diff --git a/.github/workflows/sync-pr-labels.yml b/.github/workflows/sync-pr-labels.yml index 1bb0e88..b253334 100644 --- a/.github/workflows/sync-pr-labels.yml +++ b/.github/workflows/sync-pr-labels.yml @@ -319,114 +319,6 @@ jobs: console.log(`Error applying contributor labels: ${error.message}`); } - # STEP 5: CodeRabbit review status labels - - name: Check CodeRabbit review status - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const prNumber = context.payload.pull_request.number; - - try { - console.log(`Checking CodeRabbit review threads for PR #${prNumber}`); - - // GraphQL query to fetch review threads and resolution status - const query = ` - query($owner: String!, $repo: String!, $prNumber: Int!) { - repository(owner: $owner, name: $repo) { - pullRequest(number: $prNumber) { - reviewThreads(first: 100) { - nodes { - isResolved - comments(first: 20) { - nodes { - author { - login - } - } - } - } - } - } - } - } - `; - - const result = await github.graphql(query, { - owner: context.repo.owner, - repo: context.repo.repo, - prNumber: prNumber - }); - - const threads = result.repository.pullRequest.reviewThreads.nodes; - - console.log(`Total review threads found: ${threads.length}`); - - // Filter unresolved CodeRabbit threads - const unresolvedCodeRabbitThreads = threads.filter(thread => - !thread.isResolved && - thread.comments.nodes.some(comment => - comment.author && - comment.author.login && - comment.author.login.toLowerCase().includes("coderabbit") - ) - ); - - const hasUnresolvedComments = unresolvedCodeRabbitThreads.length > 0; - - console.log(`Unresolved CodeRabbit threads: ${unresolvedCodeRabbitThreads.length}`); - - // Get current labels - const currentLabels = await github.rest.issues.listLabelsOnIssue({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber - }); - - const existingLabel = currentLabels.data.find( - label => label.name === "unresolved-code-rabbit-review" - ); - - // Apply label if unresolved comments exist - if (hasUnresolvedComments && !existingLabel) { - - console.log("Applying unresolved-code-rabbit-review label"); - - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - labels: ["unresolved-code-rabbit-review"] - }); - - } - - // Remove label if all comments resolved - if (!hasUnresolvedComments && existingLabel) { - - console.log("Removing unresolved-code-rabbit-review label"); - - await github.rest.issues.removeLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - name: "unresolved-code-rabbit-review" - }); - - } - - if ( - (hasUnresolvedComments && existingLabel) || - (!hasUnresolvedComments && !existingLabel) - ) { - console.log("Label already in correct state. No changes needed."); - } - - } catch (error) { - console.log(`Error checking CodeRabbit review status: ${error.message}`); - core.setFailed(error.message); - } - # Summary step - name: Label sync summary uses: actions/github-script@v7