@@ -182,6 +182,17 @@ check_pr_status() {
182182
183183 debug_log " GitHub API response received"
184184
185+ # Check for authentication errors
186+ local auth_error
187+ auth_error=$( echo " $pr_response " | grep -o ' "message":[[:space:]]*"[^"]*"' | sed ' s/"message":[[:space:]]*"\([^"]*\)"/\1/' )
188+
189+ if [ " $auth_error " = " Bad credentials" ]; then
190+ echo " → GitHub authentication failed (bad credentials), skipping PR cleanup for all namespaces"
191+ debug_log " GitHub authentication failed - bad credentials"
192+ export GITHUB_AUTH_FAILED=true
193+ return 1
194+ fi
195+
185196 # Check if PR exists and get its state
186197 local pr_state
187198 pr_state=$( echo " $pr_response " | grep -o ' "state":[[:space:]]*"[^"]*"' | sed ' s/"state":[[:space:]]*"\([^"]*\)"/\1/' )
@@ -298,8 +309,8 @@ kubectl get namespaces \
298309 debug_log " Age-based cleanup triggered"
299310 fi
300311
301- # Check PR-based cleanup if enabled
302- if [ " $PR_CLEANUP_ENABLED " = " true" ]; then
312+ # Check PR-based cleanup if enabled and GitHub auth is working
313+ if [ " $PR_CLEANUP_ENABLED " = " true" ] && [ " $GITHUB_AUTH_FAILED " != " true " ] ; then
303314 if check_pr_status " $namespace " ; then
304315 should_cleanup=true
305316 if [ -n " $cleanup_reason " ]; then
@@ -309,6 +320,9 @@ kubectl get namespaces \
309320 fi
310321 debug_log " PR-based cleanup triggered: $PR_CLEANUP_REASON "
311322 fi
323+ elif [ " $PR_CLEANUP_ENABLED " = " true" ] && [ " $GITHUB_AUTH_FAILED " = " true" ]; then
324+ echo " → Skipping PR-based cleanup due to GitHub authentication failure"
325+ debug_log " Skipping PR cleanup due to GitHub auth failure"
312326 fi
313327
314328 if [ " $should_cleanup " = " true" ]; then
@@ -370,4 +384,3 @@ kubectl get namespaces \
370384
371385debug_log " Namespace processing completed"
372386echo " Renku CI deployment cleanup completed"
373-
0 commit comments