You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
echo "Found existing PR #$PR_NUMBER, using existing base: $BASE_BRANCH"
246
-
echo "Skipping merge-base detection to avoid duplicate PRs on force push"
247
252
elif [ -n "${{ github.base_ref }}" ]; then
248
253
# For PRs, use the base branch directly
249
254
BASE_BRANCH="${{ github.base_ref }}"
250
255
echo "Using PR base branch: $BASE_BRANCH"
251
256
else
252
-
# No existing PR - for direct pushes, find the common ancestor branch
253
-
echo "No existing PR found, finding base branch via merge-base"
254
-
255
-
# Get all remote branches sorted by commit date (most recent first)
256
-
# This ensures we check actively developed branches first
257
-
CURRENT_COMMIT=$(git rev-parse HEAD)
258
-
BEST_BRANCH=""
259
-
CLOSEST_DISTANCE=999999
260
-
261
-
# Only check the 30 most recently updated branches for performance
262
-
for remote_branch in $(git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/remotes/origin/ | grep -v 'HEAD\|PR-CHECKER' | head -30); do
263
-
branch_name=$(echo "$remote_branch" | sed 's|^origin/||')
264
-
265
-
# Skip if it's the current branch
266
-
if [ "$branch_name" = "${{ github.ref_name }}" ]; then
267
-
continue
257
+
# Extract base branch from branch name pattern: {name}_base or {name}-base
258
+
# Match patterns like {shreeya}_ciqlts9_2 or {shreeya}-ciqlts9_2
259
+
if [[ "$BRANCH_NAME" =~ \{[^}]+\}[_-](.+) ]]; then
260
+
EXTRACTED_BASE="${BASH_REMATCH[1]}"
261
+
echo "Extracted base branch from branch name: $EXTRACTED_BASE"
262
+
263
+
# Validate against whitelist
264
+
if echo "$VALID_BASES" | grep -wq "$EXTRACTED_BASE"; then
265
+
BASE_BRANCH="$EXTRACTED_BASE"
266
+
echo "Base branch validated: $BASE_BRANCH"
267
+
else
268
+
echo "::error::Extracted base '$EXTRACTED_BASE' is not in whitelist: $VALID_BASES"
269
+
echo "::error::Valid base branches are: $VALID_BASES"
270
+
exit 1
268
271
fi
269
-
270
-
MERGE_BASE=$(git merge-base HEAD "$remote_branch" 2>/dev/null || echo "")
271
-
272
-
# Check if this branch shares history and isn't the current commit
273
-
if [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$CURRENT_COMMIT" ]; then
274
-
# Calculate distance (number of commits) from merge-base to current HEAD
0 commit comments