Skip to content

Commit 6cd2d44

Browse files
fix: correct error handling for git fetch operations
Co-authored-by: lionelvillard <6598801+lionelvillard@users.noreply.github.com>
1 parent c2b31cc commit 6cd2d44

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

.github/workflows/ci-e2e-openshift.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,23 @@ jobs:
294294
PR_NUM="${{ needs.gate.outputs.pr_number }}"
295295
if [ -n "$PR_NUM" ] && [ "$PR_NUM" != "" ]; then
296296
# Fetch PR details to get the base branch
297-
if BASE_REF=$(gh pr view "$PR_NUM" --json baseRefName --jq '.baseRefName' 2>&1); then
297+
if BASE_REF=$(gh pr view "$PR_NUM" --json baseRefName --jq '.baseRefName'); then
298298
echo "Detected base branch: $BASE_REF"
299-
if ! git fetch origin "$BASE_REF:$BASE_REF" 2>&1; then
300-
echo "Warning: Failed to fetch branch $BASE_REF, using origin/$BASE_REF reference"
299+
if git fetch origin "$BASE_REF:$BASE_REF" 2>&1; then
300+
echo "Successfully fetched branch $BASE_REF"
301+
else
302+
echo "Warning: Failed to fetch branch $BASE_REF, will use origin/$BASE_REF reference"
301303
fi
302304
echo "base=origin/$BASE_REF" >> $GITHUB_OUTPUT
303305
else
304-
echo "Warning: Failed to fetch PR details for PR #$PR_NUM: $BASE_REF"
306+
echo "Warning: Failed to fetch PR details for PR #$PR_NUM"
305307
# Fallback to default branch
306308
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
307309
echo "Using default branch: $DEFAULT_BRANCH"
308-
if ! git fetch origin "$DEFAULT_BRANCH:$DEFAULT_BRANCH" 2>&1; then
309-
echo "Warning: Failed to fetch default branch $DEFAULT_BRANCH, using origin/$DEFAULT_BRANCH reference"
310+
if git fetch origin "$DEFAULT_BRANCH:$DEFAULT_BRANCH" 2>&1; then
311+
echo "Successfully fetched default branch $DEFAULT_BRANCH"
312+
else
313+
echo "Warning: Failed to fetch default branch $DEFAULT_BRANCH, will use origin/$DEFAULT_BRANCH reference"
310314
fi
311315
echo "base=origin/$DEFAULT_BRANCH" >> $GITHUB_OUTPUT
312316
fi
@@ -315,8 +319,10 @@ jobs:
315319
# Fallback: use repository default branch
316320
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
317321
echo "Using default branch: $DEFAULT_BRANCH"
318-
if ! git fetch origin "$DEFAULT_BRANCH:$DEFAULT_BRANCH" 2>&1; then
319-
echo "Warning: Failed to fetch default branch $DEFAULT_BRANCH, using origin/$DEFAULT_BRANCH reference"
322+
if git fetch origin "$DEFAULT_BRANCH:$DEFAULT_BRANCH" 2>&1; then
323+
echo "Successfully fetched default branch $DEFAULT_BRANCH"
324+
else
325+
echo "Warning: Failed to fetch default branch $DEFAULT_BRANCH, will use origin/$DEFAULT_BRANCH reference"
320326
fi
321327
echo "base=origin/$DEFAULT_BRANCH" >> $GITHUB_OUTPUT
322328
fi

0 commit comments

Comments
 (0)