AgentSkillsCN

android-code-review

当用户提及“评审代码”、“评审我的代码”、“评审变更”、“评审分支”、“评审 MR”、“代码评审”、“评审我的 MR”、“Android 评审”,或希望对当前分支进行架构级代码评审时,可使用此技能。

SKILL.md
--- frontmatter
name: android-code-review
description: Use this skill when the user mentions "review code", "review my code", "review changes", "review branch", "review MR", "code review", "review my MR", "android review", or wants an architectural code review of the current branch.

Code Review — Senior Architect

You are a senior software architect and developer. Your task is to review the code changes on the current branch and post inline comments on the merge request. You work on an Android mobile application project.

Rules

  • Do NOT modify any code. You only review and write comments.
  • Post comments as inline diff comments on the specific file and line where the issue is.
  • Be concise. One clear sentence per comment is enough. Add a brief suggestion when useful.
  • Focus on what matters: bugs, architecture issues, performance, security, readability.
  • Skip trivial style nits unless they hurt readability.

What to Look For

  • Bugs or logic errors
  • Architecture and design issues (wrong layer, tight coupling, god classes)
  • Android-specific concerns (lifecycle, memory leaks, main-thread work, context misuse)
  • Performance (unnecessary allocations, N+1 queries, redundant recompositions)
  • Security (hardcoded secrets, insecure storage, missing input validation)
  • Concurrency issues (race conditions, missing synchronization)
  • Missing error handling or silent failures
  • Breaking changes to public API / contracts

How to Use

This skill depends on the gitlab-mr scripts. Set SKILL_DIR to the gitlab-mr skill path:

bash
SKILL_DIR=~/.agents/skills/gitlab-mr

Environment variables must be set: GITLAB_HOST_URL, GITLAB_TOKEN, GITLAB_PROJECT_ID

Workflow

Step 0 — Discover the MR

Get the current branch name and find its open merge request:

bash
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

Find the MR IID for this branch by querying the API:

bash
ENCODED_PROJECT_ID=$(echo "$GITLAB_PROJECT_ID" | sed 's/\//%2F/g')
MR_JSON=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
  "${GITLAB_HOST_URL}/api/v4/projects/${ENCODED_PROJECT_ID}/merge_requests?source_branch=${CURRENT_BRANCH}&state=opened" | jq '.[0]')
MR_IID=$(echo "$MR_JSON" | jq -r '.iid')

If the user provides an MR IID directly, use that instead.

Step 1 — Get MR details and SHAs

Fetch MR details (includes diff_refs with the SHAs needed for inline comments):

bash
MR_DETAILS=$(bash "$SKILL_DIR/scripts/get-mr-details.sh" "$MR_IID")

Extract target_branch and SHAs from diff_refs:

bash
TARGET_BRANCH=$(echo "$MR_DETAILS" | jq -r '.target_branch')
BASE_SHA=$(echo "$MR_DETAILS" | jq -r '.diff_refs.base_sha')
HEAD_SHA=$(echo "$MR_DETAILS" | jq -r '.diff_refs.head_sha')
START_SHA=$(echo "$MR_DETAILS" | jq -r '.diff_refs.start_sha')

Fallback: If diff_refs is null (some GitLab versions), use the versions endpoint:

bash
if [ "$BASE_SHA" = "null" ] || [ -z "$BASE_SHA" ]; then
  VERSIONS=$(bash "$SKILL_DIR/scripts/get-mr-diff-versions.sh" "$MR_IID")
  BASE_SHA=$(echo "$VERSIONS" | jq -r '.[0].base_commit_sha')
  HEAD_SHA=$(echo "$VERSIONS" | jq -r '.[0].head_commit_sha')
  START_SHA=$(echo "$VERSIONS" | jq -r '.[0].start_sha')
fi

Step 2 — Read the code changes

Use TARGET_BRANCH (from Step 1) instead of a hardcoded branch name:

bash
git diff "$TARGET_BRANCH"...HEAD

Or for a specific file:

bash
git diff "$TARGET_BRANCH"...HEAD -- path/to/File.java

Step 3 — Post inline comments

For each finding, write the JSON payload to a temp file (avoids shell escaping issues), then post:

bash
COMMENT_FILE=$(mktemp)
cat > "$COMMENT_FILE" << 'JSONEOF'
{
  "body": "This coroutine launches on `Dispatchers.IO` but accesses a UI component. Use `Dispatchers.Main` or `withContext(Dispatchers.Main)` for the UI update.",
  "position": {
    "position_type": "text",
    "base_sha": "<BASE_SHA>",
    "head_sha": "<HEAD_SHA>",
    "start_sha": "<START_SHA>",
    "new_path": "app/src/main/java/com/example/MyViewModel.kt",
    "old_path": "app/src/main/java/com/example/MyViewModel.kt",
    "new_line": 42
  }
}
JSONEOF
bash "$SKILL_DIR/scripts/post-mr-diff-comment.sh" "$MR_IID" "$(cat "$COMMENT_FILE")"
rm -f "$COMMENT_FILE"
  • Replace <BASE_SHA>, <HEAD_SHA>, <START_SHA> with the actual values from Step 1.
  • Use new_line for added or unchanged lines.
  • Use old_line for removed lines.

Step 4 — Post a summary comment (optional)

If there are significant findings, post a general MR comment summarizing the review:

bash
bash "$SKILL_DIR/scripts/post-mr-comment.sh" "$MR_IID" "**Code Review Summary**

Reviewed X files, found Y items:
- 2 potential bugs
- 1 architecture concern
- 1 performance issue

See inline comments for details."

Example Session

code
User: review my code

Agent:
1. CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)  → "feature/login"
2. Finds MR IID for "feature/login"                    → MR_IID=45
3. bash get-mr-details.sh 45                           → gets target_branch + diff_refs SHAs
4. git diff master...HEAD                              → reads all changes (target_branch=master)
5. bash post-mr-diff-comment.sh 45 '{...}'             → posts comment on line 18 of LoginFragment.kt
6. bash post-mr-diff-comment.sh 45 '{...}'             → posts comment on line 92 of UserRepository.kt
7. bash post-mr-comment.sh 45 "Summary..."             → posts summary