Skip to content

Commit 32598ca

Browse files
committed
Added workflows and reusable prompts
0 parents  commit 32598ca

File tree

4 files changed

+265
-0
lines changed

4 files changed

+265
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Analyze Commit and Create Documentation Issue
2+
3+
Analyze commit `{COMMIT_SHA}` in repository `{REPOSITORY}` using the GitHub MCP server.
4+
5+
## Your Task
6+
7+
1. **Examine the commit** using MCP to access:
8+
- Commit diff and changed files
9+
- Current documentation structure
10+
- Project context
11+
12+
2. **Decide if documentation is needed** based on these criteria:
13+
14+
### ✅ Document These:
15+
- Public APIs/Interfaces (functions, classes, endpoints)
16+
- Complex logic requiring explanation
17+
- Architectural or workflow changes
18+
- Breaking changes
19+
- New dependencies or integrations
20+
- Security/performance changes
21+
- Database schemas or data models
22+
- Unit tests
23+
24+
### ❌ Skip These:
25+
- Minor refactoring or formatting
26+
- Internal helpers
27+
- Trivial typo fixes
28+
- Code moves without logic changes
29+
- Patch dependency updates
30+
in the current repository
31+
- Add labels: `documentation`, `automated`
32+
3. **If documentation is needed:**
33+
- Use the GitHub MCP server to create a GitHub issue with title: "📚 Documentation needed for commit test"
34+
- Use assign_copilot_to_issue tool to assign @copilot to issue.
35+
- In the issue body, explain:
36+
- What changed and why it needs documentation
37+
- Which documentation files should be updated
38+
- Any breaking changes or migration notes needed
39+
- Confirm if all steps succeeded or not.
40+
41+
4. **If documentation is NOT needed:**
42+
- Simply explain why in a brief response (no issue needed)
43+
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Analyze Commit for Unit Test Coverage
2+
3+
Analyze commit `{COMMIT_SHA}` in repository `{REPOSITORY}` using the GitHub MCP server to determine if unit tests are missing or need to be added.
4+
5+
## Your Task
6+
7+
1. **Examine the commit** using MCP to access:
8+
- Commit diff and all changed files
9+
- Existing test files in the repository
10+
- Project structure and testing patterns
11+
12+
2. **Identify testable code changes** - Look for:
13+
- New functions, methods, or classes
14+
- Modified business logic
15+
- New API endpoints or routes
16+
- Data validation or transformation logic
17+
- Error handling paths
18+
- Edge cases in algorithms
19+
20+
3. **Check for corresponding tests** using these language-agnostic patterns:
21+
22+
### Common Test File Patterns:
23+
| Source File | Expected Test File Patterns |
24+
|-------------|----------------------------|
25+
| `src/foo.ts` | `src/foo.test.ts`, `src/foo.spec.ts`, `test/foo.test.ts`, `tests/foo.test.ts` |
26+
| `src/foo.py` | `src/test_foo.py`, `tests/test_foo.py`, `src/foo_test.py` |
27+
| `src/Foo.java` | `src/FooTest.java`, `test/FooTest.java` |
28+
| `src/foo.go` | `src/foo_test.go` |
29+
| `src/foo.rs` | `src/foo_test.rs`, `tests/foo.rs` |
30+
| `src/foo.rb` | `spec/foo_spec.rb`, `test/foo_test.rb` |
31+
| `src/foo.cs` | `src/FooTests.cs`, `tests/FooTests.cs` |
32+
| `lib/foo.js` | `lib/foo.test.js`, `test/foo.test.js` |
33+
34+
### Common Test Directories:
35+
- `test/`, `tests/`, `spec/`, `__tests__/`
36+
- `src/__tests__/`, `src/test/`
37+
- Language-specific: `pytest/`, `jest/`, `rspec/`
38+
39+
4. **Evaluate test coverage need** based on:
40+
41+
### ✅ Tests Likely Needed:
42+
- New public functions/methods without corresponding test additions
43+
- Complex conditional logic (if/else, switch) added
44+
- New error handling or exception paths
45+
- Data parsing, validation, or transformation
46+
- New API endpoints or route handlers
47+
- Database queries or data access logic
48+
- Security-related code (auth, encryption, sanitization)
49+
- Business rules or domain logic
50+
- Integration points with external services
51+
52+
### ❌ Tests Likely NOT Needed:
53+
- Pure configuration file changes
54+
- Documentation or comment-only changes
55+
- Type definitions or interfaces only
56+
- Simple constant definitions
57+
- Dependency version updates only
58+
- CSS/styling changes only
59+
- Trivial getter/setter additions
60+
- Test file changes themselves (tests testing tests)
61+
- Generated or auto-generated code
62+
- Migration scripts that are run once
63+
64+
5. **Calculate a confidence score** (0-100) for whether tests are needed:
65+
- 80-100: Tests definitely needed - significant untested logic added
66+
- 60-79: Tests recommended - meaningful code without test coverage
67+
- 40-59: Tests optional - minor changes that could use tests
68+
- 0-39: Tests not needed - trivial or already covered
69+
70+
6. **If tests are recommended (score >= 60):**
71+
72+
Create a GitHub issue using MCP with:
73+
74+
**Title:** `🧪 Unit tests needed for: [brief description of changes]`
75+
76+
**Body should include:**
77+
```markdown
78+
## Test Coverage Analysis
79+
80+
**Commit:** {COMMIT_SHA}
81+
**Confidence Score:** [X]/100
82+
83+
### Files Needing Tests
84+
85+
| Source File | Status | Suggested Test File |
86+
|-------------|--------|---------------------|
87+
| `path/to/file.ext` | ⚠️ No tests found | `path/to/file.test.ext` |
88+
89+
### Recommended Test Cases
90+
91+
For each file, list specific functions/methods and suggested test scenarios:
92+
93+
#### `filename.ext`
94+
- [ ] Test `functionName()` - happy path
95+
- [ ] Test `functionName()` - error handling
96+
- [ ] Test `functionName()` - edge cases (null, empty, boundary values)
97+
98+
### Why Tests Are Needed
99+
100+
[Explain the risk of not having tests for this code]
101+
102+
### Testing Hints
103+
104+
- Framework detected: [Jest/Pytest/JUnit/etc. or "Unknown"]
105+
- Existing test patterns: [Describe patterns found in repo]
106+
- Mock/stub suggestions: [If external dependencies need mocking]
107+
108+
---
109+
*Auto-generated by test coverage workflow*
110+
```
111+
112+
- Add labels: `testing`, `automated`, `unit-tests`
113+
- Use assign_copilot_to_issue tool to assign @copilot to the issue
114+
115+
7. **If tests are NOT needed (score < 60):**
116+
- Provide a brief explanation of why tests aren't necessary
117+
- No issue creation needed
118+
119+
## Important Guidelines
120+
121+
- Be language-agnostic - detect the language from file extensions
122+
- Consider the project's existing testing conventions
123+
- Don't flag test files as needing tests
124+
- Consider that some projects use different testing philosophies
125+
- Account for integration tests vs unit tests
126+
- Be specific about WHAT should be tested, not just that tests are needed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Generate Documentation with Copilot
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'docs/**'
7+
- '**.md'
8+
9+
jobs:
10+
generate-docs:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install GitHub Copilot CLI
20+
env:
21+
GH_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
22+
run: |
23+
curl -fsSL https://gh.io/copilot-install | bash
24+
echo "Installed Copilot CLI version:"
25+
copilot --version
26+
27+
- name: Analyze and delegate to Copilot
28+
env:
29+
GH_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
30+
run: |
31+
echo "Analyzing commit ${{ github.sha }}"
32+
echo "Loading documentation criteria from prompt..."
33+
34+
PROMPT=$(cat .github/prompts/analyze-for-docs.prompt.md)
35+
PROMPT="${PROMPT//\{COMMIT_SHA\}/${{ github.sha }}}"
36+
PROMPT="${PROMPT//\{REPOSITORY\}/${{ github.repository }}}"
37+
38+
echo "Delegating to GitHub Copilot..."
39+
echo "- Copilot will use MCP to examine the commit"
40+
echo "- Copilot will decide if documentation is needed"
41+
echo "- Copilot will create an issue and assign it to itself if needed"
42+
echo ""
43+
44+
copilot -p "$PROMPT" --enable-all-github-mcp-tools --allow-all-tools
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Generate Tests with Copilot
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'docs/**'
7+
- '**.md'
8+
- '.github/workflows/**'
9+
- '.gitignore'
10+
- 'LICENSE'
11+
- '*.config.js'
12+
- '*.config.ts'
13+
14+
jobs:
15+
generate-tests:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Install GitHub Copilot CLI
25+
env:
26+
GH_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
27+
run: |
28+
curl -fsSL https://gh.io/copilot-install | bash
29+
echo "Installed Copilot CLI version:"
30+
copilot --version
31+
32+
- name: Analyze and generate tests with Copilot
33+
env:
34+
GH_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
35+
run: |
36+
echo "Analyzing commit ${{ github.sha }} for test coverage..."
37+
echo "Source files changed: ${{ steps.changes.outputs.source_count }}"
38+
echo ""
39+
40+
# Load the prompt template
41+
PROMPT=$(cat .github/prompts/analyze-for-tests.prompt.md)
42+
PROMPT="${PROMPT//\{COMMIT_SHA\}/${{ github.sha }}}"
43+
PROMPT="${PROMPT//\{REPOSITORY\}/${{ github.repository }}}"
44+
45+
echo "Delegating to GitHub Copilot for test analysis..."
46+
echo "- Copilot will examine the commit diff"
47+
echo "- Copilot will check for corresponding test files"
48+
echo "- Copilot will assess if new tests are needed"
49+
echo "- Copilot will create an issue if tests are recommended"
50+
echo ""
51+
52+
copilot -p "$PROMPT" --enable-all-github-mcp-tools --allow-all-tools --no-ask-user

0 commit comments

Comments
 (0)