|
18 | 18 | # GITHUB_TOKEN Required. PAT with admin:org scope |
19 | 19 | # ORG Required. GitHub organization name |
20 | 20 | # REPO_NAME_FILTER Optional. Prefix filter for repository names (default: all repos) |
| 21 | +# SKIP_ARCHIVED Optional. Set to "true" to skip maintain/push/triage/pull permissions on |
| 22 | +# archived repositories; admin permissions are still applied (default: false) |
21 | 23 | # REPO_ADMIN Optional. Space-separated team slugs to grant admin access |
22 | 24 | # REPO_MAINTAIN Optional. Space-separated team slugs to grant maintain access |
23 | 25 | # REPO_PUSH Optional. Space-separated team slugs to grant push access |
@@ -50,6 +52,7 @@ GITHUB_TOKEN=${GITHUB_TOKEN:-''} |
50 | 52 | ORG=${ORG:-''} |
51 | 53 | API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'} |
52 | 54 | REPO_NAME_FILTER=${REPO_NAME_FILTER:-''} |
| 55 | +SKIP_ARCHIVED=${SKIP_ARCHIVED:-'false'} |
53 | 56 |
|
54 | 57 | # Permission-specific team variables (space-separated team slugs) |
55 | 58 | REPO_ADMIN=${REPO_ADMIN:-''} |
@@ -80,6 +83,9 @@ print_status "Organization: ${ORG}" |
80 | 83 | if [ -n "${REPO_NAME_FILTER}" ]; then |
81 | 84 | print_status "Repository filter: ${REPO_NAME_FILTER}*" |
82 | 85 | fi |
| 86 | +if [ "${SKIP_ARCHIVED}" = "true" ]; then |
| 87 | + print_status "Skipping non-admin permissions on archived repositories" |
| 88 | +fi |
83 | 89 |
|
84 | 90 | is_excluded () { |
85 | 91 | local REPO_NAME=$1 |
@@ -146,19 +152,26 @@ process_repos () { |
146 | 152 | err "$(echo "${repos_json}" | jq -r '.message // "unknown error"')" |
147 | 153 | fi |
148 | 154 |
|
149 | | - while IFS= read -r REPO; do |
| 155 | + while IFS=$'\t' read -r REPO ARCHIVED; do |
150 | 156 | [ -z "${REPO}" ] && continue |
151 | 157 | print_status "Processing repo ${REPO}" |
152 | 158 |
|
| 159 | + # Admin access is always granted, even on archived repos (e.g. so |
| 160 | + # platform teams retain settings access after archival). |
153 | 161 | apply_level "${REPO}" "admin" "${REPO_ADMIN}" "${REPO_ADMIN_EXCLUDE}" |
154 | | - apply_level "${REPO}" "maintain" "${REPO_MAINTAIN}" "${REPO_MAINTAIN_EXCLUDE}" |
155 | | - apply_level "${REPO}" "push" "${REPO_PUSH}" "${REPO_PUSH_EXCLUDE}" |
156 | | - apply_level "${REPO}" "triage" "${REPO_TRIAGE}" "${REPO_TRIAGE_EXCLUDE}" |
157 | | - apply_level "${REPO}" "pull" "${REPO_PULL}" "${REPO_PULL_EXCLUDE}" |
| 162 | + |
| 163 | + if [ "${SKIP_ARCHIVED}" = "true" ] && [ "${ARCHIVED}" = "true" ]; then |
| 164 | + print_status " Skipping non-admin permissions on ${REPO} (archived)" |
| 165 | + else |
| 166 | + apply_level "${REPO}" "maintain" "${REPO_MAINTAIN}" "${REPO_MAINTAIN_EXCLUDE}" |
| 167 | + apply_level "${REPO}" "push" "${REPO_PUSH}" "${REPO_PUSH_EXCLUDE}" |
| 168 | + apply_level "${REPO}" "triage" "${REPO_TRIAGE}" "${REPO_TRIAGE_EXCLUDE}" |
| 169 | + apply_level "${REPO}" "pull" "${REPO_PULL}" "${REPO_PULL_EXCLUDE}" |
| 170 | + fi |
158 | 171 |
|
159 | 172 | # Add delay to prevent hitting GitHub rate limit |
160 | 173 | sleep 5 |
161 | | - done < <(echo "${repos_json}" | jq -r --arg filter "${REPO_NAME_FILTER}" 'sort_by(.name) | .[] | select(.name | startswith($filter)) | .name') |
| 174 | + done < <(echo "${repos_json}" | jq -r --arg filter "${REPO_NAME_FILTER}" 'sort_by(.name) | .[] | select(.name | startswith($filter)) | [.name, (.archived // false | tostring)] | @tsv') |
162 | 175 | done |
163 | 176 | } |
164 | 177 |
|
|
0 commit comments