From 2e7ed2f79fd775c6dc0aadf2136e1fd7d1da3f78 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Wed, 6 Mar 2024 10:17:53 -0500 Subject: [PATCH] Issue #33: adds pagination to codeowners file creation and removes required_status_check --- .../branch-protection-ruleset.sh | 5 +--- .../codeowners-file-creation.sh | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/github-management-script/branch-protection-ruleset.sh b/github-management-script/branch-protection-ruleset.sh index 0d046b0..98a238f 100755 --- a/github-management-script/branch-protection-ruleset.sh +++ b/github-management-script/branch-protection-ruleset.sh @@ -35,10 +35,7 @@ set_branch_protection() { API_URL="https://api.github.com/repos/${REPO_NAME}/branches/${BRANCH_NAME}/protection" DATA='{ - "required_status_checks": { - "strict": true, - "contexts": ["lint-test / lint-test"] - }, + "required_status_checks": null, "enforce_admins": true, "required_pull_request_reviews": { "required_approving_review_count": 1, diff --git a/github-management-script/codeowners-file-creation.sh b/github-management-script/codeowners-file-creation.sh index 233d787..05ea593 100644 --- a/github-management-script/codeowners-file-creation.sh +++ b/github-management-script/codeowners-file-creation.sh @@ -31,7 +31,7 @@ create_codeowners() { API_URL="https://api.github.com/repos/${org_name}/${repo_name}/contents/.github/CODEOWNERS" curl -s -X PUT \ - -H "Accept: application/vnd.github.v3+json" \ + -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ -d "{\"message\": \"Add CODEOWNERS file\", \"content\": \"${encoded_content}\"}" \ "${API_URL}" @@ -41,15 +41,26 @@ echo "Please enter your GitHub token:" read -r GITHUB_TOKEN ORG_NAME="ai-cfia" -API_URL="https://api.github.com/orgs/${ORG_NAME}/repos?type=public" -RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - "${API_URL}") -REPOS=$(echo "${RESPONSE}" | jq -r '.[].full_name') +PAGE=1 +PER_PAGE=100 -for REPO in ${REPOS}; do - echo "Processing repository: ${REPO}" +while :; do + API_URL="https://api.github.com/orgs/${ORG_NAME}/repos?type=public&per_page=${PER_PAGE}&page=${PAGE}" + + RESPONSE=$(curl -s -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${API_URL}") - create_codeowners "$(dirname "${REPO}") $(basename "${REPO}")" + REPOS=$(echo "${RESPONSE}" | jq -r '.[].full_name') + + if [[ -z "${REPOS}" ]]; then + break + fi + + for REPO in ${REPOS}; do + echo "Processing repository: ${REPO}" + create_codeowners "${ORG_NAME}" "$(basename "${REPO}")" + done + ((PAGE++)) done