Mirrowel commited on
Commit
29be8ce
·
1 Parent(s): 083f14b

ci: actually works now

Browse files
Files changed (1) hide show
  1. .github/workflows/pr-review.yml +27 -24
.github/workflows/pr-review.yml CHANGED
@@ -427,6 +427,8 @@ jobs:
427
  BASE_BRANCH="${{ env.BASE_BRANCH }}"
428
  CURRENT_SHA="${PR_HEAD_SHA}"
429
  DIFF_CONTENT=""
 
 
430
 
431
  echo "Generating full PR diff against base branch: $BASE_BRANCH"
432
 
@@ -450,25 +452,25 @@ jobs:
450
  TRUNCATION_MSG=$'\n\n[DIFF TRUNCATED - PR is very large. Showing first 500KB only. Review scaled to high-impact areas.]'
451
  DIFF_CONTENT="${DIFF_CONTENT:0:500000}${TRUNCATION_MSG}"
452
  fi
453
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
454
- echo "$DIFF_CONTENT" > "$TMP_DIR/first_review_diff.txt"
455
  else
456
  echo "::warning::Could not generate diff. Using changed files list only."
457
  DIFF_CONTENT="(Diff generation failed. Please refer to the changed files list above.)"
458
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
459
- echo "$DIFF_CONTENT" > "$TMP_DIR/first_review_diff.txt"
460
  fi
461
  else
462
- echo "::warning::Could not find merge base between $BASE_BRANCH and $CURRENT_SHA."
463
- DIFF_CONTENT="(No common ancestor found. This might be a new branch or orphaned commits.)"
464
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
465
- echo "$DIFF_CONTENT" > "$TMP_DIR/first_review_diff.txt"
466
  fi
467
  else
468
  echo "::warning::Could not fetch base branch $BASE_BRANCH. Using changed files list only."
469
  DIFF_CONTENT="(Base branch not available for diff. Please refer to the changed files list above.)"
470
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
471
- echo "$DIFF_CONTENT" > "$TMP_DIR/first_review_diff.txt"
472
  fi
473
 
474
  env:
@@ -481,6 +483,8 @@ jobs:
481
  LAST_SHA=${{ steps.review_type.outputs.last_reviewed_sha }}
482
  CURRENT_SHA="${PR_HEAD_SHA}"
483
  DIFF_CONTENT=""
 
 
484
  echo "Attempting to generate incremental diff from $LAST_SHA to $CURRENT_SHA"
485
 
486
  # Fetch the last reviewed commit, handle potential errors (e.g., rebased/force-pushed commit)
@@ -499,23 +503,22 @@ jobs:
499
  TRUNCATION_MSG=$'\n\n[DIFF TRUNCATED - Changes are very large. Showing first 500KB only.]'
500
  DIFF_CONTENT="${DIFF_CONTENT:0:500000}${TRUNCATION_MSG}"
501
  fi
502
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
503
- echo "$DIFF_CONTENT" > "$TMP_DIR/incremental_diff.txt"
504
  else
505
  echo "::warning::Could not generate diff between $LAST_SHA and $CURRENT_SHA. Possible rebase/force-push. AI will perform full review."
506
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
507
- echo "" > "$TMP_DIR/incremental_diff.txt"
508
  fi
509
  else
510
  echo "::warning::Failed to fetch last reviewed SHA: $LAST_SHA. This can happen if the commit was part of a force-push or rebase. The AI will perform a full review as a fallback."
511
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
512
- echo "" > "$TMP_DIR/incremental_diff.txt"
513
  fi
514
 
515
- # Ensure files exist even on edge cases
516
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
517
- [ -f "$TMP_DIR/first_review_diff.txt" ] || touch "$TMP_DIR/first_review_diff.txt"
518
- [ -f "$TMP_DIR/incremental_diff.txt" ] || touch "$TMP_DIR/incremental_diff.txt"
519
 
520
 
521
  - name: Assemble Review Prompt
@@ -528,14 +531,14 @@ jobs:
528
  PR_HEAD_SHA: ${{ env.PR_HEAD_SHA }}
529
  PULL_REQUEST_CONTEXT: ${{ env.PULL_REQUEST_CONTEXT }}
530
  run: |
531
- # Build DIFF_FILE_PATH pointing to the generated diff in RUNNER_TEMP
532
- TMP_DIR="${RUNNER_TEMP:-/tmp}"
533
  if [ "${{ steps.review_type.outputs.is_first_review }}" = "true" ]; then
534
- DIFF_FILE_PATH="$TMP_DIR/first_review_diff.txt"
535
  else
536
- DIFF_FILE_PATH="$TMP_DIR/incremental_diff.txt"
537
  fi
538
  # Substitute variables, embedding PR context and diff file path; DIFF_FILE_PATH kept local to this process
 
539
  VARS='${REVIEW_TYPE} ${PR_AUTHOR} ${IS_FIRST_REVIEW} ${PR_NUMBER} ${GITHUB_REPOSITORY} ${PR_HEAD_SHA} ${PULL_REQUEST_CONTEXT} ${DIFF_FILE_PATH}'
540
  DIFF_FILE_PATH="$DIFF_FILE_PATH" envsubst "$VARS" < /tmp/pr-review.md > "$TMP_DIR/assembled_prompt.txt"
541
  # Immediately clear large env after use
 
427
  BASE_BRANCH="${{ env.BASE_BRANCH }}"
428
  CURRENT_SHA="${PR_HEAD_SHA}"
429
  DIFF_CONTENT=""
430
+ # Ensure dedicated diff folder exists in the workspace (hidden to avoid accidental use)
431
+ mkdir -p "$GITHUB_WORKSPACE/.mirrobot_files"
432
 
433
  echo "Generating full PR diff against base branch: $BASE_BRANCH"
434
 
 
452
  TRUNCATION_MSG=$'\n\n[DIFF TRUNCATED - PR is very large. Showing first 500KB only. Review scaled to high-impact areas.]'
453
  DIFF_CONTENT="${DIFF_CONTENT:0:500000}${TRUNCATION_MSG}"
454
  fi
455
+ # Write diff directly into the repository workspace in the dedicated folder
456
+ echo "$DIFF_CONTENT" > "$GITHUB_WORKSPACE/.mirrobot_files/first_review_diff.txt"
457
  else
458
  echo "::warning::Could not generate diff. Using changed files list only."
459
  DIFF_CONTENT="(Diff generation failed. Please refer to the changed files list above.)"
460
+ # Write fallback diff directly into the workspace folder
461
+ echo "$DIFF_CONTENT" > "$GITHUB_WORKSPACE/.mirrobot_files/first_review_diff.txt"
462
  fi
463
  else
464
+ echo "::warning::Could not find merge base between $BASE_BRANCH and $CURRENT_SHA."
465
+ DIFF_CONTENT="(No common ancestor found. This might be a new branch or orphaned commits.)"
466
+ # Write fallback diff content directly into the repository workspace folder
467
+ echo "$DIFF_CONTENT" > "$GITHUB_WORKSPACE/.mirrobot_files/first_review_diff.txt"
468
  fi
469
  else
470
  echo "::warning::Could not fetch base branch $BASE_BRANCH. Using changed files list only."
471
  DIFF_CONTENT="(Base branch not available for diff. Please refer to the changed files list above.)"
472
+ # Write error-case diff directly into the repository workspace folder
473
+ echo "$DIFF_CONTENT" > "$GITHUB_WORKSPACE/.mirrobot_files/first_review_diff.txt"
474
  fi
475
 
476
  env:
 
483
  LAST_SHA=${{ steps.review_type.outputs.last_reviewed_sha }}
484
  CURRENT_SHA="${PR_HEAD_SHA}"
485
  DIFF_CONTENT=""
486
+ # Ensure dedicated diff folder exists in the workspace (hidden to avoid accidental use)
487
+ mkdir -p "$GITHUB_WORKSPACE/.mirrobot_files"
488
  echo "Attempting to generate incremental diff from $LAST_SHA to $CURRENT_SHA"
489
 
490
  # Fetch the last reviewed commit, handle potential errors (e.g., rebased/force-pushed commit)
 
503
  TRUNCATION_MSG=$'\n\n[DIFF TRUNCATED - Changes are very large. Showing first 500KB only.]'
504
  DIFF_CONTENT="${DIFF_CONTENT:0:500000}${TRUNCATION_MSG}"
505
  fi
506
+ # Write incremental diff directly into the repository workspace folder
507
+ echo "$DIFF_CONTENT" > "$GITHUB_WORKSPACE/.mirrobot_files/incremental_diff.txt"
508
  else
509
  echo "::warning::Could not generate diff between $LAST_SHA and $CURRENT_SHA. Possible rebase/force-push. AI will perform full review."
510
+ # Ensure an empty incremental diff file exists in the workspace folder as fallback
511
+ echo "" > "$GITHUB_WORKSPACE/.mirrobot_files/incremental_diff.txt"
512
  fi
513
  else
514
  echo "::warning::Failed to fetch last reviewed SHA: $LAST_SHA. This can happen if the commit was part of a force-push or rebase. The AI will perform a full review as a fallback."
515
+ # Ensure an empty incremental diff file exists in the workspace folder when last-SHA fetch fails
516
+ echo "" > "$GITHUB_WORKSPACE/.mirrobot_files/incremental_diff.txt"
517
  fi
518
 
519
+ # Ensure workspace diff files exist even on edge cases (in the hidden folder)
520
+ [ -f "$GITHUB_WORKSPACE/.mirrobot_files/first_review_diff.txt" ] || touch "$GITHUB_WORKSPACE/.mirrobot_files/first_review_diff.txt"
521
+ [ -f "$GITHUB_WORKSPACE/.mirrobot_files/incremental_diff.txt" ] || touch "$GITHUB_WORKSPACE/.mirrobot_files/incremental_diff.txt"
 
522
 
523
 
524
  - name: Assemble Review Prompt
 
531
  PR_HEAD_SHA: ${{ env.PR_HEAD_SHA }}
532
  PULL_REQUEST_CONTEXT: ${{ env.PULL_REQUEST_CONTEXT }}
533
  run: |
534
+ # Build DIFF_FILE_PATH pointing to the generated diff in the repository workspace
 
535
  if [ "${{ steps.review_type.outputs.is_first_review }}" = "true" ]; then
536
+ DIFF_FILE_PATH="$GITHUB_WORKSPACE/.mirrobot_files/first_review_diff.txt"
537
  else
538
+ DIFF_FILE_PATH="$GITHUB_WORKSPACE/.mirrobot_files/incremental_diff.txt"
539
  fi
540
  # Substitute variables, embedding PR context and diff file path; DIFF_FILE_PATH kept local to this process
541
+ TMP_DIR="${RUNNER_TEMP:-/tmp}"
542
  VARS='${REVIEW_TYPE} ${PR_AUTHOR} ${IS_FIRST_REVIEW} ${PR_NUMBER} ${GITHUB_REPOSITORY} ${PR_HEAD_SHA} ${PULL_REQUEST_CONTEXT} ${DIFF_FILE_PATH}'
543
  DIFF_FILE_PATH="$DIFF_FILE_PATH" envsubst "$VARS" < /tmp/pr-review.md > "$TMP_DIR/assembled_prompt.txt"
544
  # Immediately clear large env after use