-
Notifications
You must be signed in to change notification settings - Fork 40
Add docs-from-code workflow to process labeled issues with Copilot #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/add-issue-trigger-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ea46b30
Initial plan
Copilot 0022f92
Add docs-from-code workflow for processing labeled issues
Copilot 923cdff
Address code review feedback for docs-from-code workflow
Copilot b08008c
Refine condition check and simplify redundant logic
Copilot fbaf104
Update .github/workflows/docs-from-code.yml
IEvangelist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| name: Process Docs from Code Issues | ||
|
|
||
| on: | ||
| issues: | ||
| types: [labeled] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| assign-to-copilot: | ||
| name: Assign to Copilot Agent | ||
| runs-on: ubuntu-latest | ||
| if: github.event.action == 'labeled' && github.event.label.name == 'docs-from-code' | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Extract SME from issue body | ||
| id: extract-sme | ||
| uses: actions/github-script@v7 | ||
IEvangelist marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with: | ||
| script: | | ||
| const issueBody = context.payload.issue.body || ''; | ||
|
|
||
| // Look for PR author pattern in issue body | ||
| // Expected format from dotnet/aspire workflow: "PR Author: @username" or similar | ||
| const authorPatterns = [ | ||
| /PR\s*Author:\s*@?([\w-]+)/i, | ||
| /Author:\s*@?([\w-]+)/i, | ||
| /SME:\s*@?([\w-]+)/i, | ||
| /Original\s*PR\s*by\s*@?([\w-]+)/i, | ||
| /Created\s*by\s*@([\w-]+)/i | ||
| ]; | ||
|
|
||
| let smeUsername = null; | ||
|
|
||
| for (const pattern of authorPatterns) { | ||
| const match = issueBody.match(pattern); | ||
| if (match) { | ||
| smeUsername = match[1]; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Also try to extract PR URL if present | ||
| const prUrlPattern = /https:\/\/github\.com\/dotnet\/aspire\/pull\/(\d+)/; | ||
| const prUrlMatch = issueBody.match(prUrlPattern); | ||
|
|
||
| if (!smeUsername && prUrlMatch) { | ||
| // If we found a PR URL but no author, we'll need to fetch it | ||
| const prNumber = prUrlMatch[1]; | ||
| try { | ||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: 'dotnet', | ||
| repo: 'aspire', | ||
| pull_number: parseInt(prNumber) | ||
| }); | ||
| smeUsername = pr.user.login; | ||
| console.log(`Extracted SME from PR #${prNumber}: ${smeUsername}`); | ||
| } catch (error) { | ||
| console.log(`Could not fetch PR details: ${error.message}`); | ||
| } | ||
| } | ||
|
|
||
| core.setOutput('sme', smeUsername || ''); | ||
| core.setOutput('found', smeUsername ? 'true' : 'false'); | ||
|
|
||
| console.log(`SME Username: ${smeUsername || 'not found'}`); | ||
|
|
||
| - name: Assign issue to Copilot | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const issueNumber = context.payload.issue.number; | ||
|
|
||
| // Assign the issue to copilot | ||
| try { | ||
| await github.rest.issues.addAssignees({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| assignees: ['copilot'] | ||
| }); | ||
| console.log(`Successfully assigned issue #${issueNumber} to copilot`); | ||
| } catch (error) { | ||
| console.log(`Could not assign to copilot: ${error.message}`); | ||
| // Continue even if assignment fails | ||
| } | ||
|
|
||
| - name: Add comment mentioning SME | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const issueNumber = context.payload.issue.number; | ||
| const smeUsername = '${{ steps.extract-sme.outputs.sme }}'; | ||
| const smeFound = '${{ steps.extract-sme.outputs.found }}' === 'true'; | ||
|
|
||
| let commentBody = '## 🤖 Copilot Agent Assigned\n\n'; | ||
| commentBody += 'This issue has been assigned to GitHub Copilot to draft a pull request based on the description provided.\n\n'; | ||
|
|
||
| if (smeFound) { | ||
| commentBody += '### 📋 SME Review Required\n\n'; | ||
| commentBody += `@${smeUsername} - You have been identified as the subject matter expert (SME) for this documentation update based on the originating PR in the [dotnet/aspire](https://github.com/dotnet/aspire) repository. Please review the draft PR once Copilot has completed its work.\n`; | ||
| } else { | ||
| commentBody += '### ⚠️ SME Not Found\n\n'; | ||
| commentBody += 'Could not automatically identify the SME from the issue body. Please manually tag the appropriate reviewer once the draft PR is created.\n'; | ||
| } | ||
|
|
||
| commentBody += '\n---\n*This comment was automatically generated by the docs-from-code workflow.*'; | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber, | ||
| body: commentBody | ||
| }); | ||
|
|
||
| console.log(`Added comment to issue #${issueNumber}`); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.