Skip to content

Commit 3c51b57

Browse files
committed
perf: make general settings a static file
1 parent 307cb98 commit 3c51b57

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

.github/workflows/admin_update_repo_settings.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
admin-update-tf-module-rulesets:
3434
name: 'GitHub: Update tf-module Rulesets'
3535
runs-on: ubuntu-latest
36+
if: ${{ github.ref_name != 'prod' }}
3637
steps:
3738
- name: Checkout repository
3839
uses: actions/checkout@v4

admin/repo_static/general.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"has_issues": true,
3+
"has_wiki": false,
4+
"has_projects": false,
5+
"allow_squash_merge": true,
6+
"allow_merge_commit": true,
7+
"allow_rebase_merge": false,
8+
"allow_auto_merge": false,
9+
"allow_update_branch": true,
10+
"delete_branch_on_merge": true
11+
}

admin/update_repo_settings.sh

+6-24
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function create_ruleset() {
2424
REPOSITORY_NAME=${2}
2525
ENVIRONMENT_NAME=${3}
2626

27-
echo "Creating ruleset for ${REPOSITORY_NAME} - ${ENVIRONMENT_NAME}"
27+
echo "Creating ruleset for ${ENVIRONMENT_NAME} - ${REPOSITORY_OWNER}/${REPOSITORY_NAME}"
2828

2929
RULESET_CONTENT=$(echo $(sed \
3030
-e "s|\${ENVIRONMENT_NAME}|${ENVIRONMENT_NAME}|g" \
@@ -46,7 +46,7 @@ function update_ruleset() {
4646
ENVIRONMENT_NAME=${3}
4747
RULESET_ID=${4}
4848

49-
echo "Updating ruleset for ${REPOSITORY_NAME} - ${ENVIRONMENT_NAME}"
49+
echo "Updating ruleset for ${ENVIRONMENT_NAME} - ${REPOSITORY_OWNER}/${REPOSITORY_NAME}"
5050

5151
RULESET_CONTENT=$(echo $(sed \
5252
-e "s|\${ENVIRONMENT_NAME}|${ENVIRONMENT_NAME}|g" \
@@ -65,54 +65,37 @@ function update_ruleset() {
6565
function update_repo_general_settings() {
6666
REPOSITORY_OWNER=${1}
6767

68-
echo "::group::Updating repository settings"
68+
GENERAL_CONTENT=$(cat admin/repo_static/general.json)
6969
COMBINED_ARRAY=(${REPO_LIST_APP_IAC[@]} ${REPO_LIST_TF_IAC[@]} ${REPO_LIST_TF_MODULE[@]})
7070
for REPOSITORY_NAME in ${COMBINED_ARRAY[@]}; do
71-
echo "Updating ${REPOSITORY_OWNER}/${REPOSITORY_NAME}"
72-
gh api \
71+
echo "Updating general settings for ${REPOSITORY_OWNER}/${REPOSITORY_NAME}"
72+
echo "${GENERAL_CONTENT}" | gh api \
7373
--method PATCH \
7474
-H "Accept: application/vnd.github+json" \
7575
-H "X-GitHub-Api-Version: 2022-11-28" \
7676
/repos/${REPOSITORY_OWNER}/${REPOSITORY_NAME} \
77-
-F "has_issues=true" \
78-
-F "has_projects=false" \
79-
-F "has_wiki=false" \
80-
-F "allow_squash_merge=true" \
81-
-F "allow_merge_commit=true" \
82-
-F "allow_rebase_merge=false" \
83-
-F "allow_auto_merge=false" \
84-
-F "delete_branch_on_merge=true" \
85-
-F "allow_update_branch=true" 1>/dev/null
77+
--input - 1>/dev/null
8678
done
87-
echo "::endgroup::"
8879
}
8980

9081
function update_tf_module_rulesets() {
9182
REPOSITORY_OWNER=${1}
9283
ENVIRONMENT_NAME=${2}
9384

94-
echo "::group::tf-module repository rulesets"
9585
for REPOSITORY_NAME in ${REPO_LIST_TF_MODULE[@]}; do
96-
if [ "${ENVIRONMENT_NAME}" = "prod" ]; then
97-
# Module repositories do not need a prod ruleset
98-
continue
99-
fi
100-
10186
ruleset_id=$(get_ruleset_by_name ${REPOSITORY_OWNER} ${REPOSITORY_NAME} ${ENVIRONMENT_NAME})
10287
if [ -z "${ruleset_id}" ]; then
10388
create_ruleset ${REPOSITORY_OWNER} ${REPOSITORY_NAME} ${ENVIRONMENT_NAME}
10489
else
10590
update_ruleset ${REPOSITORY_OWNER} ${REPOSITORY_NAME} ${ENVIRONMENT_NAME} ${ruleset_id}
10691
fi
10792
done
108-
echo "::endgroup::"
10993
}
11094

11195
function update_tf_iac_rulesets() {
11296
REPOSITORY_OWNER=${1}
11397
ENVIRONMENT_NAME=${2}
11498

115-
echo "::group::app-tf-iac repository rulesets"
11699
COMBINED_ARRAY=(${REPO_LIST_APP_IAC[@]} ${REPO_LIST_TF_IAC[@]})
117100
for REPOSITORY_NAME in ${COMBINED_ARRAY[@]}; do
118101
ruleset_id=$(get_ruleset_by_name ${REPOSITORY_OWNER} ${REPOSITORY_NAME} ${ENVIRONMENT_NAME})
@@ -122,5 +105,4 @@ function update_tf_iac_rulesets() {
122105
update_ruleset ${REPOSITORY_OWNER} ${REPOSITORY_NAME} ${ENVIRONMENT_NAME} ${ruleset_id}
123106
fi
124107
done
125-
echo "::endgroup::"
126108
}

0 commit comments

Comments
 (0)