GitHub Copilot Integration¶
Supercharge your debugging workflow by combining AI Workflow Failure Summary Action with GitHub Copilot.
Overview¶
This action generates AI-powered failure analyses that are optimized for GitHub Copilot consumption. The structured output format makes it easy for Copilot to understand the context and provide intelligent suggestions.
graph TB
A[Workflow Fails] --> B[AI Action Analyzes]
B --> C[Structured Summary]
C --> D[Posted to Issue/Summary]
D --> E[Developer Reviews]
E --> F[Ask Copilot for Help]
F --> G[Copilot Suggests Fixes]
G --> H[Apply & Test]
H --> I{Fixed?}
I -->|Yes| J[Ship It!]
I -->|No| F
How It Works¶
1. Failure Analysis is Generated¶
When a workflow fails, the action creates a structured summary:
## Summary
Test suite failed due to missing DATABASE_URL environment variable
## Root Cause
The integration tests require DATABASE_URL but it's not set in the workflow
## Error Location
- File: test/integration/db.test.js:15
- Error: DATABASE_URL is not defined
## Recommended Actions
1. Add DATABASE_URL to workflow environment
2. Configure in repository secrets
...
2. Copilot Understands the Context¶
GitHub Copilot can read: - ✅ Issue descriptions created by the action - ✅ GitHub Actions summary output - ✅ Structured error details - ✅ File paths and line numbers - ✅ Recommended fix actions
3. Get AI-Powered Fix Suggestions¶
Ask Copilot questions like:
- "Review the latest workflow failure and suggest fixes"
- "Based on the AI analysis, how do I fix the DATABASE_URL error?"
- "Show me how to add environment variables to the workflow"
- "Create a fix for the issue #123 found by AI analysis"
Usage Patterns¶
In GitHub Issues¶
When create-issue: true is enabled, Copilot can read the issue directly:
In VSCode¶
Using Copilot Chat Panel¶
- Open Copilot Chat (Ctrl+Shift+I / Cmd+Shift+I)
- Reference the analysis:
@workspace The CI workflow failed with error in src/api/handler.ts
The AI analysis says there's a type mismatch. Can you show me the fix?
Using Inline Suggestions¶
With the analyzed file open:
// Copilot will suggest fixes based on:
// - The error location from AI analysis
// - The recommended actions
// - Your existing code context
In GitHub Web UI¶
Reviewing PRs¶
- PR fails and AI analysis runs
- Analysis posted as comment or issue
- Review the analysis in the PR
- Ask Copilot:
@github-copilot[bot] suggest fixes for these failures
In Actions Tab¶
- Navigate to failed workflow run
- View AI summary in the run summary
- Copy relevant parts to Copilot
- Get contextual help
Optimizing for Copilot¶
Use Structured Output¶
Ensure your custom prompts produce Copilot-friendly output:
Format your analysis for GitHub Copilot:
1. **Use Precise File References**: Always include full paths
- Good: `src/components/Button.tsx:45`
- Bad: "in the Button component"
2. **Include Code Snippets**: Show the problematic code
```typescript
// Current (broken):
const result = await fetch(url)
// Should be:
const result = await fetch(url).then(r => r.json())
```
3. **Provide Diff Format**: Show exact changes needed
```diff
- const API_URL = undefined
+ const API_URL = process.env.REACT_APP_API_URL
```
4. **Link Documentation**: Include relevant doc URLs
- [React Hooks Docs](https://react.dev/reference/react)
- [TypeScript Handbook](https://www.typescriptlang.org/docs/)
5. **Use Consistent Formatting**:
- Headers: ## Summary, ## Root Cause, etc.
- Lists: Numbered for steps, bullets for items
- Code blocks: Always specify language
Create Copilot Workspace Context¶
Add a .github/copilot-instructions.md file (if supported):
# Copilot Context for This Repository
## Tech Stack
- Node.js 20+
- React 18 with TypeScript
- Jest for testing
- GitHub Actions for CI/CD
## Common CI/CD Issues
When helping with workflow failures:
1. Check .github/workflows/ for workflow definitions
2. Review package.json for scripts and dependencies
3. Look at test files in __tests__/
4. Consider environment variables in .env.example
## Our Coding Standards
- TypeScript strict mode enabled
- All components must have tests
- Use async/await over promises
- Follow ESLint configuration
When the AI Failure Analysis action identifies an issue,
provide fixes that match these standards.
Example Workflows¶
Full Integration Example¶
name: CI with AI and Copilot Integration
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
ai-analysis:
runs-on: ubuntu-latest
if: failure()
needs: [test]
permissions:
actions: read
contents: read
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Analyze with AI
id: analyze
uses: ianlintner/ai_summary_action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
create-issue: 'true'
custom-system-prompt: '.github/prompts/copilot-optimized.md'
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const summary = `## 🤖 AI Failure Analysis
${process.env.ANALYSIS_SUMMARY}
### 💡 Next Steps
Ask @github-copilot[bot] to help fix these issues:
- "Suggest fixes for the errors in this PR"
- "Explain the root cause and show me how to fix it"
- "Update the tests based on this analysis"
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});
env:
ANALYSIS_SUMMARY: ${{ steps.analyze.outputs.summary }}
Copilot Prompts Library¶
General Debugging¶
@workspace Review the latest AI workflow failure analysis and:
1. Identify all files that need changes
2. Suggest specific code fixes
3. Explain why the error occurred
4. Help me write tests to prevent this
Test Failures¶
The AI analysis shows test failures in [file].
@workspace Can you:
- Fix the failing tests
- Explain what changed
- Suggest additional test cases
Build Errors¶
@workspace The build failed with errors in [files].
Based on the AI analysis:
1. Show me the exact changes needed
2. Update the relevant files
3. Explain the root cause
Dependency Issues¶
@workspace The AI analysis identified dependency conflicts.
Help me:
- Understand which packages are incompatible
- Suggest compatible versions
- Update package.json accordingly
Advanced Integration¶
Custom Copilot Actions¶
Create a custom Copilot action for your repository:
{
"actions": [
{
"name": "Fix CI Failure",
"description": "Analyze and fix the latest CI failure using AI insights",
"steps": [
"Read the latest AI failure analysis issue",
"Identify files that need changes",
"Generate fixes based on recommendations",
"Create a PR with the fixes"
]
}
]
}
Workspace Extensions¶
Use VSCode extensions to enhance integration:
{
"github.copilot.advanced": {
"inlineSuggestEnable": true,
"enableAutoCompletions": true
},
"github.copilot.enable": {
"*": true,
"yaml": true,
"markdown": true
}
}
Best Practices¶
✅ Do¶
- Enable Issue Creation: Makes it easy for Copilot to reference
- Use Clear File Paths: Help Copilot find the right files
- Include Code Snippets: Show Copilot what's wrong
- Add Context: Explain your tech stack in prompts
- Link Documentation: Help Copilot reference correct docs
❌ Don't¶
- Don't Use Vague Errors: Be specific in analysis
- Don't Skip Line Numbers: Copilot needs precise locations
- Don't Mix Issues: One analysis per failure type
- Don't Ignore Copilot Limits: Keep context reasonable
Troubleshooting¶
Copilot not understanding the analysis? - Ensure output is in markdown format - Use clear headers and sections - Include file paths and line numbers - Try more structured prompts
Copilot suggestions not relevant?
- Add more context to custom prompts
- Reference specific files in questions
- Include tech stack details
- Use @workspace scope in questions
Can't reference issues? - Make sure issue creation is enabled - Check issue permissions in workflow - Verify issue is public (or you have access)
Real-World Example¶
Here's a complete flow from failure to fix:
- Workflow fails in PR #123
- AI Action analyzes, creates issue #456
- Developer reviews issue in VSCode
- Asks Copilot:
- Copilot suggests:
- Developer applies the fix
- Push & verify tests pass ✅