Skip to content

Commit bfd414b

Browse files
committed
feat: defensive pre-flight checks — non-git, non-GitHub, default branch detection
1 parent 0c67660 commit bfd414b

3 files changed

Lines changed: 71 additions & 28 deletions

File tree

code-review/SKILL.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ Invoke with: `code review`, `code-review`, `review`, or `review my code`
2020
3. **Structural issues > style issues** — ignore naming conventions; focus on logic, security, performance.
2121
4. **Severity levels** — Critical / High / Medium / Low so the user knows what to fix first.
2222

23+
## Pre-flight
24+
25+
1. **Detect context**: Are we in a git repo? Is there a diff to review?
26+
- In git repo with uncommitted changes → review the uncommitted changes
27+
- In git repo on feature branch → review diff against default branch
28+
- User provided a file/snippet → review that directly
29+
- Not in git repo, no file provided → ask user what to review
30+
2. **Detect language/framework** from file extensions and project files to tailor the checklist.
31+
2332
## Checklist
2433

2534
### Security
@@ -53,12 +62,13 @@ Invoke with: `code review`, `code-review`, `review`, or `review my code`
5362

5463
### 1. Get the Diff
5564
```bash
56-
# If reviewing a branch
57-
git diff main...HEAD --stat
58-
git diff main...HEAD
65+
# In a git repo on feature branch
66+
git diff $(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo main)...HEAD
67+
68+
# Or uncommitted changes
69+
git diff
5970

60-
# If reviewing a PR
61-
# Use GitHub API to get PR files
71+
# Or user-provided code — review directly
6272
```
6373

6474
### 2. Review Each File
@@ -69,7 +79,7 @@ Scan every changed file against the checklist above.
6979
## Output Format
7080

7181
```markdown
72-
# Code Review: {branch/PR}
82+
# Code Review: {branch/PR/file}
7383

7484
## Summary
7585
- Changes: {N} files, +{N} -{N} lines

qa/SKILL.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ Invoke with: `qa`, `test this`, `qa check`, or `run qa`
2020
3. **Severity levels** — Critical / High / Medium / Low with a health score
2121
4. **Actionable** — each issue includes steps to reproduce and suggested fix
2222

23+
## Pre-flight
24+
25+
1. **Detect context**:
26+
- In git repo on feature branch → diff-aware mode (read `git diff` against default branch)
27+
- In git repo, no changes → report "nothing to test"
28+
- User provided a URL → URL testing mode
29+
- Not in git repo → ask user what to test
30+
2. **Detect default branch**: `git symbolic-ref refs/remotes/origin/HEAD` or fall back to `main`
31+
2332
## Modes
2433

2534
| Mode | Trigger | What it does |
2635
|------|---------|-------------|
27-
| Diff-aware | `qa` (on feature branch) | Read `git diff main`, test affected areas |
36+
| Diff-aware | `qa` (on feature branch) | Read diff against default branch, test affected areas |
2837
| URL | `qa https://...` | Test the given URL systematically |
2938
| Quick | `qa --quick` | 30-second smoke test: homepage + top 5 pages |
3039
| Full | `qa --full` | Exhaustive exploration, 5-15 minutes |
@@ -34,8 +43,9 @@ Invoke with: `qa`, `test this`, `qa check`, or `run qa`
3443
### 1. Identify What to Test
3544
```bash
3645
# On a feature branch: read the diff
37-
git diff main...HEAD --stat
38-
git diff main...HEAD
46+
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo main)
47+
git diff $DEFAULT...HEAD --stat
48+
git diff $DEFAULT...HEAD
3949

4050
# Identify affected:
4151
# - Routes / endpoints

ship/SKILL.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,66 @@ Invoke with: `ship`, `ship it`, or `ship this`
2020
3. **Stop on failure** — if any step fails, stop and report. Don't improvise fixes.
2121
4. **Speed** — minimum tool calls, fastest completion.
2222

23+
## Pre-flight Checks
24+
25+
Before starting, verify the environment:
26+
27+
1. **Is this a git repo?** Run `git rev-parse --is-inside-work-tree`. If not → stop and report "Not a git repository."
28+
2. **Is there a remote?** Run `git remote -v`. If no remote → stop and report "No git remote configured."
29+
3. **Detect hosting platform** from remote URL:
30+
- `github.com` → use GitHub API for PR
31+
- `gitlab.com` → use GitLab API for MR
32+
- Other → push only, skip PR creation, report "PR skipped: unsupported hosting platform"
33+
2334
## Workflow
2435

2536
### 1. Verify State
2637
```bash
38+
# Confirm in a git repo
39+
git rev-parse --is-inside-work-tree || { echo "❌ Not a git repository."; exit 1; }
40+
2741
# Confirm on a feature branch
2842
BRANCH=$(git branch --show-current)
29-
if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
30-
echo "❌ You're on main. Can't ship. Switch to a feature branch first."
43+
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
44+
if [ "$BRANCH" = "$DEFAULT" ]; then
45+
echo "❌ You're on $DEFAULT. Can't ship. Switch to a feature branch first."
3146
exit 1
3247
fi
3348

3449
# Confirm no uncommitted changes
35-
git status --porcelain
50+
if [ -n "$(git status --porcelain)" ]; then
51+
echo "❌ Uncommitted changes. Commit or stash first."
52+
exit 1
53+
fi
3654
```
3755

38-
### 2. Sync Main
56+
### 2. Sync with default branch
3957
```bash
4058
git fetch origin
41-
git rebase origin/main
59+
git rebase origin/$DEFAULT
4260
# If conflict → stop and report. Don't resolve automatically.
4361
```
4462

4563
### 3. Run Tests (if the repo has them)
46-
```bash
47-
# Detect test framework and run
48-
# npm test / bun test / pytest / go test / cargo test / etc.
49-
# Failure → stop and report
50-
```
64+
Detect and run:
65+
- `package.json` with test script → `npm test` or `bun test`
66+
- `pytest.ini` / `pyproject.toml` / `setup.py``pytest`
67+
- `go.mod``go test ./...`
68+
- `Cargo.toml``cargo test`
69+
- `Makefile` with test target → `make test`
70+
- None found → skip, report "⏭️ no tests detected"
71+
72+
Failure → stop and report.
5173

5274
### 4. Push
5375
```bash
5476
git push origin HEAD
5577
```
5678

57-
### 5. Open PR
58-
Create a PR via GitHub API:
59-
- Title: concise summary of the changes
60-
- Body: auto-generated from commit messages
61-
- Labels: detect from context if possible
62-
- Base: `main`
79+
### 5. Open PR / MR
80+
- **GitHub**: create PR via API. Title from branch name or first commit. Body from commit log.
81+
- **GitLab**: create MR via API.
82+
- **Other**: skip, report push URL only.
6383

6484
### 6. Report
6585

@@ -72,11 +92,13 @@ Create a PR via GitHub API:
7292

7393
| Step | Status |
7494
|------|--------|
75-
| Branch check |`{branch}` |
76-
| Sync main | ✅ / ❌ conflict |
95+
| Git repo | ✅ / ❌ not a repo |
96+
| Branch check |`{branch}` / ❌ on default branch |
97+
| Clean state | ✅ / ❌ uncommitted changes |
98+
| Sync | ✅ / ❌ conflict |
7799
| Tests | ✅ / ⏭️ no tests / ❌ failed |
78100
| Push ||
79-
| PR | ✅ {PR URL} |
101+
| PR/MR | ✅ {URL} / ⏭️ unsupported platform |
80102

81103
## Commits ({N})
82104
- {commit 1}
@@ -92,3 +114,4 @@ Create a PR via GitHub API:
92114
- The entire flow should take no more than 10 tool calls
93115
- Don't add changelog/version bump unless the repo has that convention
94116
- PR opened = done. Don't wait for review.
117+
- If the platform is unsupported for PR, a successful push is still a successful ship.

0 commit comments

Comments
 (0)