From d2d3d95117a262ca2d33f956334a4b83ff159535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nath=C3=A3=20Paulino?= Date: Wed, 28 Jun 2023 16:42:51 -0300 Subject: [PATCH] fix: Repo settings config on cortex-api (#10) * fix: Repo settings config on cortex-api * fix: Solve the problem when we have repos that don't have EXISTING_CHECKS for a specific branch --- entrypoint.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3d9a093..c2f6af8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -139,9 +139,17 @@ for repository in "${REPOSITORIES[@]}"; do -H "Content-Type: application/json" \ -u ${USERNAME}:${GITHUB_TOKEN} \ ${GITHUB_API_URL}/repos/${repository}/branches/${BRANCH_PROTECTION_NAME}/protection/required_status_checks) - - EXISTING_CHECKS=$(echo "$REQUIRED_STATUS_CHECKS" | jq -rc '.checks') + EXISTING_CHECKS=$(echo "$REQUIRED_STATUS_CHECKS" | jq -rc '.checks') + + if [ "$EXISTING_CHECKS" == "null" ]; then + echo "Check here the reason of there is no existing checks at this branch." + echo $( echo "$REQUIRED_STATUS_CHECKS" | jq -c '.message') + CURRENT_CHECKS=[] + else + CURRENT_CHECKS=$EXISTING_CHECKS; + fi; + # the argjson instead of just arg lets us pass the values not as strings jq -n \ --argjson enforceAdmins $BRANCH_PROTECTION_ENFORCE_ADMINS \ @@ -149,7 +157,7 @@ for repository in "${REPOSITORIES[@]}"; do --argjson codeOwnerReviews $BRANCH_PROTECTION_CODE_OWNERS \ --argjson reviewCount $BRANCH_PROTECTION_REQUIRED_REVIEWERS \ --argjson requiredStatusChecks $BRANCH_PROTECTION_REQUIRED_STATUS_CHECKS \ - --argjson existingChecks "$EXISTING_CHECKS" \ + --argjson existingChecks "$CURRENT_CHECKS" \ --arg restrictPushesTeamAllowed $BRANCH_PROTECTION_RESTRICT_PUSHES_TEAM_ALLOWED \ '{ required_status_checks:{