Skip to content

Commit f9800c4

Browse files
committed
fix: optimize skill
1 parent 740f5df commit f9800c4

2 files changed

Lines changed: 77 additions & 9 deletions

File tree

.agents/skills/pr-comment-resolver/SKILL.md

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,39 @@ This skill outlines the step-by-step workflow for fetching, analyzing, addressin
2222
* Call the MCP tool `list_pull_requests` on `github-mcp-server` (or query the GitHub API) to locate the open pull request that corresponds to the active branch. Note down the `pullNumber`.
2323

2424
### 2. Retrieve Review Comments
25+
**Option A: Using GitHub CLI (Recommended)**
26+
```bash
27+
# Get all pull request review comments
28+
gh api repos/bcgov/nr-silva/pulls/<PR_NUMBER>/comments
29+
30+
# Parse with Python for readability
31+
gh api repos/bcgov/nr-silva/pulls/<PR_NUMBER>/comments 2>&1 | python3 -c "
32+
import json, sys
33+
for c in json.load(sys.stdin):
34+
print(f'ID: {c[\"id\"]} | Path: {c[\"path\"]} | Line: {c[\"line\"]} | Body: {c[\"body\"][:80]}...')
35+
"
36+
```
37+
38+
**Option B: Using MCP Tools**
2539
* Call the `pull_request_read` tool with `method="get_review_comments"`, specifying the `owner`, `repo`, and `pullNumber`.
26-
* Identify all unresolved comment threads (`is_resolved: false`). For each thread, extract:
27-
* The `commentId` (obtained from the comment object or the suffix of `html_url` e.g., `#discussion_r3599506357` -> `3599506357`).
40+
41+
**For each comment, extract:**
42+
* The `commentId` (the numeric ID, e.g., `3678193517`).
2843
* The file `path` and target `line` numbers.
2944
* The comment `body` detailing the requested change.
45+
* The `is_resolved` flag — only address unresolved comments (`is_resolved: false`).
46+
47+
### 3. Validate Comments Retrieved
48+
**Before proceeding, confirm:**
49+
```bash
50+
# Count total unresolved comments
51+
gh api repos/bcgov/nr-silva/pulls/<PR_NUMBER>/comments | \
52+
python3 -c "import json, sys; comments = json.load(sys.stdin); print(f'Total: {len(comments)} comment(s)')"
53+
```
54+
* If count is **0**, the PR may not have review comments yet, or they may already be resolved.
55+
* If count is **> 0**, proceed with validation and addressing each comment.
3056

31-
### 3. Validate Each Comment
57+
### 4. Validate Each Comment
3258
For each comment:
3359
1. **Read Context**: Examine the referenced code, the full method/component, and surrounding logic.
3460
2. **Assess Validity**: Determine if the comment is:
@@ -41,7 +67,7 @@ For each comment:
4167
- If **valid**: Proceed to Step 4 (Address the Comment).
4268
- If **invalid/unnecessary**: Reply with a brief explanation of why the comment is not applicable, then move to next comment.
4369

44-
### 4. Address Each Valid Comment Sequentially
70+
### 5. Address Each Valid Comment Sequentially
4571
For each validated comment:
4672
1. **Analyze and Modify**: Read the referenced code block and edit the file to address the feedback using your code editing tools.
4773
2. **Local Validation**: Run the relevant local tests or verification commands to confirm the fix is correct and functional.
@@ -54,13 +80,25 @@ For each validated comment:
5480
```bash
5581
git push
5682
```
57-
5. **Get Commit Hash**: Extract the 7-digit commit SHA (found in the commit command output or via `git rev-parse --short HEAD`).
58-
6. **Post Reply**: Call the MCP tool `add_reply_to_pull_request_comment` with the arguments:
83+
5. **Get Commit Hash**: Extract the 7-digit commit SHA:
84+
```bash
85+
git rev-parse --short HEAD
86+
```
87+
6. **Post Reply** (two options):
88+
89+
**Option A: GitHub CLI (Recommended)**
90+
```bash
91+
gh api repos/bcgov/nr-silva/pulls/<PR_NUMBER>/comments/<COMMENT_ID>/replies \
92+
-f body="Fixed in commit <7-digit-hash>"
93+
```
94+
95+
**Option B: MCP Tool**
96+
Call the `add_reply_to_pull_request_comment` tool with:
5997
* `owner`, `repo`, `pullNumber`
6098
* `commentId`: the numeric ID of the review comment
6199
* `body`: `"Fixed in commit <7-digit-hash>."`
62100

63-
### 5. Final Verification
101+
### 6. Final Verification
64102
* Verify the codebase is clean and regression-free:
65103
* **Check number of changed files**: Count the files modified across all commits.
66104
* **If ≤2 files changed**: Run targeted tests for the affected modules only.
@@ -92,3 +130,34 @@ Alternatively, to verify compilation only (faster):
92130
cd backend
93131
./mvnw clean compile
94132
```
133+
134+
---
135+
136+
## Troubleshooting
137+
138+
### Problem: No comments found when calling the API
139+
**Common causes:**
140+
1. **Wrong PR number**: Verify the PR number from GitHub or use `gh pr view` to confirm the current PR
141+
```bash
142+
gh pr view # Shows current PR number and branch
143+
```
144+
2. **Comments already resolved**: Check GitHub UI to see if all Copilot/reviewer comments are marked as resolved
145+
3. **API permissions**: Ensure GitHub CLI is authenticated:
146+
```bash
147+
gh auth status
148+
```
149+
150+
### Problem: Forgot to fetch comments initially
151+
**Solution:** Always run the fetch and validation step (Step 2-3) FIRST, before analyzing any code:
152+
```bash
153+
# Quick check if PR has any review comments
154+
gh api repos/bcgov/nr-silva/pulls/1380/comments | python3 -c "import json, sys; print(len(json.load(sys.stdin)), 'comment(s)')"
155+
```
156+
This prevents missed reviews and wasted time analyzing code without knowing what needs fixing.
157+
158+
### Problem: Getting 404 on API call
159+
**Typical issue:** Using wrong repository path. Verify with:
160+
```bash
161+
gh repo view # Shows owner/repo path
162+
```
163+
Then use the correct format: `repos/{owner}/{repo}/pulls/{number}/comments`

backend/src/main/java/ca/bc/gov/restapi/results/common/service/impl/AbstractOpeningSearchService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ private void validatePageSize(Pageable pagination) {
247247
int pageSize = pagination.getPageSize();
248248
if (pageSize <= 0) {
249249
throw new ResponseStatusException(
250-
HttpStatus.BAD_REQUEST,
251-
"Page size must be greater than 0, but was: " + pageSize);
250+
HttpStatus.BAD_REQUEST, "Page size must be greater than 0, but was: " + pageSize);
252251
}
253252
if (pageSize > SilvaConstants.MAX_PAGE_SIZE_OPENING_SEARCH) {
254253
throw new MaxPageSizeException(SilvaConstants.MAX_PAGE_SIZE_OPENING_SEARCH);

0 commit comments

Comments
 (0)