Skip to content

Commit

Permalink
Issue #33: adds pagination to codeowners file creation and removes re…
Browse files Browse the repository at this point in the history
…quired_status_check
  • Loading branch information
SonOfLope committed Mar 6, 2024
1 parent b252474 commit 2e7ed2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
5 changes: 1 addition & 4 deletions github-management-script/branch-protection-ruleset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 20 additions & 9 deletions github-management-script/codeowners-file-creation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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

0 comments on commit 2e7ed2f

Please sign in to comment.