agentleFS
opendatahub-ioopendatahub-io/code-review-skills/skills/gitlab-code-review/SKILL.md

gitlab-code-review

Skill1 starsChanged 5 days agoApache-2.0View on GitHub

Perform AI code review on a GitLab merge request. Reviews all commits since the base branch, produces structured JSON feedback with inline comments, and posts results to the GitLab MR (in CI) or displays them locally for preview. Use when asked to review a GitLab merge request, do a GitLab code review, or run ai-review on a GitLab project.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. Stuko0/alice-agent★ 2same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository4 other files it gives its agents.

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. About 0 are common, 10 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use $BASE and $HEAD_REF for all git commands:

    line 57
  2. Distinctive:

    Only review the committed diff between branches: Do NOT run git status, do NOT report on untracked files, and do NOT include uncommitted …

    line 64
  3. Distinctive:

    If no additional instructions were provided above, follow these defaults:

    line 72
  4. Distinctive:

    When referencing coding standards, security norms, best practices, or component-specific behavior, search for and cite the authoritative …

    line 82
  5. Very specific:

    Write your review output as a JSON file at /tmp/ai-review-output.json.

    line 88
  6. Distinctive:

    ONLY comment on lines that appear in the diff (changed or added lines).

    line 115
  7. Distinctive:

    Do NOT comment on unchanged lines.

    line 116
  8. Distinctive:

    Use the line number as it appears in the NEW version of the file.

    line 117
  9. Very specific:

    If there are no inline issues to report, use an empty array [].

    line 126
  10. Very specific:

    When a finding has a small, unambiguous code fix, attach a fix object.

    line 130
  11. Distinctive:

    Keep it small: a few lines, never more than about 20.

    line 145
  12. Distinctive:

    Keep it short (2-4 sentences).

    line 170
  13. Very specific:

    Run the review.py script from this skill's scripts/ directory.

    line 183
  14. Very specific:

    If the script reports a JSON parse error, fix the JSON in /tmp/ai-review-output.json and re-run the command.

    line 200
  15. Very specific:

    If the $SUGGEST_REVIEWERS environment variable is set to "true", run:

    line 205
  16. Very specific:

    If a .git-blame-ignore-revs file exists at the repo root, commits listed in it are excluded from authorship counts, the same way git blame …

    line 215
  17. Distinctive:

    If the script fails, report the error but continue to Step 5.

    line 219
  18. Distinctive:

    After the script completes successfully:

    line 223

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

GitLab Code Review

Perform a structured code review of the current branch's changes and post results to a GitLab merge request (in CI) or display them locally for preview.

Step 1: Fetch Org Review Rules

Fetch the org-wide PR review rules before reviewing: run the fetch block in references/org-rules.md, which runs only when ORG_REVIEW_RULES is true, and apply the fetched file by that file's contract. With the flag off, the default, there is nothing to do. With it on, a missing gh or timeout, a failed mktemp, or a failed fetch degrades as designed: append to the eventual summary "Org review rules from security-config were unavailable: <reason>", citing the captured stderr.

Step 2: Review Code Changes

Review ALL commits in the branch since the base branch. Use git commands to inspect the changes — do NOT access remote APIs (e.g., glab commands), except the org-rules fetch in Step 1.

IMPORTANT: In CI, always use $CI_MERGE_REQUEST_DIFF_BASE_SHA and $CI_COMMIT_SHA to define the diff range. Never use origin/main..HEAD in CI because the checkout may leave HEAD detached at the target branch tip, producing an empty diff. The CI variables point to the exact commits that define the MR diff. Fall back to origin/main..HEAD only for local runs.

# Set the diff range — CI variables are authoritative when present
if [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ] && [ -n "$CI_COMMIT_SHA" ]; then
  BASE="$CI_MERGE_REQUEST_DIFF_BASE_SHA"
  HEAD_REF="$CI_COMMIT_SHA"
else
  BASE="origin/main"  # adjust if default branch differs (e.g., master, develop)
  HEAD_REF="HEAD"
fi

Use $BASE and $HEAD_REF for all git commands:

git log --oneline ${BASE}..${HEAD_REF}
git diff ${BASE}..${HEAD_REF}

Only review the committed diff between branches. Do NOT run git status, do NOT report on untracked files, and do NOT include uncommitted working-tree changes in your review.

Review Guidelines

$ARGUMENTS

If no additional instructions were provided above, follow these defaults:

Provide constructive feedback that helps maintain code quality and follows project best practices. Be selective and focused: only comment on issues that genuinely matter. Do not comment for the sake of commenting. If the code is well-written and follows best practices, it is perfectly acceptable to return zero inline comments. Prioritize critical and major issues over minor stylistic preferences. Avoid repeating the same type of feedback across multiple locations — one representative comment is sufficient.

When referencing coding standards, security norms, best practices, or component-specific behavior, search for and cite the authoritative source (official documentation, RFCs, upstream references) to back up the claim.

Step 3: Produce Review JSON

Write your review output as a JSON file at /tmp/ai-review-output.json.

The JSON must be a valid object matching this schema exactly:

{
  "summary": "Brief overall assessment of the changes (2-4 sentences, markdown allowed inside this string)",
  "positive_aspects": ["List of good practices and well-implemented features"],
  "inline_comments": [
    {
      "file": "path/to/file (relative to repo root)",
      "line": 42,
      "severity": "critical|major|minor|suggestion",
      "comment": "Description of the issue and suggested fix (markdown allowed inside this string)",
      "fix": {
        "start_line": 42,
        "end_line": 42,
        "code": "Optional: exact replacement for lines start_line..end_line (whole lines, new file numbering)"
      }
    }
  ],
  "fix_prompt": "Optional: a copy-paste prompt to fix all issues found. Omit this field if there are no actionable fixes."
}

Inline comments rules

  • ONLY comment on lines that appear in the diff (changed or added lines). Do NOT comment on unchanged lines.
  • Use the line number as it appears in the NEW version of the file.
  • file must be the path relative to the repository root (e.g., src/main.py, not /workspace/src/main.py).
  • Severity levels:
    • critical: Security vulnerabilities, build-breaking changes
    • major: Significant logic errors, pattern violations
    • minor: Style issues, minor improvements
    • suggestion: Optional improvements for code quality
  • Each comment should be self-contained and actionable.
  • If there are no inline issues to report, use an empty array [].

Applicable fix rules (fix)

When a finding has a small, unambiguous code fix, attach a fix object. The posting script turns it into a GitLab suggestion that the MR author applies with one click, so the replacement must be exact.

  • fix is optional. Omit it for design-level findings, findings that need changes in several places, or whenever you are not certain the replacement is complete and correct in context.
  • start_line and end_line are inclusive line numbers in the NEW version of the file, and line must fall inside that range. Use start_line == end_line == line for a one-line replacement.
  • code replaces the whole lines start_line..end_line. Copy the exact indentation (tabs vs spaces) from the file. Do not include diff markers (+/-), line numbers, or a code fence. Do not include a trailing newline.
  • An empty code string deletes the range.
  • Keep it small: a few lines, never more than about 20. The script drops ranges above 50 lines, ranges outside the file, and replacements identical to the current code, and posts the comment as prose instead.
  • The comment text must still explain the change; the suggestion block is appended after it, not instead of it.

Example: the diff adds an else: at line 74 that should only run when the wheel is absent from the target set.

{
  "file": "src/pulp_qualify_wheels.py",
  "line": 74,
  "severity": "major",
  "comment": "Only record a QA failure when the wheel is also absent from production; otherwise an already-published dependency blocks its promotion unit.",
  "fix": {
    "start_line": 74,
    "end_line": 74,
    "code": "            elif wheel not in target_wheel_set:"
  }
}

Summary rules

  • Keep it short (2-4 sentences). The inline comments carry the detail.
  • Mention the overall quality and any critical concerns.

Positive aspects rules

  • List 1-3 things done well. If nothing stands out, use an empty array [].

Fix prompt rules

  • Omit this field entirely if there are no actionable fixes.

Step 4: Post Results

Run the review.py script from this skill's scripts/ directory. Execute it directly (not via python) to invoke uv via the shebang:

./scripts/review.py post /tmp/ai-review-output.json

The script auto-detects the platform (GitLab CI or local). GitHub pull requests go through the repo's GitHub Action (which runs the github-code-review skill) instead, not this skill. The script handles:

  • JSON validation and chill-mode filtering (controlled by $CHILL_MODE env var)
  • Rendering fix objects as applicable GitLab suggestions (disabled when $INLINE_FIXES is false)
  • Deduplication against previous reviews (skips comments on unchanged code)
  • Deleting unresolved AI review discussions without human responses on the MR (GitLab)
  • Posting inline comments and a summary note to the MR (GitLab)
  • Falling back to formatted terminal display when no CI platform is detected

If the script reports a JSON parse error, fix the JSON in /tmp/ai-review-output.json and re-run the command.

Step 4.5: Suggest Reviewers (Optional)

If the $SUGGEST_REVIEWERS environment variable is set to "true", run:

./scripts/review.py suggest-reviewers

This identifies potential reviewers based on git history of the modified files and posts a separate comment on the MR tagging them. It uses the GitLab GraphQL API to resolve git commit authors to GitLab usernames.

If a .git-blame-ignore-revs file exists at the repo root, commits listed in it are excluded from authorship counts, the same way git blame --ignore-revs-file would treat them.

If the script fails, report the error but continue to Step 5.

Step 5: Report Results

After the script completes successfully:

  • CI: Confirm the review was posted to the merge request
  • Local: The script displays results directly in the terminal
  • Errors: Report any failures from the script output

Gotchas

  • Line numbers in inline_comments must reference the NEW file version, not the old one; using old-side line numbers causes comments to land on the wrong line in GitLab.
  • A fix replaces whole lines. Partial-line edits, wrong indentation, or a range that does not contain line produce a suggestion that breaks the file when applied, or get dropped by the script.
  • The JSON output must be strict JSON (no trailing commas, no comments). Invalid JSON will cause the posting script to fail.
  • Running git status or reviewing uncommitted changes will produce false findings that are not part of the MR diff.

Environment Variables

The Python script reads these from the environment. In GitLab CI, most are set automatically — no manual configuration needed.

GitLab

VariableRequired forDefaultDescription
GITLAB_API_TOKENCI/MR—GitLab Personal Access Token
CI_SERVER_URL—https://gitlab.comGitLab server URL
CI_PROJECT_IDCI/MR—GitLab project ID
CI_MERGE_REQUEST_IIDCI/MR—Merge request IID
CI_MERGE_REQUEST_DIFF_BASE_SHACI/MR—Base SHA for diff positioning
CI_COMMIT_SHACI/MR—Head commit SHA
CI_PROJECT_PATHsuggest-reviewers—Full project path for GraphQL queries
CI_JOB_NAME—ai-reviewJob name for summary footer
CI_JOB_URL—#Job URL for summary footer
AGENT_MODEL——Model shown in the summary footer (set by agentic-ci)
AGENT_REASONING_EFFORT——Reasoning effort shown in the summary footer (set by agentic-ci)

Common

VariableRequired forDefaultDescription
CHILL_MODE—trueFilter out suggestion-level comments
INLINE_FIXES—trueRender fix objects as applicable GitLab suggestions
VERBOSE—falseShow detailed API error responses
SUGGEST_REVIEWERS—falseSuggest reviewers based on git history
ORG_REVIEW_RULESOrg rulesfalseOpt in to the org-wide PR review rules: true fetches and applies them
GH_TOKENOrg rules fetch—Fine-grained read-only token scoped to security-config; local runs use your authenticated gh

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.