🤖 Update dependencies with Copilot assignment #52
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: 🤖 Update dependencies with Copilot assignment | |
| on: | |
| workflow_dispatch: # run on demand | |
| schedule: | |
| - cron: "27 5 * * 0" # run every Sunday at 5:27 AM UTC | |
| # set up octo-sts to get the correct token that's user scoped | |
| jobs: | |
| create-and-assign-issue: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| contents: read | |
| steps: | |
| - name: Checkout the repo | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Get the issue fields from the template | |
| uses: imjohnbo/extract-issue-template-fields@fcdd71b8add0dbd44221bcc368924a7722db96d2 # v1.0.3 | |
| id: extract | |
| with: | |
| path: .github/ISSUE_TEMPLATE/ai-update.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check if Copilot is enabled and get repository info | |
| id: copilot-check | |
| run: | | |
| # Get repository ID and check for Copilot | |
| REPO_QUERY='query { | |
| repository(owner: "${{ github.repository_owner }}", name: "kubernoodles") { | |
| id | |
| suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) { | |
| nodes { | |
| login | |
| __typename | |
| ... on Bot { | |
| id | |
| } | |
| ... on User { | |
| id | |
| } | |
| } | |
| } | |
| } | |
| }' | |
| RESPONSE=$(curl -X POST \ | |
| -H "Authorization: bearer ${{ secrets.COPILOT_USER }}" \ | |
| -H "Content-Type: application/json" \ | |
| --data-raw "{\"query\": \"$(echo $REPO_QUERY | tr -d '\n' | sed 's/"/\\"/g')\"}" \ | |
| https://api.github.com/graphql) | |
| echo "GraphQL Response: $RESPONSE" | |
| # Extract repository ID | |
| REPO_ID=$(echo $RESPONSE | jq -r '.data.repository.id') | |
| echo "REPO_ID=$REPO_ID" >> $GITHUB_OUTPUT | |
| # Find Copilot bot ID | |
| COPILOT_ID=$(echo $RESPONSE | jq -r '.data.repository.suggestedActors.nodes[] | select(.login == "copilot-swe-agent") | .id') | |
| echo "COPILOT_ID=$COPILOT_ID" >> $GITHUB_OUTPUT | |
| if [ "$COPILOT_ID" = "null" ] || [ -z "$COPILOT_ID" ]; then | |
| echo "Copilot not found in suggested actors" | |
| echo "COPILOT_ENABLED=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Copilot found with ID: $COPILOT_ID" | |
| echo "COPILOT_ENABLED=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create issue and assign to Copilot | |
| if: steps.copilot-check.outputs.COPILOT_ENABLED == 'true' | |
| id: create-issue-copilot | |
| run: | | |
| # Get current date for title | |
| DATE=$(date +%Y-%m-%d) | |
| # Log the repository ID and Copilot ID | |
| echo "Repository ID: ${{ steps.copilot-check.outputs.REPO_ID }}" | |
| echo "Copilot ID: ${{ steps.copilot-check.outputs.COPILOT_ID }}" | |
| # Create the GraphQL mutation with proper JSON escaping | |
| # First escape the body content for JSON | |
| ESCAPED_BODY=$(echo '${{ steps.extract.outputs.body }}' | jq -Rs .) | |
| ESCAPED_TITLE=$(echo '${{ steps.extract.outputs.title }}' | jq -Rs .) | |
| # Build the JSON payload | |
| JSON_PAYLOAD=$(jq -n \ | |
| --arg repoId "${{ steps.copilot-check.outputs.REPO_ID }}" \ | |
| --arg title "${{ steps.extract.outputs.title }} for $DATE" \ | |
| --argjson body "$ESCAPED_BODY" \ | |
| --arg copilotId "${{ steps.copilot-check.outputs.COPILOT_ID }}" \ | |
| '{ | |
| query: "mutation($repoId: ID!, $title: String!, $body: String!, $copilotId: ID!) { createIssue(input: { repositoryId: $repoId, title: $title, body: $body, assigneeIds: [$copilotId] }) { issue { id number title url assignees(first: 10) { nodes { login } } } } }", | |
| variables: { | |
| repoId: $repoId, | |
| title: $title, | |
| body: $body, | |
| copilotId: $copilotId | |
| } | |
| }') | |
| # Execute the mutation | |
| RESPONSE=$(curl -X POST \ | |
| -H "Authorization: bearer ${{ secrets.COPILOT_USER }}" \ | |
| -H "Content-Type: application/json" \ | |
| -H "GraphQL-Features: issues_copilot_assignment_api_support" \ | |
| --data-raw "$JSON_PAYLOAD" \ | |
| https://api.github.com/graphql) | |
| echo "Create issue response: $RESPONSE" | |
| # Extract issue details | |
| ISSUE_NUMBER=$(echo $RESPONSE | jq -r '.data.createIssue.issue.number') | |
| ISSUE_URL=$(echo $RESPONSE | jq -r '.data.createIssue.issue.url') | |
| echo "Created issue #$ISSUE_NUMBER: $ISSUE_URL" | |
| echo "ISSUE_NUMBER=$ISSUE_NUMBER" >> $GITHUB_OUTPUT | |
| echo "ISSUE_URL=$ISSUE_URL" >> $GITHUB_OUTPUT | |
| - name: Fallback - Create issue without Copilot assignment | |
| if: steps.copilot-check.outputs.COPILOT_ENABLED == 'false' | |
| uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd # v3.4.4 | |
| id: create-issue-fallback | |
| with: | |
| title: "${{ steps.extract.outputs.title }} for ${{ env.date }}" | |
| body: ${{ steps.extract.outputs.body }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Summary | |
| run: | | |
| if [ "${{ steps.copilot-check.outputs.COPILOT_ENABLED }}" == "true" ]; then | |
| echo "✅ Issue created and assigned to Copilot: ${{ steps.create-issue-copilot.outputs.ISSUE_URL }}" | |
| else | |
| echo "⚠️ Copilot not available - issue created without assignment" | |
| fi |