ai-cfia / devops

The DevOps Repository from the AI-CFIA serves as a centralized hub for scripts, configurations, and documentation for DevOps.
MIT License
1 stars 0 forks source link

As a Devops, I would like to be able to use the script to automate branch protection ruleset #33

Closed SonOfLope closed 8 months ago

SonOfLope commented 8 months ago

When executing the script, we get the following errors :

"Invalid request.\n\nNo subschema in \"anyOf\" matched.\n\"restrictions\" wasn't supplied.\nFor 'items', \"lint-test / lint-test\" is not an object.\nNot all subschemas of \"allOf\" matched.\nFor 'anyOf/1', {\"strict\"=>true, \"checks\"=>[\"lint-test / lint-test\"]} is not a null.",
  "documentation_url": "https://docs.github.com/rest/branches/branch-protection#update-branch-protection"

Looking at the documentation, required_status_checks requires a "context" key and not a "checks" key

       "required_status_checks": {
            "strict": true,
            "checks": ["lint-test / lint-test"]
        },

Also, we are missing a comma at the end of "require_code_owner_reviews": true :

        "required_pull_request_reviews": {
            "required_approving_review_count": 1,
            "require_code_owner_reviews": true
        },

Which results in error parsing JSON.

We are also not getting all existing repositories when we do :

API_URL="https://api.github.com/orgs/${ORG_NAME}/repos?type=public"

# get list of all public repos
RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" \
    -H "Authorization: Bearer ${GITHUB_TOKEN}" \
    "${API_URL}")

REPOS=$(echo "${RESPONSE}" | jq -r '.[].full_name')

since GitHub's API paginates the responses. If we have more repositories than the default per-page limit (usually 30), not all repositories will be returned in a single API call.