From 3a384cbe4f4fe93ba480e3cfba133ec4c4a538e9 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Fri, 12 Apr 2024 10:58:26 -0400 Subject: [PATCH 1/2] Issue #112: Update scripts (already executed) with product teams --- github-management-script/add-team-to-repos.md | 8 +-- github-management-script/add-team-to-repos.sh | 55 ++++++++++++++----- .../codeowners-file-creation.md | 3 +- .../codeowners-file-creation.sh | 14 ++++- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/github-management-script/add-team-to-repos.md b/github-management-script/add-team-to-repos.md index 0ae4dd4..a8931af 100644 --- a/github-management-script/add-team-to-repos.md +++ b/github-management-script/add-team-to-repos.md @@ -10,7 +10,8 @@ that an administrative team is added to each repository. - **Automated Team Assignment:** Automatically adds a specified team to all repositories within a given GitHub organization. - **Dynamic Team Assignment:** The script assigns teams (`backend`, `frontend`, - `db`) dynamically based on the naming convention of the repositories. + `data`, `finesse`, `nachet`, `harvester`) dynamically based on the naming + convention of the repositories. - **Admin Team Enforcement:** Ensures that an administrative team is added to every repository, regardless of its naming convention. @@ -27,9 +28,8 @@ that an administrative team is added to each repository. 2. **Configuration:** - Open the script in your text editor. - - Fill in the `GITHUB_ORG`, `TEAM_PERMISSION` and - `ADMIN_TEAM_SLUG` variables with the appropriate values for your GitHub - organization and teams. + - Fill in the `GITHUB_ORG`, `TEAM_PERMISSION` and `ADMIN_TEAM_SLUG` variables + with the appropriate values for your GitHub organization and teams. 3. **Run the Script:** - Open your terminal and navigate to the directory containing the script. diff --git a/github-management-script/add-team-to-repos.sh b/github-management-script/add-team-to-repos.sh index 405b226..4d06436 100755 --- a/github-management-script/add-team-to-repos.sh +++ b/github-management-script/add-team-to-repos.sh @@ -12,10 +12,12 @@ add_team_to_repo() { local org=$2 local repo=$3 local permission=$4 - local owner=$5 - - curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" \ - "https://api.github.com/orgs/${org}/teams/${team_slug}/repos/${owner}/${repo}" \ + curl -L \ + -X PUT \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/orgs/${org}/teams/${team_slug}/repos/${repo}" \ -d "{\"permission\":\"${permission}\"}" } @@ -40,21 +42,46 @@ while :; do TEAM_SLUG='backend' elif [[ "${REPO}" == *frontend* ]]; then TEAM_SLUG='frontend' - elif [[ "${REPO}" == *db* ]]; then - TEAM_SLUG='db' - else - TEAM_SLUG='devops' fi - echo "Adding team \"${TEAM_SLUG}\" to repo \"${REPO}\" with permission \"${TEAM_PERMISSION}\"" - add_team_to_repo "${TEAM_SLUG}" "${ORG_NAME}" "${REPO}" "${TEAM_PERMISSION}" + if [[ "${REPO}" == *db* ]] || [[ "${REPO}" == *data* ]]; then + TEAM_SLUG='data' + fi + + if [[ "${REPO}" == *nachet* ]]; then + PRODUCT_SLUG='nachet' + elif [[ "${REPO}" == *finesse* ]]; then + PRODUCT_SLUG='finesse' + elif [[ "${REPO}" == *harvester* ]]; then + PRODUCT_SLUG='harvester' + fi + + if [[ "${TEAM_SLUG}" != '' ]]; then + echo "Adding team \"${TEAM_SLUG}\" to repo \"${REPO}\" with permission \"${TEAM_PERMISSION}\"" + add_team_to_repo "${TEAM_SLUG}" "${ORG_NAME}" "${REPO}" "${TEAM_PERMISSION}" - if [[ "${TEAM_SLUG}" != "${ADMIN_TEAM_SLUG}" ]]; then - echo "Adding team \"${ADMIN_TEAM_SLUG}\" to repo \"${REPO}\" with permission \"${TEAM_PERMISSION}\"" - add_team_to_repo "${ADMIN_TEAM_SLUG}" "${ORG_NAME}" "${REPO}" "${TEAM_PERMISSION}" + if [[ "${TEAM_SLUG}" != "${ADMIN_TEAM_SLUG}" ]]; then + echo "Adding team \"${ADMIN_TEAM_SLUG}\" to repo \"${REPO}\" with permission \"${TEAM_PERMISSION}\"" + add_team_to_repo "${ADMIN_TEAM_SLUG}" "${ORG_NAME}" "${REPO}" "${TEAM_PERMISSION}" + else + echo "... Skipped adding team \"${ADMIN_TEAM_SLUG}\" as it is the same as \"${TEAM_SLUG}\"" + fi else - echo "... Skipped adding team \"${ADMIN_TEAM_SLUG}\" as it is the same as \"${TEAM_SLUG}\"" + echo "Skipping.. No team found for repo \"${REPO}\"" fi + + if [[ "${PRODUCT_SLUG}" != '' ]]; then + echo "Adding product team \"${PRODUCT_SLUG}\" to repo \"${REPO}\" with permission \"${TEAM_PERMISSION}\"" + add_team_to_repo "${PRODUCT_SLUG}" "${ORG_NAME}" "${REPO}" "${TEAM_PERMISSION}" + else + echo "Skipping.. No product team found for repo \"${REPO}\"" + fi + + echo "Adding team devops to repo \"${REPO}\" with permission \"${TEAM_PERMISSION}\"" + add_team_to_repo "devops" "${ORG_NAME}" "${REPO}" "${TEAM_PERMISSION}" + + TEAM_SLUG='' + PRODUCT_SLUG='' done ((PAGE++)) diff --git a/github-management-script/codeowners-file-creation.md b/github-management-script/codeowners-file-creation.md index 492abcc..0e51dbd 100644 --- a/github-management-script/codeowners-file-creation.md +++ b/github-management-script/codeowners-file-creation.md @@ -8,7 +8,8 @@ the CFIA organization and applies tag rules based on repository names. * **Creates CODEOWNERS Files:** The script generates CODEOWNERS files in target repositories, defining code ownership rules to streamline the review process. * **Customizable Team Tagging:** It tags relevant teams (`backend`, `frontend`, - `data`, `devops`) based on the repository name. + `data`, `devops`, `finesse`, `harvester`, `nachet`) based on the repository + name. * **DevOps Ownership:** The script assigns specific ownership to the DevOps team for files within the `.github` directory, Dockerfile, and docker-compose configurations. diff --git a/github-management-script/codeowners-file-creation.sh b/github-management-script/codeowners-file-creation.sh index d084c0b..783ccad 100755 --- a/github-management-script/codeowners-file-creation.sh +++ b/github-management-script/codeowners-file-creation.sh @@ -9,10 +9,20 @@ generate_codeowners() { content+="* @ai-cfia/backend\n" elif [[ ${repo_name} == *"frontend"* ]]; then content+="* @ai-cfia/frontend\n" - elif [[ ${repo_name} == *"db"* ]]; then + fi + + if [[ ${repo_name} == *"db"* ]]; then content+="* @ai-cfia/data\n" fi + if [[ "${repo_name}" == *nachet* ]]; then + content+="* @ai-cfia/nachet\n" + elif [[ "${repo_name}" == *finesse* ]]; then + content+="* @ai-cfia/finesse\n" + elif [[ "${repo_name}" == *harvester* ]]; then + content+="* @ai-cfia/harvester\n" + fi + content+="/.github/ @ai-cfia/devops\n" content+="Dockerfile @ai-cfia/devops\n" content+="docker-compose.yml @ai-cfia/devops\n" @@ -43,7 +53,7 @@ create_codeowners() { local json_data if [[ -n "${sha}" ]]; then # If the file exists, include the SHA in the request to update it - json_data="{\"message\": \"Update CODEOWNERS file with EOF line\", \"content\": \"${encoded_content}\", \"sha\": \"${sha}\"}" + json_data="{\"message\": \"Update CODEOWNERS file\", \"content\": \"${encoded_content}\", \"sha\": \"${sha}\"}" else # If the file doesn't exist, the SHA is not required json_data="{\"message\": \"Add CODEOWNERS file\", \"content\": \"${encoded_content}\"}" From 0430ef58168d84e57f25d52bfba3bce30f2e6ac5 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Fri, 12 Apr 2024 11:10:05 -0400 Subject: [PATCH 2/2] Issue #112: fix markdown violation --- github-management-script/codeowners-file-creation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-management-script/codeowners-file-creation.md b/github-management-script/codeowners-file-creation.md index 0e51dbd..4ce2e18 100644 --- a/github-management-script/codeowners-file-creation.md +++ b/github-management-script/codeowners-file-creation.md @@ -21,7 +21,7 @@ the CFIA organization and applies tag rules based on repository names. ## Usage 1. **Set Environment Variables:** - 1. `GITHUB_TOKEN`: Store your GitHub PAT in this environment variable. + 1. `GITHUB_TOKEN`: Store your GitHub PAT in this environment variable. 2. `ORG_NAME`: Set this to the name of your target GitHub organization. 2. **Execute the Script:** Run the script. It will: 1. Prompt for your GitHub token (if not set).