Skip to content

Commit 6461e8d

Browse files
feat: add environment variables to control context inclusion
Adds the following environment variables to reduce token usage: - INCLUDE_PREVIOUS_REVIEWS (default: true) - INCLUDE_HUMAN_COMMENTS (default: true) - INCLUDE_CHECK_RUNS (default: true) - INCLUDE_LABELS (default: true) - INCLUDE_PR_DESCRIPTION (default: true) - INCLUDE_COMMIT_MESSAGES (default: true) Set any to 'false' to exclude that context and reduce token count. This helps handle large PRs that would otherwise exceed model context limits.
1 parent 57e2d7a commit 6461e8d

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

ai-reviewer.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ AI_MAX_TOKENS="${AI_MAX_TOKENS:-64000}"
3232
MAX_DIFF_SIZE="${MAX_DIFF_SIZE:-5000000}" # 5MB default limit (allows large PRs while preventing excessive API usage)
3333
EXCLUDE_FILE_PATTERNS="${EXCLUDE_FILE_PATTERNS:-*.lock,*.min.js,*.min.css,package-lock.json,yarn.lock}"
3434

35+
# Context inclusion options (set to 'false' to disable, reduces token usage)
36+
INCLUDE_PREVIOUS_REVIEWS="${INCLUDE_PREVIOUS_REVIEWS:-true}"
37+
INCLUDE_HUMAN_COMMENTS="${INCLUDE_HUMAN_COMMENTS:-true}"
38+
INCLUDE_CHECK_RUNS="${INCLUDE_CHECK_RUNS:-true}"
39+
INCLUDE_LABELS="${INCLUDE_LABELS:-true}"
40+
INCLUDE_PR_DESCRIPTION="${INCLUDE_PR_DESCRIPTION:-true}"
41+
INCLUDE_COMMIT_MESSAGES="${INCLUDE_COMMIT_MESSAGES:-true}"
42+
3543
# Read diff content from stdin
3644
DIFF_CONTENT=$(cat)
3745

@@ -64,23 +72,23 @@ fi
6472

6573
# Fetch previous AI review (only the most recent one) for context
6674
PREVIOUS_REVIEWS=""
67-
if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
75+
if [ "$INCLUDE_PREVIOUS_REVIEWS" = "true" ] && [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
6876
# Fetch only the most recent AI review comment
6977
PREVIOUS_REVIEWS=$(gh api "repos/$REPO_FULL_NAME/issues/$PR_NUMBER/comments" \
7078
--jq '[.[] | select(.body | startswith("## AI Code Review"))] | last | if . then "### Previous AI Review (" + .created_at + "):\n" + .body + "\n---\n" else "" end' 2>/dev/null | head -c 10000 || echo "")
7179
fi
7280

7381
# Fetch human comments for context
7482
HUMAN_COMMENTS=""
75-
if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
83+
if [ "$INCLUDE_HUMAN_COMMENTS" = "true" ] && [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
7684
# Fetch comments from humans (not the bot)
7785
HUMAN_COMMENTS=$(gh api "repos/$REPO_FULL_NAME/issues/$PR_NUMBER/comments" \
7886
--jq '[.[] | select(.body | startswith("## AI Code Review") | not)] | map("**" + .user.login + "** (" + .created_at + "):\n" + .body) | join("\n\n---\n\n")' 2>/dev/null | head -c 20000 || echo "")
7987
fi
8088

8189
# Fetch GitHub Actions check runs status (if PR_NUMBER and REPO_FULL_NAME are set)
8290
CHECK_RUNS_STATUS=""
83-
if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
91+
if [ "$INCLUDE_CHECK_RUNS" = "true" ] && [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
8492
# Get the head SHA of the PR
8593
HEAD_SHA=$(gh api "repos/$REPO_FULL_NAME/pulls/$PR_NUMBER" --jq '.head.sha' 2>/dev/null || echo "")
8694

@@ -93,7 +101,7 @@ fi
93101

94102
# Fetch available repository labels (if PR_NUMBER and REPO_FULL_NAME are set)
95103
AVAILABLE_LABELS=""
96-
if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
104+
if [ "$INCLUDE_LABELS" = "true" ] && [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
97105
# Fetch all labels from the repository
98106
if [ "$DEBUG_MODE" = "true" ]; then
99107
echo "🔍 Fetching available labels from repository..." >&2
@@ -113,7 +121,7 @@ fi
113121

114122
# Fetch PR title and description
115123
PR_DESCRIPTION=""
116-
if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
124+
if [ "$INCLUDE_PR_DESCRIPTION" = "true" ] && [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
117125
if [ "$DEBUG_MODE" = "true" ]; then
118126
echo "🔍 Fetching PR title and description..." >&2
119127
fi
@@ -127,7 +135,7 @@ fi
127135

128136
# Fetch commit messages (limit to 15 most recent, exclude merges)
129137
COMMIT_MESSAGES=""
130-
if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
138+
if [ "$INCLUDE_COMMIT_MESSAGES" = "true" ] && [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
131139
if [ "$DEBUG_MODE" = "true" ]; then
132140
echo "🔍 Fetching commit messages..." >&2
133141
fi

0 commit comments

Comments
 (0)