mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-08-01 20:51:00 -07:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52860fd53a | |||
| 947eff6a05 | |||
| e279fb7917 | |||
| 388af256d5 | |||
| c3b88a61b1 | |||
| 2e85d48bdc | |||
| d7bf0c3a13 | |||
| 7bde726067 | |||
| 6d6fc9dcf3 | |||
| 86080cc72b | |||
| e49430f744 |
@@ -1,190 +1,202 @@
|
||||
#!/bin/bash
|
||||
|
||||
notify() {
|
||||
local title="$1"
|
||||
local message="$2"
|
||||
local pr="$3"
|
||||
local title="${1}"
|
||||
local message="${2}"
|
||||
local pr="${3}"
|
||||
# Terminal escape sequence
|
||||
printf "\e]9;%s | PR #%s | %s\a" "$title" "$pr" "$message"
|
||||
printf "\e]9;%s | PR #%s | %s\a" "${title}" "${pr}" "${message}"
|
||||
# Native macOS notification
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
osascript -e "display notification \"$message\" with title \"$title\" subtitle \"PR #$pr\""
|
||||
OS_TYPE=$(uname)
|
||||
if [[ "${OS_TYPE}" == "Darwin" ]]; then
|
||||
osascript -e "display notification \"${message}\" with title \"${title}\" subtitle \"PR #${pr}\""
|
||||
fi
|
||||
}
|
||||
|
||||
pr_number=$1
|
||||
if [[ -z "$pr_number" ]]; then
|
||||
pr_number="${1}"
|
||||
if [[ -z "${pr_number}" ]]; then
|
||||
echo "Usage: async-review <pr_number>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
base_dir=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||
if [[ -z "$base_dir" ]]; then
|
||||
if [[ -z "${base_dir}" ]]; then
|
||||
echo "❌ Must be run from within a git repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Use the repository's local .gemini/tmp directory for ephemeral worktrees and logs
|
||||
pr_dir="$base_dir/.gemini/tmp/async-reviews/pr-$pr_number"
|
||||
target_dir="$pr_dir/worktree"
|
||||
log_dir="$pr_dir/logs"
|
||||
pr_dir="${base_dir}/.gemini/tmp/async-reviews/pr-${pr_number}"
|
||||
target_dir="${pr_dir}/worktree"
|
||||
log_dir="${pr_dir}/logs"
|
||||
|
||||
cd "$base_dir" || exit 1
|
||||
cd "${base_dir}" || exit 1
|
||||
|
||||
mkdir -p "$log_dir"
|
||||
rm -f "$log_dir/setup.exit" "$log_dir/final-assessment.exit" "$log_dir/final-assessment.md"
|
||||
mkdir -p "${log_dir}"
|
||||
rm -f "${log_dir}/setup.exit" "${log_dir}/final-assessment.exit" "${log_dir}/final-assessment.md"
|
||||
|
||||
echo "🧹 Cleaning up previous worktree if it exists..." | tee -a "$log_dir/setup.log"
|
||||
git worktree remove -f "$target_dir" >> "$log_dir/setup.log" 2>&1 || true
|
||||
git branch -D "gemini-async-pr-$pr_number" >> "$log_dir/setup.log" 2>&1 || true
|
||||
git worktree prune >> "$log_dir/setup.log" 2>&1 || true
|
||||
echo "🧹 Cleaning up previous worktree if it exists..." | tee -a "${log_dir}/setup.log"
|
||||
git worktree remove -f "${target_dir}" >> "${log_dir}/setup.log" 2>&1 || true
|
||||
git branch -D "gemini-async-pr-${pr_number}" >> "${log_dir}/setup.log" 2>&1 || true
|
||||
git worktree prune >> "${log_dir}/setup.log" 2>&1 || true
|
||||
|
||||
echo "📡 Fetching PR #$pr_number..." | tee -a "$log_dir/setup.log"
|
||||
if ! git fetch origin -f "pull/$pr_number/head:gemini-async-pr-$pr_number" >> "$log_dir/setup.log" 2>&1; then
|
||||
echo 1 > "$log_dir/setup.exit"
|
||||
echo "❌ Fetch failed. Check $log_dir/setup.log"
|
||||
notify "Async Review Failed" "Fetch failed." "$pr_number"
|
||||
echo "📡 Fetching PR #${pr_number}..." | tee -a "${log_dir}/setup.log"
|
||||
if ! git fetch origin -f "pull/${pr_number}/head:gemini-async-pr-${pr_number}" >> "${log_dir}/setup.log" 2>&1; then
|
||||
echo 1 > "${log_dir}/setup.exit"
|
||||
echo "❌ Fetch failed. Check ${log_dir}/setup.log"
|
||||
notify "Async Review Failed" "Fetch failed." "${pr_number}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d "$target_dir" ]]; then
|
||||
echo "🧹 Pruning missing worktrees..." | tee -a "$log_dir/setup.log"
|
||||
git worktree prune >> "$log_dir/setup.log" 2>&1
|
||||
echo "🌿 Creating worktree in $target_dir..." | tee -a "$log_dir/setup.log"
|
||||
if ! git worktree add "$target_dir" "gemini-async-pr-$pr_number" >> "$log_dir/setup.log" 2>&1; then
|
||||
echo 1 > "$log_dir/setup.exit"
|
||||
echo "❌ Worktree creation failed. Check $log_dir/setup.log"
|
||||
notify "Async Review Failed" "Worktree creation failed." "$pr_number"
|
||||
if [[ ! -d "${target_dir}" ]]; then
|
||||
echo "🧹 Pruning missing worktrees..." | tee -a "${log_dir}/setup.log"
|
||||
git worktree prune >> "${log_dir}/setup.log" 2>&1
|
||||
echo "🌿 Creating worktree in ${target_dir}..." | tee -a "${log_dir}/setup.log"
|
||||
if ! git worktree add "${target_dir}" "gemini-async-pr-${pr_number}" >> "${log_dir}/setup.log" 2>&1; then
|
||||
echo 1 > "${log_dir}/setup.exit"
|
||||
echo "❌ Worktree creation failed. Check ${log_dir}/setup.log"
|
||||
notify "Async Review Failed" "Worktree creation failed." "${pr_number}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "🌿 Worktree already exists." | tee -a "$log_dir/setup.log"
|
||||
echo "🌿 Worktree already exists." | tee -a "${log_dir}/setup.log"
|
||||
fi
|
||||
echo 0 > "$log_dir/setup.exit"
|
||||
echo 0 > "${log_dir}/setup.exit"
|
||||
|
||||
cd "$target_dir" || exit 1
|
||||
cd "${target_dir}" || exit 1
|
||||
|
||||
echo "🚀 Launching background tasks. Logs saving to: $log_dir"
|
||||
echo "🚀 Launching background tasks. Logs saving to: ${log_dir}"
|
||||
|
||||
echo " ↳ [1/5] Grabbing PR diff..."
|
||||
rm -f "$log_dir/pr-diff.exit"
|
||||
{ gh pr diff "$pr_number" > "$log_dir/pr-diff.diff" 2>&1; echo $? > "$log_dir/pr-diff.exit"; } &
|
||||
rm -f "${log_dir}/pr-diff.exit"
|
||||
{ gh pr diff "${pr_number}" > "${log_dir}/pr-diff.diff" 2>&1; echo $? > "${log_dir}/pr-diff.exit"; } &
|
||||
|
||||
echo " ↳ [2/5] Starting build and lint..."
|
||||
rm -f "$log_dir/build-and-lint.exit"
|
||||
{ { npm run clean && npm ci && npm run format && npm run build && npm run lint:ci && npm run typecheck; } > "$log_dir/build-and-lint.log" 2>&1; echo $? > "$log_dir/build-and-lint.exit"; } &
|
||||
rm -f "${log_dir}/build-and-lint.exit"
|
||||
{ { npm run clean && npm ci && npm run format && npm run build && npm run lint:ci && npm run typecheck; } > "${log_dir}/build-and-lint.log" 2>&1; echo $? > "${log_dir}/build-and-lint.exit"; } &
|
||||
|
||||
# Dynamically resolve gemini binary (fallback to your nightly path)
|
||||
GEMINI_CMD=$(which gemini || echo "$HOME/.gcli/nightly/node_modules/.bin/gemini")
|
||||
POLICY_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/policy.toml"
|
||||
GEMINI_CMD=$(command -v gemini || echo "${HOME}/.gcli/nightly/node_modules/.bin/gemini")
|
||||
BASH_SOURCE_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
POLICY_PATH="$(cd "${BASH_SOURCE_DIR}/.." && pwd)/policy.toml"
|
||||
|
||||
echo " ↳ [3/5] Starting Gemini code review..."
|
||||
rm -f "$log_dir/review.exit"
|
||||
{ "$GEMINI_CMD" --policy "$POLICY_PATH" -p "/review-frontend $pr_number" > "$log_dir/review.md" 2>&1; echo $? > "$log_dir/review.exit"; } &
|
||||
rm -f "${log_dir}/review.exit"
|
||||
{ "${GEMINI_CMD}" --policy "${POLICY_PATH}" -p "/review-frontend ${pr_number}" > "${log_dir}/review.md" 2>&1; echo $? > "${log_dir}/review.exit"; } &
|
||||
|
||||
echo " ↳ [4/5] Starting automated tests (waiting for build and lint)..."
|
||||
rm -f "$log_dir/npm-test.exit"
|
||||
rm -f "${log_dir}/npm-test.exit"
|
||||
{
|
||||
while [ ! -f "$log_dir/build-and-lint.exit" ]; do sleep 1; done
|
||||
if [ "$(cat "$log_dir/build-and-lint.exit")" == "0" ]; then
|
||||
gh pr checks "$pr_number" > "$log_dir/ci-checks.log" 2>&1
|
||||
while [[ ! -f "${log_dir}/build-and-lint.exit" ]]; do sleep 1; done
|
||||
BUILD_LINT_EXIT_VAL=$(cat "${log_dir}/build-and-lint.exit")
|
||||
if [[ "${BUILD_LINT_EXIT_VAL}" == "0" ]]; then
|
||||
gh pr checks "${pr_number}" > "${log_dir}/ci-checks.log" 2>&1
|
||||
ci_status=$?
|
||||
|
||||
if [ "$ci_status" -eq 0 ]; then
|
||||
echo "CI checks passed. Skipping local npm tests." > "$log_dir/npm-test.log"
|
||||
echo 0 > "$log_dir/npm-test.exit"
|
||||
elif [ "$ci_status" -eq 8 ]; then
|
||||
echo "CI checks are still pending. Skipping local npm tests to avoid duplicate work. Please check GitHub for final results." > "$log_dir/npm-test.log"
|
||||
echo 0 > "$log_dir/npm-test.exit"
|
||||
if [[ "${ci_status}" -eq 0 ]]; then
|
||||
echo "CI checks passed. Skipping local npm tests." > "${log_dir}/npm-test.log"
|
||||
echo 0 > "${log_dir}/npm-test.exit"
|
||||
elif [[ "${ci_status}" -eq 8 ]]; then
|
||||
echo "CI checks are still pending. Skipping local npm tests to avoid duplicate work. Please check GitHub for final results." > "${log_dir}/npm-test.log"
|
||||
echo 0 > "${log_dir}/npm-test.exit"
|
||||
else
|
||||
echo "CI checks failed. Failing checks:" > "$log_dir/npm-test.log"
|
||||
gh pr checks "$pr_number" --json name,bucket -q '.[] | select(.bucket=="fail") | .name' >> "$log_dir/npm-test.log" 2>&1
|
||||
echo "CI checks failed. Failing checks:" > "${log_dir}/npm-test.log"
|
||||
gh pr checks "${pr_number}" --json name,bucket -q '.[] | select(.bucket=="fail") | .name' >> "${log_dir}/npm-test.log" 2>&1
|
||||
|
||||
echo "Attempting to extract failing test files from CI logs..." >> "$log_dir/npm-test.log"
|
||||
pr_branch=$(gh pr view "$pr_number" --json headRefName -q '.headRefName' 2>/dev/null)
|
||||
run_id=$(gh run list --branch "$pr_branch" --workflow ci.yml --json databaseId -q '.[0].databaseId' 2>/dev/null)
|
||||
echo "Attempting to extract failing test files from CI logs..." >> "${log_dir}/npm-test.log"
|
||||
PR_VIEW_DATA=$(gh pr view "${pr_number}" --json headRefName 2>/dev/null)
|
||||
pr_branch=$(echo "${PR_VIEW_DATA}" | sed -n 's/.*"headRefName":"\([^"]*\)".*/\1/p')
|
||||
RUN_LIST_DATA=$(gh run list --branch "${pr_branch}" --workflow ci.yml --json databaseId 2>/dev/null)
|
||||
run_id_list=$(echo "${RUN_LIST_DATA}" | sed -n 's/.*"databaseId":\([0-9]*\).*/\1/p')
|
||||
read -r run_id <<< "${run_id_list}"
|
||||
|
||||
failed_files=""
|
||||
if [[ -n "$run_id" ]]; then
|
||||
failed_files=$(gh run view "$run_id" --log-failed 2>/dev/null | grep -o -E '(packages/[a-zA-Z0-9_-]+|integration-tests|evals)/[a-zA-Z0-9_/-]+\.test\.ts(x)?' | sort | uniq)
|
||||
if [[ -n "${run_id}" ]]; then
|
||||
RUN_VIEW_OUTPUT=$(gh run view "${run_id}" --log-failed 2>/dev/null)
|
||||
# Split the pipeline to avoid SC2312
|
||||
failed_files_raw=$(echo "${RUN_VIEW_OUTPUT}" | grep -o -E '(packages/[a-zA-Z0-9_-]+|integration-tests|evals)/[a-zA-Z0-9_/-]+\.test\.ts(x)?')
|
||||
failed_files_sorted=$(echo "${failed_files_raw}" | sort)
|
||||
failed_files=$(echo "${failed_files_sorted}" | uniq)
|
||||
fi
|
||||
|
||||
if [[ -n "$failed_files" ]]; then
|
||||
echo "Found failing test files from CI:" >> "$log_dir/npm-test.log"
|
||||
for f in $failed_files; do echo " - $f" >> "$log_dir/npm-test.log"; done
|
||||
echo "Running ONLY failing tests locally..." >> "$log_dir/npm-test.log"
|
||||
if [[ -n "${failed_files}" ]]; then
|
||||
echo "Found failing test files from CI:" >> "${log_dir}/npm-test.log"
|
||||
for f in ${failed_files}; do echo " - ${f}" >> "${log_dir}/npm-test.log"; done
|
||||
echo "Running ONLY failing tests locally..." >> "${log_dir}/npm-test.log"
|
||||
|
||||
exit_code=0
|
||||
for file in $failed_files; do
|
||||
if [[ "$file" == packages/* ]]; then
|
||||
ws_dir=$(echo "$file" | cut -d'/' -f1,2)
|
||||
for file in ${failed_files}; do
|
||||
if [[ "${file}" == packages/* ]]; then
|
||||
ws_dir=$(echo "${file}" | cut -d'/' -f1,2)
|
||||
else
|
||||
ws_dir=$(echo "$file" | cut -d'/' -f1)
|
||||
ws_dir=$(echo "${file}" | cut -d'/' -f1)
|
||||
fi
|
||||
rel_file=${file#$ws_dir/}
|
||||
rel_file=${file#"${ws_dir}/"}
|
||||
|
||||
echo "--- Running $rel_file in workspace $ws_dir ---" >> "$log_dir/npm-test.log"
|
||||
if ! npm run test:ci -w "$ws_dir" -- "$rel_file" >> "$log_dir/npm-test.log" 2>&1; then
|
||||
echo "--- Running ${rel_file} in workspace ${ws_dir} ---" >> "${log_dir}/npm-test.log"
|
||||
if ! npm run test:ci -w "${ws_dir}" -- "${rel_file}" >> "${log_dir}/npm-test.log" 2>&1; then
|
||||
exit_code=1
|
||||
fi
|
||||
done
|
||||
echo $exit_code > "$log_dir/npm-test.exit"
|
||||
echo "${exit_code}" > "${log_dir}/npm-test.exit"
|
||||
else
|
||||
echo "Could not extract specific failing files. Skipping full local test suite as it takes too long. Please check CI logs manually." >> "$log_dir/npm-test.log"
|
||||
echo 1 > "$log_dir/npm-test.exit"
|
||||
echo "Could not extract specific failing files. Skipping full local test suite as it takes too long. Please check CI logs manually." >> "${log_dir}/npm-test.log"
|
||||
echo 1 > "${log_dir}/npm-test.exit"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Skipped due to build-and-lint failure" > "$log_dir/npm-test.log"
|
||||
echo 1 > "$log_dir/npm-test.exit"
|
||||
echo "Skipped due to build-and-lint failure" > "${log_dir}/npm-test.log"
|
||||
echo 1 > "${log_dir}/npm-test.exit"
|
||||
fi
|
||||
} &
|
||||
|
||||
echo " ↳ [5/5] Starting Gemini test execution (waiting for build and lint)..."
|
||||
rm -f "$log_dir/test-execution.exit"
|
||||
rm -f "${log_dir}/test-execution.exit"
|
||||
{
|
||||
while [ ! -f "$log_dir/build-and-lint.exit" ]; do sleep 1; done
|
||||
if [ "$(cat "$log_dir/build-and-lint.exit")" == "0" ]; then
|
||||
"$GEMINI_CMD" --policy "$POLICY_PATH" -p "Analyze the diff for PR $pr_number using 'gh pr diff $pr_number'. Instead of running the project's automated test suite (like 'npm test'), physically exercise the newly changed code in the terminal (e.g., by writing a temporary script to call the new functions, or testing the CLI command directly). Verify the feature's behavior works as expected. IMPORTANT: Do NOT modify any source code to fix errors. Just exercise the code and log the results, reporting any failures clearly. Do not ask for user confirmation." > "$log_dir/test-execution.log" 2>&1; echo $? > "$log_dir/test-execution.exit"
|
||||
while [[ ! -f "${log_dir}/build-and-lint.exit" ]]; do sleep 1; done
|
||||
BUILD_LINT_EXIT_CHECK=$(cat "${log_dir}/build-and-lint.exit")
|
||||
if [[ "${BUILD_LINT_EXIT_CHECK}" == "0" ]]; then
|
||||
"${GEMINI_CMD}" --policy "${POLICY_PATH}" -p "Analyze the diff for PR ${pr_number} using 'gh pr diff ${pr_number}'. Instead of running the project's automated test suite (like 'npm test'), physically exercise the newly changed code in the terminal (e.g., by writing a temporary script to call the new functions, or testing the CLI command directly). Verify the feature's behavior works as expected. IMPORTANT: Do NOT modify any source code to fix errors. Just exercise the code and log the results, reporting any failures clearly. Do not ask for user confirmation." > "${log_dir}/test-execution.log" 2>&1; echo $? > "${log_dir}/test-execution.exit"
|
||||
else
|
||||
echo "Skipped due to build-and-lint failure" > "$log_dir/test-execution.log"
|
||||
echo 1 > "$log_dir/test-execution.exit"
|
||||
echo "Skipped due to build-and-lint failure" > "${log_dir}/test-execution.log"
|
||||
echo 1 > "${log_dir}/test-execution.exit"
|
||||
fi
|
||||
} &
|
||||
|
||||
echo "✅ All tasks dispatched!"
|
||||
echo "You can monitor progress with: tail -f $log_dir/*.log"
|
||||
echo "Read your review later at: $log_dir/review.md"
|
||||
echo "You can monitor progress with: tail -f ${log_dir}/*.log"
|
||||
echo "Read your review later at: ${log_dir}/review.md"
|
||||
|
||||
# Polling loop to wait for all background tasks to finish
|
||||
tasks=("pr-diff" "build-and-lint" "review" "npm-test" "test-execution")
|
||||
log_files=("pr-diff.diff" "build-and-lint.log" "review.md" "npm-test.log" "test-execution.log")
|
||||
declare -a ASYNC_TASKS=("pr-diff" "build-and-lint" "review" "npm-test" "test-execution")
|
||||
declare -a ASYNC_LOGS=("pr-diff.diff" "build-and-lint.log" "review.md" "npm-test.log" "test-execution.log")
|
||||
|
||||
declare -A task_done
|
||||
for t in "${tasks[@]}"; do task_done[$t]=0; done
|
||||
for t in "${ASYNC_TASKS[@]}"; do task_done["${t}"]=0; done
|
||||
|
||||
all_done=0
|
||||
while [[ $all_done -eq 0 ]]; do
|
||||
while [[ "${all_done}" -eq 0 ]]; do
|
||||
clear
|
||||
echo "=================================================="
|
||||
echo "🚀 Async PR Review Status for PR #$pr_number"
|
||||
echo "🚀 Async PR Review Status for PR #${pr_number}"
|
||||
echo "=================================================="
|
||||
echo ""
|
||||
|
||||
all_done=1
|
||||
for i in "${!tasks[@]}"; do
|
||||
t="${tasks[$i]}"
|
||||
for i in "${!ASYNC_TASKS[@]}"; do
|
||||
t="${ASYNC_TASKS[${i}]}"
|
||||
|
||||
if [[ -f "$log_dir/$t.exit" ]]; then
|
||||
exit_code=$(cat "$log_dir/$t.exit")
|
||||
if [[ "$exit_code" == "0" ]]; then
|
||||
echo " ✅ $t: SUCCESS"
|
||||
EXIT_FILE_POLL="${log_dir}/${t}.exit"
|
||||
if [[ -f "${EXIT_FILE_POLL}" ]]; then
|
||||
EXIT_CODE_POLL=$(cat "${EXIT_FILE_POLL}")
|
||||
if [[ "${EXIT_CODE_POLL}" == "0" ]]; then
|
||||
echo " ✅ ${t}: SUCCESS"
|
||||
else
|
||||
echo " ❌ $t: FAILED (exit code $exit_code)"
|
||||
echo " ❌ ${t}: FAILED (exit code ${EXIT_CODE_POLL})"
|
||||
fi
|
||||
task_done[$t]=1
|
||||
task_done["${t}"]=1
|
||||
else
|
||||
echo " ⏳ $t: RUNNING"
|
||||
echo " ⏳ ${t}: RUNNING"
|
||||
all_done=0
|
||||
fi
|
||||
done
|
||||
@@ -194,48 +206,51 @@ while [[ $all_done -eq 0 ]]; do
|
||||
echo "📝 Live Logs (Last 5 lines of running tasks)"
|
||||
echo "=================================================="
|
||||
|
||||
for i in "${!tasks[@]}"; do
|
||||
t="${tasks[$i]}"
|
||||
log_file="${log_files[$i]}"
|
||||
for i in "${!ASYNC_TASKS[@]}"; do
|
||||
t="${ASYNC_TASKS[${i}]}"
|
||||
log_file="${ASYNC_LOGS[${i}]}"
|
||||
|
||||
if [[ ${task_done[$t]} -eq 0 ]]; then
|
||||
if [[ -f "$log_dir/$log_file" ]]; then
|
||||
if [[ ${task_done["${t}"]} -eq 0 ]]; then
|
||||
LOG_PATH_POLL="${log_dir}/${log_file}"
|
||||
if [[ -f "${LOG_PATH_POLL}" ]]; then
|
||||
echo ""
|
||||
echo "--- $t ---"
|
||||
tail -n 5 "$log_dir/$log_file"
|
||||
echo "--- ${t} ---"
|
||||
tail -n 5 "${LOG_PATH_POLL}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $all_done -eq 0 ]]; then
|
||||
if [[ "${all_done}" -eq 0 ]]; then
|
||||
sleep 3
|
||||
fi
|
||||
done
|
||||
|
||||
clear
|
||||
echo "=================================================="
|
||||
echo "🚀 Async PR Review Status for PR #$pr_number"
|
||||
echo "🚀 Async PR Review Status for PR #${pr_number}"
|
||||
echo "=================================================="
|
||||
echo ""
|
||||
for t in "${tasks[@]}"; do
|
||||
exit_code=$(cat "$log_dir/$t.exit")
|
||||
if [[ "$exit_code" == "0" ]]; then
|
||||
echo " ✅ $t: SUCCESS"
|
||||
for t in "${ASYNC_TASKS[@]}"; do
|
||||
EXIT_FILE_FINAL="${log_dir}/${t}.exit"
|
||||
EXIT_CODE_FINAL=$(cat "${EXIT_FILE_FINAL}")
|
||||
if [[ "${EXIT_CODE_FINAL}" == "0" ]]; then
|
||||
echo " ✅ ${t}: SUCCESS"
|
||||
else
|
||||
echo " ❌ $t: FAILED (exit code $exit_code)"
|
||||
echo " ❌ ${t}: FAILED (exit code ${EXIT_CODE_FINAL})"
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
|
||||
echo "⏳ Tasks complete! Synthesizing final assessment..."
|
||||
if ! "$GEMINI_CMD" --policy "$POLICY_PATH" -p "Read the review at $log_dir/review.md, the automated test logs at $log_dir/npm-test.log, and the manual test execution logs at $log_dir/test-execution.log. Summarize the results, state whether the build and tests passed based on $log_dir/build-and-lint.exit and $log_dir/npm-test.exit, and give a final recommendation for PR $pr_number." > "$log_dir/final-assessment.md" 2>&1; then
|
||||
echo $? > "$log_dir/final-assessment.exit"
|
||||
if ! "${GEMINI_CMD}" --policy "${POLICY_PATH}" -p "Read the review at ${log_dir}/review.md, the automated test logs at ${log_dir}/npm-test.log, and the manual test execution logs at ${log_dir}/test-execution.log. Summarize the results, state whether the build and tests passed based on ${log_dir}/build-and-lint.exit and ${log_dir}/npm-test.exit, and give a final recommendation for PR ${pr_number}." > "${log_dir}/final-assessment.md" 2>&1; then
|
||||
EXIT_SYNTHESIS=$?
|
||||
echo "${EXIT_SYNTHESIS}" > "${log_dir}/final-assessment.exit"
|
||||
echo "❌ Final assessment synthesis failed!"
|
||||
echo "Check $log_dir/final-assessment.md for details."
|
||||
notify "Async Review Failed" "Final assessment synthesis failed." "$pr_number"
|
||||
echo "Check ${log_dir}/final-assessment.md for details."
|
||||
notify "Async Review Failed" "Final assessment synthesis failed." "${pr_number}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo 0 > "$log_dir/final-assessment.exit"
|
||||
echo "✅ Final assessment complete! Check $log_dir/final-assessment.md"
|
||||
notify "Async Review Complete" "Review and test execution finished successfully." "$pr_number"
|
||||
echo 0 > "${log_dir}/final-assessment.exit"
|
||||
echo "✅ Final assessment complete! Check ${log_dir}/final-assessment.md"
|
||||
notify "Async Review Complete" "Review and test execution finished successfully." "${pr_number}"
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#!/bin/bash
|
||||
pr_number=$1
|
||||
pr_number="${1}"
|
||||
|
||||
if [[ -z "$pr_number" ]]; then
|
||||
if [[ -z "${pr_number}" ]]; then
|
||||
echo "Usage: check-async-review <pr_number>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
base_dir=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||
if [[ -z "$base_dir" ]]; then
|
||||
if [[ -z "${base_dir}" ]]; then
|
||||
echo "❌ Must be run from within a git repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_dir="$base_dir/.gemini/tmp/async-reviews/pr-$pr_number/logs"
|
||||
log_dir="${base_dir}/.gemini/tmp/async-reviews/pr-${pr_number}/logs"
|
||||
|
||||
if [[ ! -d "$log_dir" ]]; then
|
||||
if [[ ! -d "${log_dir}" ]]; then
|
||||
echo "STATUS: NOT_FOUND"
|
||||
echo "❌ No logs found for PR #$pr_number in $log_dir"
|
||||
echo "❌ No logs found for PR #${pr_number} in ${log_dir}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -34,32 +34,32 @@ all_done=true
|
||||
echo "STATUS: CHECKING"
|
||||
|
||||
for task_info in "${tasks[@]}"; do
|
||||
IFS="|" read -r task_name log_file <<< "$task_info"
|
||||
IFS="|" read -r task_name log_file <<< "${task_info}"
|
||||
|
||||
file_path="$log_dir/$log_file"
|
||||
exit_file="$log_dir/$task_name.exit"
|
||||
file_path="${log_dir}/${log_file}"
|
||||
exit_file="${log_dir}/${task_name}.exit"
|
||||
|
||||
if [[ -f "$exit_file" ]]; then
|
||||
exit_code=$(cat "$exit_file")
|
||||
if [[ "$exit_code" == "0" ]]; then
|
||||
echo "✅ $task_name: SUCCESS"
|
||||
if [[ -f "${exit_file}" ]]; then
|
||||
EXIT_CODE_VAL=$(cat "${exit_file}")
|
||||
if [[ "${EXIT_CODE_VAL}" == "0" ]]; then
|
||||
echo "✅ ${task_name}: SUCCESS"
|
||||
else
|
||||
echo "❌ $task_name: FAILED (exit code $exit_code)"
|
||||
echo " Last lines of $file_path:"
|
||||
tail -n 3 "$file_path" | sed 's/^/ /'
|
||||
echo "❌ ${task_name}: FAILED (exit code ${EXIT_CODE_VAL})"
|
||||
echo " Last lines of ${file_path}:"
|
||||
tail -n 3 "${file_path}" | sed 's/^/ /' || true
|
||||
fi
|
||||
elif [[ -f "$file_path" ]]; then
|
||||
echo "⏳ $task_name: RUNNING"
|
||||
elif [[ -f "${file_path}" ]]; then
|
||||
echo "⏳ ${task_name}: RUNNING"
|
||||
all_done=false
|
||||
else
|
||||
echo "➖ $task_name: NOT STARTED"
|
||||
echo "➖ ${task_name}: NOT STARTED"
|
||||
all_done=false
|
||||
fi
|
||||
done
|
||||
|
||||
if $all_done; then
|
||||
if [[ "${all_done}" == "true" ]]; then
|
||||
echo "STATUS: COMPLETE"
|
||||
echo "LOG_DIR: $log_dir"
|
||||
echo "LOG_DIR: ${log_dir}"
|
||||
else
|
||||
echo "STATUS: IN_PROGRESS"
|
||||
fi
|
||||
fi
|
||||
|
||||
Generated
+1269
File diff suppressed because it is too large
Load Diff
@@ -88,6 +88,7 @@
|
||||
"devDependencies": {
|
||||
"@agentclientprotocol/sdk": "^0.12.0",
|
||||
"@octokit/rest": "^22.0.0",
|
||||
"@tktco/node-actionlint": "^1.6.0",
|
||||
"@types/marked": "^5.0.2",
|
||||
"@types/mime-types": "^3.0.1",
|
||||
"@types/minimatch": "^5.1.2",
|
||||
@@ -126,11 +127,13 @@
|
||||
"react-devtools-core": "^6.1.2",
|
||||
"react-dom": "^19.2.0",
|
||||
"semver": "^7.7.2",
|
||||
"shellcheck": "^4.1.0",
|
||||
"strip-ansi": "^7.1.2",
|
||||
"ts-prune": "^0.10.3",
|
||||
"tsx": "^4.20.3",
|
||||
"typescript-eslint": "^8.30.1",
|
||||
"vitest": "^3.2.4",
|
||||
"yaml-lint": "^1.7.0",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
+7
-10
@@ -24,15 +24,15 @@ import { fileURLToPath } from 'node:url';
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const root = join(__dirname, '..');
|
||||
|
||||
// remove npm install/build artifacts
|
||||
rmSync(join(root, 'node_modules'), { recursive: true, force: true });
|
||||
rmSync(join(root, 'bundle'), { recursive: true, force: true });
|
||||
rmSync(join(root, 'packages/cli/src/generated/'), {
|
||||
const RMRF_OPTIONS = {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
const RMRF_OPTIONS = { recursive: true, force: true };
|
||||
maxRetries: 10,
|
||||
retryDelay: 100,
|
||||
};
|
||||
rmSync(join(root, 'node_modules'), RMRF_OPTIONS);
|
||||
rmSync(join(root, 'bundle'), RMRF_OPTIONS);
|
||||
rmSync(join(root, 'packages/cli/src/generated/'), RMRF_OPTIONS);
|
||||
// Dynamically clean dist directories in all workspaces
|
||||
const rootPackageJson = JSON.parse(
|
||||
readFileSync(join(root, 'package.json'), 'utf-8'),
|
||||
@@ -57,10 +57,7 @@ for (const workspace of rootPackageJson.workspaces) {
|
||||
}
|
||||
|
||||
// Clean up vscode-ide-companion package
|
||||
rmSync(join(root, 'packages/vscode-ide-companion/node_modules'), {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
rmSync(join(root, 'packages/vscode-ide-companion/node_modules'), RMRF_OPTIONS);
|
||||
|
||||
const vscodeCompanionDir = join(root, 'packages/vscode-ide-companion');
|
||||
try {
|
||||
|
||||
+131
-172
@@ -6,129 +6,16 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import {
|
||||
mkdirSync,
|
||||
rmSync,
|
||||
readFileSync,
|
||||
existsSync,
|
||||
lstatSync,
|
||||
} from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { execSync, spawnSync } from 'node:child_process';
|
||||
import { existsSync, lstatSync, readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const ACTIONLINT_VERSION = '1.7.7';
|
||||
const SHELLCHECK_VERSION = '0.11.0';
|
||||
const YAMLLINT_VERSION = '1.35.1';
|
||||
|
||||
const TEMP_DIR =
|
||||
process.env.GEMINI_LINT_TEMP_DIR || join(tmpdir(), 'gemini-cli-linters');
|
||||
|
||||
function getPlatformArch() {
|
||||
const platform = process.platform;
|
||||
const arch = process.arch;
|
||||
if (platform === 'linux' && arch === 'x64') {
|
||||
return {
|
||||
actionlint: 'linux_amd64',
|
||||
shellcheck: 'linux.x86_64',
|
||||
};
|
||||
}
|
||||
if (platform === 'darwin' && arch === 'x64') {
|
||||
return {
|
||||
actionlint: 'darwin_amd64',
|
||||
shellcheck: 'darwin.x86_64',
|
||||
};
|
||||
}
|
||||
if (platform === 'darwin' && arch === 'arm64') {
|
||||
return {
|
||||
actionlint: 'darwin_arm64',
|
||||
shellcheck: 'darwin.aarch64',
|
||||
};
|
||||
}
|
||||
if (platform === 'win32' && arch === 'x64') {
|
||||
return {
|
||||
actionlint: 'windows_amd64',
|
||||
// shellcheck is not used for Windows since it uses the .zip release
|
||||
// which has a consistent name across architectures
|
||||
};
|
||||
}
|
||||
throw new Error(`Unsupported platform/architecture: ${platform}/${arch}`);
|
||||
}
|
||||
|
||||
const platformArch = getPlatformArch();
|
||||
|
||||
const PYTHON_VENV_PATH = join(TEMP_DIR, 'python_venv');
|
||||
|
||||
const pythonVenvPythonPath = join(
|
||||
PYTHON_VENV_PATH,
|
||||
process.platform === 'win32' ? 'Scripts' : 'bin',
|
||||
process.platform === 'win32' ? 'python.exe' : 'python',
|
||||
);
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
const actionlintCheck = isWindows
|
||||
? `where actionlint 2>nul`
|
||||
: 'command -v actionlint';
|
||||
|
||||
const actionlintInstaller = isWindows
|
||||
? `powershell -Command "` +
|
||||
`New-Item -ItemType Directory -Force -Path '${TEMP_DIR}/actionlint' | Out-Null; ` +
|
||||
`Invoke-WebRequest -Uri 'https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${platformArch.actionlint}.zip' -OutFile '${TEMP_DIR}/.actionlint.zip'; ` +
|
||||
`Add-Type -AssemblyName System.IO.Compression.FileSystem; ` +
|
||||
`[System.IO.Compression.ZipFile]::ExtractToDirectory('${TEMP_DIR}/.actionlint.zip', '${TEMP_DIR}/actionlint')"`
|
||||
: `
|
||||
mkdir -p "${TEMP_DIR}/actionlint"
|
||||
curl -sSLo "${TEMP_DIR}/.actionlint.tgz" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${platformArch.actionlint}.tar.gz"
|
||||
tar -xzf "${TEMP_DIR}/.actionlint.tgz" -C "${TEMP_DIR}/actionlint"
|
||||
`;
|
||||
|
||||
const shellcheckCheck = isWindows
|
||||
? `where shellcheck 2>nul`
|
||||
: 'command -v shellcheck';
|
||||
|
||||
const shellcheckInstaller = isWindows
|
||||
? `powershell -Command "` +
|
||||
`Invoke-WebRequest -Uri 'https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.zip' -OutFile '${TEMP_DIR}/.shellcheck.zip'; ` +
|
||||
`Add-Type -AssemblyName System.IO.Compression.FileSystem; ` +
|
||||
`[System.IO.Compression.ZipFile]::ExtractToDirectory('${TEMP_DIR}/.shellcheck.zip', '${TEMP_DIR}/shellcheck')"`
|
||||
: `
|
||||
mkdir -p "${TEMP_DIR}/shellcheck"
|
||||
curl -sSLo "${TEMP_DIR}/.shellcheck.txz" "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${platformArch.shellcheck}.tar.xz"
|
||||
tar -xf "${TEMP_DIR}/.shellcheck.txz" -C "${TEMP_DIR}/shellcheck" --strip-components=1
|
||||
`;
|
||||
|
||||
const yamllintCheck = isWindows
|
||||
? `if exist "${PYTHON_VENV_PATH}\\Scripts\\yamllint.exe" (exit 0) else (exit 1)`
|
||||
: `test -x "${PYTHON_VENV_PATH}/bin/yamllint"`;
|
||||
|
||||
const yamllintInstaller = isWindows
|
||||
? `python -m venv "${PYTHON_VENV_PATH}" && ` +
|
||||
`"${pythonVenvPythonPath}" -m pip install --upgrade pip && ` +
|
||||
`"${pythonVenvPythonPath}" -m pip install "yamllint==${YAMLLINT_VERSION}" --index-url https://pypi.org/simple`
|
||||
: `
|
||||
python3 -m venv "${PYTHON_VENV_PATH}" && \
|
||||
"${pythonVenvPythonPath}" -m pip install --upgrade pip && \
|
||||
"${pythonVenvPythonPath}" -m pip install "yamllint==${YAMLLINT_VERSION}" --index-url https://pypi.org/simple
|
||||
`;
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* check: string;
|
||||
* installer: string;
|
||||
* run: string;
|
||||
* }}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @type {{[linterName: string]: Linter}}
|
||||
*/
|
||||
const LINTERS = {
|
||||
actionlint: {
|
||||
check: actionlintCheck,
|
||||
installer: actionlintInstaller,
|
||||
check: 'npm list @tktco/node-actionlint --depth=0',
|
||||
installer: 'npm install --save-dev @tktco/node-actionlint',
|
||||
run: `
|
||||
actionlint \
|
||||
npx node-actionlint \
|
||||
-color \
|
||||
-ignore 'SC2002:' \
|
||||
-ignore 'SC2016:' \
|
||||
@@ -137,45 +24,59 @@ const LINTERS = {
|
||||
`,
|
||||
},
|
||||
shellcheck: {
|
||||
check: shellcheckCheck,
|
||||
installer: shellcheckInstaller,
|
||||
run: `
|
||||
git ls-files | grep -E '^([^.]+|.*\\.(sh|zsh|bash))' | xargs file --mime-type \
|
||||
| grep "text/x-shellscript" | awk '{ print substr($1, 1, length($1)-1) }' \
|
||||
| xargs shellcheck \
|
||||
--check-sourced \
|
||||
--enable=all \
|
||||
--exclude=SC2002,SC2129,SC2310 \
|
||||
--severity=style \
|
||||
--format=gcc \
|
||||
--color=never | sed -e 's/note:/warning:/g' -e 's/style:/warning:/g'
|
||||
`,
|
||||
check: 'npm list shellcheck --depth=0',
|
||||
installer: 'npm install --save-dev shellcheck',
|
||||
},
|
||||
yamllint: {
|
||||
check: yamllintCheck,
|
||||
installer: yamllintInstaller,
|
||||
run: "git ls-files | grep -E '\\.(yaml|yml)' | xargs yamllint --format github",
|
||||
check: 'npm list yaml-lint --depth=0',
|
||||
installer: 'npm install --save-dev yaml-lint',
|
||||
},
|
||||
};
|
||||
|
||||
function getShellScripts() {
|
||||
const allFiles = execSync('git ls-files', { encoding: 'utf-8' })
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
|
||||
return allFiles.filter((file) => {
|
||||
if (
|
||||
file.endsWith('.sh') ||
|
||||
file.endsWith('.zsh') ||
|
||||
file.endsWith('.bash')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
!file.includes('.') &&
|
||||
existsSync(file) &&
|
||||
!lstatSync(file).isDirectory()
|
||||
) {
|
||||
try {
|
||||
const content = readFileSync(file, 'utf-8');
|
||||
const firstLine = content.split('\n')[0];
|
||||
return (
|
||||
firstLine.startsWith('#!') &&
|
||||
(firstLine.includes('sh') ||
|
||||
firstLine.includes('bash') ||
|
||||
firstLine.includes('zsh'))
|
||||
);
|
||||
} catch (_e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function getYamlFiles() {
|
||||
return execSync('git ls-files', { encoding: 'utf-8' })
|
||||
.split('\n')
|
||||
.filter((file) => file.endsWith('.yaml') || file.endsWith('.yml'));
|
||||
}
|
||||
|
||||
function runCommand(command, stdio = 'inherit') {
|
||||
try {
|
||||
const env = { ...process.env };
|
||||
const nodeBin = join(process.cwd(), 'node_modules', '.bin');
|
||||
const sep = isWindows ? ';' : ':';
|
||||
const pythonBin = isWindows
|
||||
? join(PYTHON_VENV_PATH, 'Scripts')
|
||||
: join(PYTHON_VENV_PATH, 'bin');
|
||||
// Windows sometimes uses 'Path' instead of 'PATH'
|
||||
const pathKey = 'Path' in env ? 'Path' : 'PATH';
|
||||
env[pathKey] = [
|
||||
nodeBin,
|
||||
join(TEMP_DIR, 'actionlint'),
|
||||
join(TEMP_DIR, 'shellcheck'),
|
||||
pythonBin,
|
||||
env[pathKey],
|
||||
].join(sep);
|
||||
execSync(command, { stdio, env, shell: true });
|
||||
execSync(command, { stdio, env: process.env, shell: true });
|
||||
return true;
|
||||
} catch (_e) {
|
||||
return false;
|
||||
@@ -184,10 +85,6 @@ function runCommand(command, stdio = 'inherit') {
|
||||
|
||||
export function setupLinters() {
|
||||
console.log('Setting up linters...');
|
||||
if (!process.env.GEMINI_LINT_TEMP_DIR) {
|
||||
rmSync(TEMP_DIR, { recursive: true, force: true });
|
||||
}
|
||||
mkdirSync(TEMP_DIR, { recursive: true });
|
||||
|
||||
for (const linter in LINTERS) {
|
||||
const { check, installer } = LINTERS[linter];
|
||||
@@ -220,21 +117,67 @@ export function runActionlint() {
|
||||
|
||||
export function runShellcheck() {
|
||||
console.log('\nRunning shellcheck...');
|
||||
if (!runCommand(LINTERS.shellcheck.run)) {
|
||||
const files = getShellScripts();
|
||||
if (files.length === 0) {
|
||||
console.log('No shell scripts found.');
|
||||
return;
|
||||
}
|
||||
|
||||
const args = [
|
||||
'shellcheck',
|
||||
'--check-sourced',
|
||||
'--enable=all',
|
||||
'--exclude=SC2002,SC2129,SC2310',
|
||||
'--severity=style',
|
||||
'--format=gcc',
|
||||
'--color=never',
|
||||
...files,
|
||||
];
|
||||
|
||||
const result = spawnSync('npx', args, {
|
||||
env: process.env,
|
||||
encoding: 'utf-8',
|
||||
shell: true, // Needed for npx on Windows and some Unix environments
|
||||
});
|
||||
|
||||
if (result.stdout) {
|
||||
console.log(
|
||||
result.stdout
|
||||
.replace(/note:/g, 'warning:')
|
||||
.replace(/style:/g, 'warning:'),
|
||||
);
|
||||
}
|
||||
|
||||
if (result.status !== 0) {
|
||||
if (result.stderr) {
|
||||
console.error(result.stderr);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export function runYamllint() {
|
||||
console.log('\nRunning yamllint...');
|
||||
if (!runCommand(LINTERS.yamllint.run)) {
|
||||
const files = getYamlFiles();
|
||||
if (files.length === 0) {
|
||||
console.log('No YAML files found.');
|
||||
return;
|
||||
}
|
||||
|
||||
const result = spawnSync('npx', ['yaml-lint', ...files], {
|
||||
env: process.env,
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
});
|
||||
|
||||
if (result.status !== 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export function runPrettier() {
|
||||
console.log('\nRunning Prettier...');
|
||||
if (!runCommand('prettier --check .')) {
|
||||
if (!runCommand('npx prettier --check .')) {
|
||||
console.log(
|
||||
'Prettier check failed. Please run "npm run format" to fix formatting issues.',
|
||||
);
|
||||
@@ -258,27 +201,43 @@ export function runSensitiveKeywordLinter() {
|
||||
function getChangedFiles() {
|
||||
const baseRef = process.env.GITHUB_BASE_REF || 'main';
|
||||
try {
|
||||
execSync(`git fetch origin ${baseRef}`);
|
||||
const mergeBase = execSync(`git merge-base HEAD origin/${baseRef}`)
|
||||
// In CI, we often have the remote main already fetched or can diff against it directly
|
||||
// Try to find merge base if possible
|
||||
const mergeBase = execSync(
|
||||
`git merge-base HEAD origin/${baseRef} 2>/dev/null || git merge-base HEAD ${baseRef} 2>/dev/null`,
|
||||
)
|
||||
.toString()
|
||||
.trim();
|
||||
return execSync(`git diff --name-only ${mergeBase}..HEAD`)
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
} catch (_error) {
|
||||
console.error(`Could not get changed files against origin/${baseRef}.`);
|
||||
try {
|
||||
console.log('Falling back to diff against HEAD~1');
|
||||
return execSync(`git diff --name-only HEAD~1..HEAD`)
|
||||
|
||||
if (mergeBase) {
|
||||
return execSync(`git diff --name-only ${mergeBase}..HEAD`)
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
} catch (_fallbackError) {
|
||||
console.error('Could not get changed files against HEAD~1 either.');
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (_error) {
|
||||
// Fall through to other methods
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('Falling back to diff against HEAD~1');
|
||||
return execSync(`git diff --name-only HEAD~1..HEAD`)
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
} catch (_fallbackError) {
|
||||
console.log('Falling back to all tracked files (slowest)');
|
||||
try {
|
||||
return execSync('git ls-files')
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
} catch (_ultimateError) {
|
||||
console.error('Could not get any files to lint.');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+46
-44
@@ -5,17 +5,17 @@
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <pr#> [model]"
|
||||
if [[ -z "${1}" ]]; then
|
||||
echo "Usage: ${0} <pr#> [model]"
|
||||
exit 1
|
||||
fi
|
||||
pr="$1"
|
||||
pr="${1}"
|
||||
model="${2:-gemini-3.1-pro-preview}"
|
||||
REPO="google-gemini/gemini-cli"
|
||||
REVIEW_DIR="$HOME/git/review/gemini-cli"
|
||||
REVIEW_DIR="${HOME}/git/review/gemini-cli"
|
||||
|
||||
if [ ! -d "$REVIEW_DIR" ]; then
|
||||
echo "ERROR: Directory $REVIEW_DIR does not exist."
|
||||
if [[ ! -d "${REVIEW_DIR}" ]]; then
|
||||
echo "ERROR: Directory ${REVIEW_DIR} does not exist."
|
||||
echo ""
|
||||
echo "Please create a new gemini-cli clone at that directory to use for reviews."
|
||||
echo "Instructions:"
|
||||
@@ -26,54 +26,56 @@ if [ ! -d "$REVIEW_DIR" ]; then
|
||||
fi
|
||||
|
||||
# 1. Check if the PR exists before doing anything else
|
||||
echo "review: Validating PR $pr on $REPO..."
|
||||
if ! gh pr view "$pr" -R "$REPO" > /dev/null 2>&1; then
|
||||
echo "ERROR: Could not find PR #$pr in $REPO."
|
||||
echo "Are you sure $pr is a Pull Request number and not an Issue number?"
|
||||
echo "review: Validating PR ${pr} on ${REPO}..."
|
||||
if ! gh pr view "${pr}" -R "${REPO}" > /dev/null 2>&1; then
|
||||
echo "ERROR: Could not find PR #${pr} in ${REPO}."
|
||||
echo "Are you sure ${pr} is a Pull Request number and not an Issue number?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "review: Opening PR $pr in browser..."
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
open "https://github.com/$REPO/pull/$pr" || true
|
||||
echo "review: Opening PR ${pr} in browser..."
|
||||
OS_TYPE=$(uname)
|
||||
if [[ "${OS_TYPE}" == "Darwin" ]]; then
|
||||
open "https://github.com/${REPO}/pull/${pr}" || true
|
||||
else
|
||||
xdg-open "https://github.com/$REPO/pull/$pr" || true
|
||||
xdg-open "https://github.com/${REPO}/pull/${pr}" || true
|
||||
fi
|
||||
|
||||
echo "review: Changing directory to $REVIEW_DIR"
|
||||
cd "$REVIEW_DIR" || exit 1
|
||||
echo "review: Changing directory to ${REVIEW_DIR}"
|
||||
cd "${REVIEW_DIR}" || exit 1
|
||||
|
||||
# 2. Fetch latest main to ensure we have a clean starting point
|
||||
echo "review: Fetching latest from origin..."
|
||||
git fetch origin main
|
||||
|
||||
# 3. Handle worktree creation
|
||||
WORKTREE_PATH="pr_$pr"
|
||||
if [ -d "$WORKTREE_PATH" ]; then
|
||||
echo "review: Worktree directory $WORKTREE_PATH already exists."
|
||||
WORKTREE_PATH="pr_${pr}"
|
||||
if [[ -d "${WORKTREE_PATH}" ]]; then
|
||||
echo "review: Worktree directory ${WORKTREE_PATH} already exists."
|
||||
# Check if it's actually a registered worktree
|
||||
if git worktree list | grep -q "$WORKTREE_PATH"; then
|
||||
WORKTREE_LIST=$(git worktree list)
|
||||
if echo "${WORKTREE_LIST}" | grep -q "${WORKTREE_PATH}"; then
|
||||
echo "review: Reusing existing worktree..."
|
||||
else
|
||||
echo "review: Directory exists but is not a worktree. Cleaning up..."
|
||||
rm -rf "$WORKTREE_PATH"
|
||||
rm -rf "${WORKTREE_PATH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "$WORKTREE_PATH" ]; then
|
||||
echo "review: Adding new worktree at $WORKTREE_PATH..."
|
||||
if [[ ! -d "${WORKTREE_PATH}" ]]; then
|
||||
echo "review: Adding new worktree at ${WORKTREE_PATH}..."
|
||||
# Create a detached worktree from origin/main
|
||||
git worktree add --detach "$WORKTREE_PATH" origin/main
|
||||
git worktree add --detach "${WORKTREE_PATH}" origin/main
|
||||
fi
|
||||
|
||||
echo "review: Changing directory to $WORKTREE_PATH"
|
||||
cd "$WORKTREE_PATH" || exit 1
|
||||
echo "review: Changing directory to ${WORKTREE_PATH}"
|
||||
cd "${WORKTREE_PATH}" || exit 1
|
||||
|
||||
# 4. Checkout the PR
|
||||
echo "review: Cleaning worktree and checking out PR $pr..."
|
||||
echo "review: Cleaning worktree and checking out PR ${pr}..."
|
||||
git reset --hard
|
||||
git clean -fd
|
||||
gh pr checkout "$pr" --branch "review-$pr" -f -R "$REPO"
|
||||
gh pr checkout "${pr}" --branch "review-${pr}" -f -R "${REPO}"
|
||||
|
||||
# 5. Clean and Build
|
||||
echo "review: Clearing possibly stale node_modules..."
|
||||
@@ -87,48 +89,48 @@ npm install
|
||||
|
||||
echo "--- build ---"
|
||||
temp_dir_base="${TMPDIR:-/tmp}"
|
||||
build_log_file=$(mktemp "${temp_dir_base}/npm_build_log.XXXXXX") || {
|
||||
if ! build_log_file=$(mktemp "${temp_dir_base}/npm_build_log.XXXXXX"); then
|
||||
echo "Attempting to create temporary file in current directory as a fallback." >&2
|
||||
build_log_file=$(mktemp "./npm_build_log_fallback.XXXXXX")
|
||||
if [ $? -ne 0 ] || [ -z "$build_log_file" ]; then
|
||||
if ! build_log_file=$(mktemp "./npm_build_log_fallback.XXXXXX"); then
|
||||
echo "ERROR: Critical - Failed to create any temporary build log file. Aborting." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
build_status=0
|
||||
build_command_to_run="FORCE_COLOR=1 CLICOLOR_FORCE=1 npm run build"
|
||||
|
||||
echo "Running build. Output (with colors) will be shown below and saved to: $build_log_file"
|
||||
echo "Build command: $build_command_to_run"
|
||||
echo "Running build. Output (with colors) will be shown below and saved to: ${build_log_file}"
|
||||
echo "Build command: ${build_command_to_run}"
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
script -q "$build_log_file" /bin/sh -c "$build_command_to_run"
|
||||
OS_TYPE=$(uname)
|
||||
if [[ "${OS_TYPE}" == "Darwin" ]]; then
|
||||
script -q "${build_log_file}" /bin/sh -c "${build_command_to_run}"
|
||||
build_status=$?
|
||||
else
|
||||
if script -q -e -c "$build_command_to_run" "$build_log_file"; then
|
||||
if script -q -e -c "${build_command_to_run}" "${build_log_file}"; then
|
||||
build_status=0
|
||||
else
|
||||
build_status=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $build_status -ne 0 ]; then
|
||||
echo "ERROR: npm build failed with exit status $build_status." >&2
|
||||
echo "Review output above. Full log (with color codes) was in $build_log_file." >&2
|
||||
if [[ "${build_status}" -ne 0 ]]; then
|
||||
echo "ERROR: npm build failed with exit status ${build_status}." >&2
|
||||
echo "Review output above. Full log (with color codes) was in ${build_log_file}." >&2
|
||||
exit 1
|
||||
else
|
||||
if grep -q -i -E "\berror\b|\bfailed\b|ERR!|FATAL|critical" "$build_log_file"; then
|
||||
if grep -q -i -E "\berror\b|\bfailed\b|ERR!|FATAL|critical" "${build_log_file}"; then
|
||||
echo "ERROR: npm build completed with exit status 0, but suspicious error patterns were found in the build output." >&2
|
||||
echo "Review output above. Full log (with color codes) was in $build_log_file." >&2
|
||||
echo "Review output above. Full log (with color codes) was in ${build_log_file}." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "npm build completed successfully (exit status 0, no critical error patterns found in log)."
|
||||
rm -f "$build_log_file"
|
||||
rm -f "${build_log_file}"
|
||||
fi
|
||||
|
||||
echo "-- running ---"
|
||||
if ! npm start -- -m "$model" -i="/review-frontend $pr"; then
|
||||
if ! npm start -- -m "${model}" -i="/review-frontend ${pr}"; then
|
||||
echo "ERROR: npm start failed. Please check its output for details." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user