Skip to content

Commit 9f51b9d

Browse files
bdsqqqampcode-com
andauthored
feat(action): add diff input and optional PR comment posting (#63)
- add `diff` input to pass `--diff <base>` to the CLI - add `github-token` input for posting findings as PR comments - stale comment cleanup: deletes previous react-doctor comments before posting - tee output to file only when github-token is set (no change for existing users) - add GitHub Actions section to README with input reference table closes #61 Amp-Thread-ID: https://ampcode.com/threads/T-019c7ad9-c09d-713d-a08d-c699637a6846 Co-authored-by: Amp <amp@ampcode.com>
1 parent 79af7ca commit 9f51b9d

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

action.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ inputs:
1414
project:
1515
description: "Workspace project(s) to scan (comma-separated)"
1616
required: false
17+
diff:
18+
description: "Base branch for diff mode (e.g. main). Only files changed vs this branch are scanned."
19+
required: false
20+
github-token:
21+
description: "GitHub token for posting PR comments. When set on pull_request events, findings are posted as a PR comment."
22+
required: false
1723
node-version:
1824
description: "Node.js version to use"
1925
default: "20"
@@ -35,11 +41,19 @@ runs:
3541
INPUT_DIRECTORY: ${{ inputs.directory }}
3642
INPUT_VERBOSE: ${{ inputs.verbose }}
3743
INPUT_PROJECT: ${{ inputs.project }}
44+
INPUT_DIFF: ${{ inputs.diff }}
45+
INPUT_GITHUB_TOKEN: ${{ inputs.github-token }}
3846
run: |
3947
FLAGS=""
4048
if [ "$INPUT_VERBOSE" = "true" ]; then FLAGS="$FLAGS --verbose"; fi
4149
if [ -n "$INPUT_PROJECT" ]; then FLAGS="$FLAGS --project $INPUT_PROJECT"; fi
42-
npx -y react-doctor@latest "$INPUT_DIRECTORY" $FLAGS
50+
if [ -n "$INPUT_DIFF" ]; then FLAGS="$FLAGS --diff $INPUT_DIFF"; fi
51+
52+
if [ -n "$INPUT_GITHUB_TOKEN" ]; then
53+
npx -y react-doctor@latest "$INPUT_DIRECTORY" $FLAGS | tee /tmp/react-doctor-output.txt
54+
else
55+
npx -y react-doctor@latest "$INPUT_DIRECTORY" $FLAGS
56+
fi
4357
4458
- id: score
4559
shell: bash
@@ -48,3 +62,35 @@ runs:
4862
run: |
4963
SCORE=$(npx -y react-doctor@latest "$INPUT_DIRECTORY" --score 2>/dev/null || echo "")
5064
echo "score=$SCORE" >> "$GITHUB_OUTPUT"
65+
66+
- if: ${{ inputs.github-token != '' && github.event_name == 'pull_request' }}
67+
uses: actions/github-script@v7
68+
with:
69+
github-token: ${{ inputs.github-token }}
70+
script: |
71+
const fs = require("fs");
72+
const path = "/tmp/react-doctor-output.txt";
73+
if (!fs.existsSync(path)) return;
74+
const output = fs.readFileSync(path, "utf8").trim();
75+
if (!output) return;
76+
77+
const marker = "<!-- react-doctor -->";
78+
const body = `${marker}\n## 🩺 React Doctor\n\n\`\`\`\n${output}\n\`\`\``;
79+
80+
const { data: comments } = await github.rest.issues.listComments({
81+
...context.repo,
82+
issue_number: context.issue.number,
83+
});
84+
const prev = comments.find((c) => c.body?.startsWith(marker));
85+
if (prev) {
86+
await github.rest.issues.deleteComment({
87+
...context.repo,
88+
comment_id: prev.id,
89+
});
90+
}
91+
92+
await github.rest.issues.createComment({
93+
...context.repo,
94+
issue_number: context.issue.number,
95+
body,
96+
});

packages/react-doctor/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ curl -fsSL https://react.doctor/install-skill.sh | bash
4848

4949
Supports Cursor, Claude Code, Amp Code, Codex, Gemini CLI, OpenCode, Windsurf, and Antigravity.
5050

51+
## GitHub Actions
52+
53+
```yaml
54+
- uses: actions/checkout@v5
55+
with:
56+
fetch-depth: 0 # required for --diff
57+
- uses: millionco/react-doctor@main
58+
with:
59+
diff: main
60+
github-token: ${{ secrets.GITHUB_TOKEN }}
61+
```
62+
63+
| Input | Default | Description |
64+
| -------------- | ------- | ----------------------------------------------------------------------- |
65+
| `directory` | `.` | Project directory to scan |
66+
| `verbose` | `true` | Show file details per rule |
67+
| `project` | | Workspace project(s) to scan (comma-separated) |
68+
| `diff` | | Base branch for diff mode. Only changed files are scanned |
69+
| `github-token` | | When set on `pull_request` events, posts findings as a PR comment |
70+
| `node-version` | `20` | Node.js version to use |
71+
72+
The action outputs a `score` (0–100) you can use in subsequent steps.
73+
5174
## Options
5275

5376
```

0 commit comments

Comments
 (0)