Skip to content

Instantly share code, notes, and snippets.

@dogwood008
Created November 21, 2025 23:58
Show Gist options
  • Select an option

  • Save dogwood008/5193fc8d73d7d535eb8d6663a4e55505 to your computer and use it in GitHub Desktop.

Select an option

Save dogwood008/5193fc8d73d7d535eb8d6663a4e55505 to your computer and use it in GitHub Desktop.
GitHubのPRに寄せられたレビューコメントが妥当か検証して、妥当なら修正&コミットしてコメントを閉じる を逐次実行するAIアシスタントへの命令
description argument-hint
Review AI comments on a GitHub PR, apply fixes when appropriate, resolve threads, and notify on Ubuntu
REPO="<owner/repo|.>" PR_NUMBER=<number> [MODE="<apply|dry-run>"]

You are an autonomous coding agent working against a GitHub repository.

Inputs:

  • REPO: $REPO
    • If ".", assume the current working directory is the target repo.
    • Otherwise clone the repository using existing credentials (gh auth or GITHUB_TOKEN).
  • PR_NUMBER: $PR_NUMBER
  • MODE: $MODE
    • Default is "apply".
    • When MODE is "dry-run": do not modify files, commit, push, or resolve review threads.

Task:

  1. Prepare the repository and PR branch.

    • If $REPO is not ".", clone it as needed.
    • Check out the PR branch for PR #$PR_NUMBER. Prefer gh pr checkout $PR_NUMBER.
  2. Fetch PR metadata and review comments.

    • Retrieve PR #$PR_NUMBER.
    • List all review threads and their comments.
  3. For each review thread:

    • Skip the thread entirely if it is already marked as resolved.
    • Extract referenced file path, line numbers, diff hunk, etc.
    • Because reviewers may reference outdated commits, file paths and line numbers may not match HEAD.
    • Attempt to locate corresponding code via:
      • File path or rename detection
      • Diff hunk context search
      • Fuzzy/text search
    • If the location cannot be reliably determined, classify the comment as obsolete.
  4. Determine whether the unresolved comment is appropriate:

    • Appropriate: real bug, correctness, safety, style-consistency, performance issue, or clear improvement.
    • Inappropriate: outdated, incorrect, conflicting with conventions, or unsafe.
  5. If MODE is "dry-run":

    • Do not change files, commit, push, or resolve threads.
    • Output classification and intended actions.
    • Summarize and stop.
  6. If MODE is "apply":

    • Strict rule: “1 review thread = 1 commit”.
      Do NOT merge fixes across multiple threads.

    • For each unresolved & appropriate thread:

      • Apply the minimal fix.

      • Run tests or linters if reasonable.

      • Stage only the changes related to this thread.

        Strict Commit Message Policy

        • 1行目: 修正内容を簡潔に記す
        • 2行目: 空行
        • 3行目: 該当レビューコメントの GitHub パーマリンク URL

        Example:

        Fix incorrect null check
        
        
        https://github.com/<owner>/<repo>/pull/<pr>/#discussion_r123456789
        

        Commit Timezone Policy (NEW)

        Before committing, Codex MUST set:

        export GIT_AUTHOR_DATE="$(date -R --date='TZ=\"Asia/Tokyo\" now')"
        export GIT_COMMITTER_DATE="$(date -R --date='TZ=\"Asia/Tokyo\" now')"
        

        or equivalently ensure both timestamps use UTC+9 (JST).
        All commits must have timestamps in UTC+9.

      • Create exactly one commit for this thread.

      • Push commit if appropriate.

      • Resolve the review thread via GitHub API or gh CLI.

      • Prefix all replies with [Codex].
        Example:
        [Codex] Addressed via commit <sha>.

    • For each unresolved & inappropriate/obsolete thread:

      • Do not modify code.
      • Resolve the thread.
      • Reply with [Codex] prefix:
        [Codex] This comment refers to outdated code and no longer applies.
  7. After all threads are processed:

    • Ensure a clean working tree.
    • Optionally leave a PR summary comment (prefixed with [Codex]):
      • Threads processed
      • Number of commits (1 per thread)
      • Threads resolved without changes
  8. Ubuntu completion notification:

    • If MODE is apply:
      • Execute canberra-gtk-play --id=complete.
      • If unavailable, print a fallback note.

Avoid unnecessary force-push. Always keep changes minimal, localized to each thread, and safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment