From e5ec69447ae82bcde68b417ed4c40e206305e8f0 Mon Sep 17 00:00:00 2001 From: Nev Wylie <54870357+MSNev@users.noreply.github.com> Date: Tue, 27 May 2025 17:21:28 -0700 Subject: [PATCH] Remove Auto-Assign workflow - copilot needs to be made a collaborator which they won't be --- .../workflows/copilot-triage-assignment.yml | 176 ------------------ 1 file changed, 176 deletions(-) delete mode 100644 .github/workflows/copilot-triage-assignment.yml diff --git a/.github/workflows/copilot-triage-assignment.yml b/.github/workflows/copilot-triage-assignment.yml deleted file mode 100644 index 92c08b2eb..000000000 --- a/.github/workflows/copilot-triage-assignment.yml +++ /dev/null @@ -1,176 +0,0 @@ -name: Assign Copilot to Triage - -on: - issues: - types: [labeled] - pull_request: - types: [labeled] - -permissions: - contents: read - issues: write - pull-requests: write - -env: - COPILOT_USERNAMES: ${{ vars.COPILOT_USERNAMES }} - -jobs: - assign-copilot: - runs-on: ubuntu-latest - if: ${{ github.event.label.name == 'triage-copilot' }} - steps: - - name: Check if actor is authorized - id: check_auth - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - // Check if the user has admin/write permissions (this will work regardless of team membership) - try { - const permission = await github.rest.repos.getCollaboratorPermissionLevel({ - owner: context.repo.owner, - repo: context.repo.repo, - username: context.actor - }); - - // Admin or write permission is sufficient - if (permission.data.permission === 'admin' || permission.data.permission === 'write') { - console.log(`${context.actor} has ${permission.data.permission} permissions - authorized`); - return true; - } - } catch (error) { - console.log(`Error checking permissions: ${error.message}`); - } - - // Also check direct mention in CODEOWNERS file - try { - const codeownersContent = await github.rest.repos.getContent({ - owner: context.repo.owner, - repo: context.repo.repo, - path: 'CODEOWNERS' - }); - - const content = Buffer.from(codeownersContent.data.content, 'base64').toString(); - if (content.includes(`@${context.actor}`)) { - console.log(`${context.actor} is directly mentioned in CODEOWNERS - authorized`); - return true; - } - } catch (error) { - console.log(`Error checking CODEOWNERS: ${error.message}`); - } - - console.log(`${context.actor} is not authorized to assign Copilot`); - return false; - result-encoding: string - - - name: Assign GitHub Copilot - if: ${{ steps.check_auth.outputs.result == 'true' }} - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const issueOrPR = context.payload.issue || context.payload.pull_request; - - if (issueOrPR) { - try { // First, let's verify if we can find a valid "copilot" user to assign - let assigneeUsername = ''; - - // Try multiple possible usernames for Copilot - const possibleCopilotUsers = process.env.COPILOT_USERNAMES.split(',').map(u => u.trim()); - - for (const username of possibleCopilotUsers) { - try { - // Check if user exists and can be assigned - const user = await github.rest.users.getByUsername({ - username: username - }); - - if (user.data && user.data.login === username && user.data.type === "Bot") { - assigneeUsername = username; - console.log(`Found valid assignee: ${username}`); - break; - } else if (user){ - console.log(`User ${username} is not a valid assignee - ${user.status}`); - } else { - console.log(`API Call failed for ${username} - ${user}`); - } - } catch (userError) { - console.log(`User ${username} not found or not available: ${userError.message}`); - } - } - - // If we found a valid assignee, try to assign them - if (assigneeUsername) { - try { - const assignResult = await github.rest.issues.addAssignees({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueOrPR.number, - assignees: [assigneeUsername] - }); - - console.log(`AssignResult: ${assignResult.status}`); - - // Verify assignment was successful by checking the response - if (assignResult.status === 201 && assignResult.data.assignees.some(a => a.login === assigneeUsername)) { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueOrPR.number, - body: `GitHub Copilot (${assigneeUsername}) has been assigned to assist with this task.` - }); - - console.log(`Successfully assigned ${assigneeUsername} to ${context.repo.owner}/${context.repo.repo}#${issueOrPR.number}`); - return; - } else { - throw new Error("Assignment appeared to succeed but assignee was not added"); - } - } catch (error) { - console.log(`Assignment to ${assigneeUsername} failed: ${error.message}`); - // Continue to alternative approach - } - } - // If assignment fails, add a special label and a more descriptive comment - // First add a "needs-copilot-attention" label - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueOrPR.number, - labels: ['needs-copilot-attention'] - }); - - // Then add a detailed comment - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueOrPR.number, - body: '**Action Required**: Unable to directly assign GitHub Copilot to this task.\n\n' + - 'This issue has been labeled with `needs-copilot-attention` for review by the team.' - }); - - console.log(`Added 'needs-copilot-attention' label to ${context.repo.owner}/${context.repo.repo}#${issueOrPR.number}`); } catch (error) { - console.log(`Error in Copilot assignment workflow: ${error.message}`); - - try { - // Add a label to indicate there was an error - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueOrPR.number, - labels: ['copilot-assignment-error'] - }).catch(e => console.log(`Could not add error label: ${e.message}`)); - - // Add a comment with detailed error information - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueOrPR.number, - body: `⚠️ **Error in Copilot Assignment Workflow**\n\n` + - `There was an error while trying to assign GitHub Copilot to this task:\n\`\`\`\n${error.message}\n\`\`\`\n\n` + - `Please contact a repository administrator for assistance.` - }); - } catch (commentError) { - console.log(`Error posting error comment: ${commentError.message}`); - } - } - }