Feat(Agent): Refactor multi-agent collaboration #310
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Under Review Label | |
| # Automatically adds "Under Review" label when a maintainer (admin/maintain/write permission) | |
| # comments on or reviews a PR. | |
| # Note: Review events may not work on fork PRs due to GitHub Actions permission restrictions, | |
| # but the workflow will exit gracefully without errors. | |
| on: | |
| issue_comment: | |
| types: [created] | |
| pull_request_review: | |
| types: [submitted] | |
| pull_request_review_comment: | |
| types: [created] | |
| jobs: | |
| add-under-review-label: | |
| # Only run on pull requests | |
| if: github.event.issue.pull_request || github.event.pull_request | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - name: Add Under Review label | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| // Get commenter/reviewer information and PR details | |
| let commenter; | |
| let commenterType; | |
| let prNumber; | |
| let prAuthor; | |
| if (context.eventName === 'issue_comment') { | |
| commenter = context.payload.comment.user.login; | |
| commenterType = context.payload.comment.user.type; | |
| prNumber = context.payload.issue.number; | |
| prAuthor = context.payload.issue.user.login; | |
| } else if (context.eventName === 'pull_request_review') { | |
| commenter = context.payload.review.user.login; | |
| commenterType = context.payload.review.user.type; | |
| prNumber = context.payload.pull_request.number; | |
| prAuthor = context.payload.pull_request.user.login; | |
| } else if (context.eventName === 'pull_request_review_comment') { | |
| commenter = context.payload.comment.user.login; | |
| commenterType = context.payload.comment.user.type; | |
| prNumber = context.payload.pull_request.number; | |
| prAuthor = context.payload.pull_request.user.login; | |
| } | |
| core.info(`Processing from @${commenter} (type: ${commenterType}) on PR #${prNumber} by @${prAuthor}`); | |
| // Ignore bots | |
| if (commenterType === 'Bot' || commenter.endsWith('[bot]')) { | |
| core.info(`@${commenter} is a bot, skipping`); | |
| return; | |
| } | |
| // Ignore PR author self-comments | |
| if (commenter === prAuthor) { | |
| core.info(`@${commenter} is the PR author, skipping self-comment`); | |
| return; | |
| } | |
| // Check commenter's permission level | |
| core.info(`Checking permissions for @${commenter}`); | |
| let permission; | |
| try { | |
| const response = await github.rest.repos.getCollaboratorPermissionLevel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| username: commenter, | |
| }); | |
| permission = response.data; | |
| } catch (error) { | |
| // Handle non-collaborators (404) or other API errors | |
| if (error.status === 404) { | |
| core.info(`@${commenter} is not a collaborator, skipping`); | |
| return; | |
| } | |
| // For other errors, log and exit gracefully | |
| core.warning(`Failed to get permissions for @${commenter}: ${error.message}`); | |
| return; | |
| } | |
| core.info(`@${commenter} permission level: ${permission.permission}`); | |
| // Check if user has admin, maintain, or write permission | |
| const allowedPermissions = ['admin', 'maintain', 'write']; | |
| if (!allowedPermissions.includes(permission.permission)) { | |
| core.info(`@${commenter} has insufficient permissions (${permission.permission}), skipping`); | |
| return; | |
| } | |
| // Check if label already exists before adding | |
| const { data: labels } = await github.rest.issues.listLabelsOnIssue({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const hasLabel = labels.some(label => label.name === 'Under Review'); | |
| if (hasLabel) { | |
| core.info(`PR #${prNumber} already has "Under Review" label, skipping`); | |
| return; | |
| } | |
| // Add label | |
| try { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| labels: ['Under Review'], | |
| }); | |
| core.info(`Successfully added "Under Review" label to PR #${prNumber}`); | |
| } catch (error) { | |
| if (error.status === 403) { | |
| core.info(`Unable to add label due to permissions (403). This is expected for review events on fork PRs.`); | |
| } else { | |
| core.warning(`Failed to add label: ${error.message}`); | |
| } | |
| } | |