Created
August 4, 2026 04:40
-
-
Save nsdevaraj/e431c92899c2651315db738cfbba3262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # review-pr.sh | |
| # | |
| # Given a GitHub pull request URL, select the matching subfolder of the | |
| # current directory and ask Copilot CLI to review the PR and post inline | |
| # review comments back to the PR on GitHub. | |
| # | |
| # Usage: | |
| # ./review-pr.sh <github-pr-url> | |
| # | |
| # Example: | |
| # ./review-pr.sh https://github.com/lumelinc/InforiverMatrix/pull/13962 | |
| set -euo pipefail | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| # --------------------------------------------------------------------------- | |
| # 1. Validate input | |
| # --------------------------------------------------------------------------- | |
| if [ "$#" -ne 1 ]; then | |
| echo "Usage: $0 <github-pr-url>" >&2 | |
| echo "Example: $0 https://github.com/lumelinc/InforiverMatrix/pull/13962" >&2 | |
| exit 1 | |
| fi | |
| PR_URL="$1" | |
| # Parse: https://github.com/<owner>/<repo>/pull/<number> | |
| if [[ ! "$PR_URL" =~ ^https?://github\.com/([^/]+)/([^/]+)/pull/([0-9]+) ]]; then | |
| echo "ERROR: Not a valid GitHub PR URL: $PR_URL" >&2 | |
| echo "Expected: https://github.com/<owner>/<repo>/pull/<number>" >&2 | |
| exit 1 | |
| fi | |
| OWNER="${BASH_REMATCH[1]}" | |
| REPO="${BASH_REMATCH[2]}" | |
| PR_NUMBER="${BASH_REMATCH[3]}" | |
| # --------------------------------------------------------------------------- | |
| # 2. Select the matching subfolder of the current directory | |
| # --------------------------------------------------------------------------- | |
| REPO_DIR="$SCRIPT_DIR/$REPO" | |
| if [ ! -d "$REPO_DIR/.git" ]; then | |
| echo "ERROR: No git subfolder named '$REPO' found in $SCRIPT_DIR" >&2 | |
| echo "Available subfolders:" >&2 | |
| for d in "$SCRIPT_DIR"/*/; do | |
| [ -d "${d}.git" ] && echo " - $(basename "$d")" >&2 | |
| done | |
| exit 1 | |
| fi | |
| echo "PR URL : $PR_URL" | |
| echo "Owner : $OWNER" | |
| echo "Repo : $REPO" | |
| echo "PR number: $PR_NUMBER" | |
| echo "Subfolder: $REPO_DIR" | |
| echo | |
| # --------------------------------------------------------------------------- | |
| # 3. Ask Copilot to review the PR and post inline comments | |
| # --------------------------------------------------------------------------- | |
| read -r -d '' PROMPT <<EOF || true | |
| Review GitHub pull request #${PR_NUMBER} in the repository ${OWNER}/${REPO}. | |
| Steps: | |
| 1. Fetch the PR metadata and diff using the gh CLI, e.g.: | |
| gh pr view ${PR_NUMBER} --repo ${OWNER}/${REPO} | |
| gh pr diff ${PR_NUMBER} --repo ${OWNER}/${REPO} | |
| 2. Carefully review the diff for bugs, logic errors, security issues, | |
| and clear correctness problems. Focus only on high-confidence issues; | |
| ignore style, formatting, and trivial nits. | |
| 3. Post your findings as INLINE review comments on the PR, anchored to the | |
| specific file paths and line numbers in the diff. Use the gh CLI to create | |
| a pull request review with inline comments, for example: | |
| gh api --method POST \\ | |
| repos/${OWNER}/${REPO}/pulls/${PR_NUMBER}/reviews \\ | |
| -f event=COMMENT \\ | |
| -f body="<overall summary>" \\ | |
| -f 'comments[][path]=<file path>' \\ | |
| -F 'comments[][line]=<line number>' \\ | |
| -f 'comments[][side]=RIGHT' \\ | |
| -f 'comments[][body]=<comment text>' | |
| Add one entry in the comments array per inline comment. Anchor each comment | |
| to a line that is part of the PR diff. | |
| 4. If you find no issues, post a single review comment saying the PR looks good. | |
| Work inside the repository checkout at: ${REPO_DIR} | |
| EOF | |
| echo ">> Launching Copilot to review PR #${PR_NUMBER} ..." | |
| echo | |
| copilot \ | |
| -C "$REPO_DIR" \ | |
| --allow-all-tools \ | |
| --allow-all-urls \ | |
| -p "$PROMPT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment