Skip to content

Commit 3d3c24d

Browse files
fix: cleanup (#15)
1 parent 4ed98d3 commit 3d3c24d

1 file changed

Lines changed: 72 additions & 84 deletions

File tree

action.yml

Lines changed: 72 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ runs:
3030
echo "$HOME/.local/bin" >> $GITHUB_PATH
3131
"$HOME/.local/bin/droid" --version
3232
33-
- name: Check and fill PR description if needed
33+
- name: Auto-generate PR description on '@droid fill'
3434
shell: bash
3535
env:
3636
FACTORY_API_KEY: ${{ inputs.factory-api-key }}
@@ -64,10 +64,17 @@ runs:
6464
cat > pr_description_prompt.txt << EOF
6565
Generate a comprehensive pull request description for PR #${{ inputs.pr-number }}.
6666
67-
First, use the Web Fetch tool to get the full PR context from:
68-
https://github.com/${{ github.repository }}/pull/${{ inputs.pr-number }}
67+
Procedure:
68+
- Get PR metadata (title & description): gh pr view ${{ inputs.pr-number }} --repo ${{ github.repository }} --json title,body
69+
- Get existing comments: gh pr view --json comments
70+
- Get diff: gh pr diff
71+
- Get changed files with patches to compute inline positions: gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --paginate --jq '.[] | {filename,patch}'
6972
70-
This will provide you with the PR title, diff, changed files, and commit messages.
73+
Use the PR metadata (title/body) as additional context:
74+
- If the existing description includes notes/context, use it to inform your writeup
75+
- Do not copy any placeholder tokens (e.g., "@droid fill") into the final output
76+
77+
This will help you understand the code changes in detail.
7178
7279
$(if [ -n "$PR_TEMPLATE" ]; then
7380
echo "YOUR TASK: Fill out the following PR template based on the code changes."
@@ -131,90 +138,71 @@ runs:
131138
set -euo pipefail
132139
133140
cat > prompt.txt << 'EOF'
134-
You are an automated code review system for PR #${{ inputs.pr-number }}.
135-
136-
## STEP 1: FETCH PR DATA
137-
Use Web Fetch: https://github.com/${{ github.repository }}/pull/${{ inputs.pr-number }}
138-
139-
## STEP 2: IDENTIFY ALL BUGS IN ONE PASS
140-
141-
Scan the ENTIRE diff and identify ALL issues now - don't save any for future runs.
142-
143-
**Focus on:**
144-
- Logic errors: unreachable code, missing break/return, off-by-one errors
145-
- Async issues: missing await, unhandled promises
146-
- Safety: null dereferences, resource leaks, injections
147-
- Type errors: wrong operators (===/==, &&/||), type coercion issues
148-
149-
**Skip:** style, naming, architecture, performance, test coverage
150-
151-
## STEP 3: LINE SELECTION
141+
You are running automated code review in a GitHub Actions runner. The gh CLI is available and authenticated via GH_TOKEN.
152142
153-
**Critical:** Use GitHub's diff line numbers instead of manual position math.
154-
- For added/changed code, take the number shown on the RIGHT side of the diff (`side: "RIGHT"`).
155-
- For removed code, use the LEFT column (`side: "LEFT"`).
156-
- Never include a `position` field when using line-based payloads.
157-
158-
For multi-line feedback you must capture the first and last HEAD line numbers in the span. These become `start_line` and `line` with matching sides (usually `"RIGHT"` for new code).
159-
160-
**Before submitting:** Verify the text at your calculated position matches the line to replace
161-
162-
## STEP 4: FORMAT COMMENTS
163-
164-
Structure: Issue → Impact → (optional) Context.
165-
Do NOT include commit suggestions or use fenced suggestion blocks.
166-
No emojis or decorative formatting - be direct and professional.
167-
168-
Example: "Missing await on async call. This returns a Promise instead of the data, causing undefined behavior downstream."
169-
170-
## STEP 5: SUBMIT REVIEW
171-
172-
**⚠️ CRITICAL: Use ONLY inline comments on specific lines. NO summaries, general comments, or commit suggestions.**
143+
Context:
144+
- Repo: ${{ github.repository }}
145+
- PR Number: ${{ github.event.pull_request.number }}
146+
- PR Head SHA: ${{ github.event.pull_request.head.sha }}
147+
- PR Base SHA: ${{ github.event.pull_request.base.sha }}
173148
174-
Submit inline comments via API:
175-
```bash
176-
curl -X POST \
177-
-H "Authorization: Bearer $GH_TOKEN" \
178-
-H "Accept: application/vnd.github.v3+json" \
179-
https://api.github.com/repos/${{ github.repository }}/pulls/${{ inputs.pr-number }}/reviews \
180-
-d '{
181-
"event": "COMMENT",
182-
"comments": [{
183-
"path": "file.js",
184-
"line": 42, // HEAD line number from the RIGHT column of the diff
185-
"side": "RIGHT",
186-
"body": "Describe the issue and its impact. Provide guidance in prose only."
187-
}]
188-
}'
189-
```
190-
191-
Multi-line requires line ranges:
192-
```json
193-
{
194-
"path": "file.js",
195-
"start_line": 40,
196-
"line": 43,
197-
"start_side": "RIGHT",
198-
"side": "RIGHT",
199-
"body": "Issue spans multiple lines. Explain the problem and recommend changes without suggestion blocks."
200-
}
201-
```
202-
(Do not mix `position` with line-based fields. Use `"LEFT"` sides when commenting on removed lines.)
203-
Note: Keep feedback in plain text; do not embed suggestion blocks or code fences.
204-
205-
## CONSTRAINTS
149+
Objectives:
150+
1) Re-check existing review comments and reply resolved when addressed.
151+
2) Review the current PR diff and flag only clear, high-severity issues.
152+
3) Leave very short inline comments (1-2 sentences) on changed lines only and a brief summary at the end.
206153
207-
**Comment Rules:**
208-
- ONLY inline comments attached to specific line numbers
209-
- NO general PR comments like "I've completed the review" or "Here's what I found"
210-
- NO commit suggestions or fenced suggestion blocks
154+
Procedure:
155+
- Get existing comments: gh pr view --json comments
156+
- Get diff: gh pr diff
157+
- Get changed files with patches to compute inline positions: gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --paginate --jq '.[] | {filename,patch}'
158+
- Compute exact inline anchors for each issue (file path + diff position). Comments MUST be placed inline on the changed line in the diff, not as top-level comments.
159+
- Detect prior top-level "no issues" style comments authored by this bot (match bodies like: "no issues", "No issues found", "LGTM"; include earlier emoji-prefixed variants if present).
160+
- If CURRENT run finds issues and any prior "no issues" comments exist:
161+
- Prefer to remove them to avoid confusion:
162+
- Try deleting top-level issue comments via: gh api -X DELETE repos/${{ github.repository }}/issues/comments/<comment_id>
163+
- If deletion isn't possible, minimize them via GraphQL (minimizeComment) or edit to prefix "[Superseded by new findings]".
164+
- If neither delete nor minimize is possible, reply to that comment: "Superseded: issues were found in newer commits".
165+
- If a previously reported issue appears fixed by nearby changes, reply: This issue appears to be resolved by the recent changes
211166
212-
**Review Rules:**
213-
- NEVER repeat comments from previous review runs
214-
- Review ALL issues in a SINGLE run
215-
- Use event: "COMMENT" only (never APPROVE/REQUEST_CHANGES)
216-
- Only comment on modified lines in the diff
217-
- Only suggest fixes when 100% confident, expressed in prose rather than suggestion blocks
167+
- Analysis scope (broad but precise):
168+
- Correctness: boundary/off-by-one error.
169+
- Robustness & validation: missing input validation.
170+
- API/contract misuse: wrong parameter order.
171+
- Concurrency & async: race condition due to shared mutable state.
172+
- Performance (evidence-based): N+1 queries.
173+
- Resource management: unclosed file handle.
174+
- Dead/unreachable code that affects behavior.
175+
- Regression risks: breaking existing behavior or tests.
176+
- Accuracy gates:
177+
- Base findings on the current diff and minimal repo context available via gh; avoid speculation.
178+
- Prioritize high-severity/high-confidence; cap at 10 comments.
179+
- If confidence is low, ask a clarifying question rather than asserting an issue.
180+
- Do not flag purely stylistic or preference-only concerns.
181+
- Deduplication policy:
182+
- Never repeat or re-raise an issue previously highlighted by this bot on this PR, regardless of whether the thread is marked resolved or unresolved.
183+
- Do not create a new comment for a previously reported issue; if needed, reply in the existing thread with a brief status update (e.g., "Resolved ...") or skip.
184+
185+
Commenting rules:
186+
- Max 10 inline comments total; prioritize the most critical issues
187+
- One issue per comment; place on the exact changed line
188+
- All issue comments MUST be inline (anchored to a file and line/position in the PR diff)
189+
- Natural tone, specific and actionable; do not mention automated or high-confidence
190+
- Tone: write like a junior developer who defers to the PR author; be polite and tentative, avoid authoritative language, and prefer concise, respectful phrasing.
191+
- Confidence: for each potential issue, internally assess confidence as High/Medium/Low.
192+
- Low confidence: phrase the comment as a question (e.g., "I noticed the code does X — did you mean to Y?") and keep it brief.
193+
- Medium/High confidence: state the issue directly and concretely.
194+
- False positives are very undesirable: only surface an issue when you are fairly confident it is valid; when uncertain, prefer a single clarifying question over a definitive claim.
195+
- Only propose an exact code change (e.g., a concrete patch/suggestion) when you are absolutely certain the change is correct and safe; otherwise do not suggest a code change—only describe the issue succinctly.
196+
- No speculative or stylistic suggestions; focus strictly on definitive fixes to high-severity issues.
197+
198+
Submission:
199+
- If there are NO issues to report and an existing top-level comment indicating "no issues" already exists (e.g., "no issues", "No issues found", "LGTM"), do NOT submit another comment. Skip submission to avoid redundancy.
200+
- If there are NO issues to report and NO prior "no issues" comment exists, submit one brief summary comment noting no issues.
201+
- If there ARE issues to report and a prior "no issues" comment exists, ensure that prior comment is deleted/minimized/marked as superseded before submitting the new review.
202+
- If there ARE issues to report, submit ONE review containing ONLY inline comments plus an optional concise summary body. Use the GitHub Reviews API to ensure comments are inline:
203+
- Build a JSON array of comments like: [{ "path": "<file>", "position": <diff_position>, "body": "..." }]
204+
- Submit via: gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews -f event=COMMENT -f body="$SUMMARY" -f comments='[$COMMENTS_JSON]'
205+
- Do NOT use: gh pr review --approve or --request-changes
218206
EOF
219207
220208
echo "Running code review analysis..."

0 commit comments

Comments
 (0)