@@ -169,7 +169,7 @@ jobs:
169169 if gh api orgs/$OWNER/teams/$CODEOWNERS_TEAM > /dev/null 2>&1; then
170170 echo "Assigning permissions to CODEOWNERS_TEAM: [$CODEOWNERS_TEAM]"
171171 gh api orgs/$OWNER/teams/$CODEOWNERS_TEAM/repos/$OWNER/$REPO_NAME \
172- -X PUT -H "Accept: application/vnd.github+json" -f permission=write || \
172+ -X PUT -H "Accept: application/vnd.github+json" -f permission=write --verbose || \
173173 echo "::error::Failed to set permissions for $CODEOWNERS_TEAM. Please check team and repository availability."
174174 else
175175 echo "::error::Team $CODEOWNERS_TEAM does not exist. Cannot assign permissions."
@@ -197,31 +197,31 @@ jobs:
197197
198198 - name : Sync rulesets from template repository
199199 run : |
200- TEMPLATE_REPO=$(basename "${{ github.repository }}")
201- echo "Fetching rulesets from $OWNER/$TEMPLATE_REPO"
202-
203- # Fetch rulesets once and store them in a variable
204- RULESETS=$(gh api repos/$OWNER/$TEMPLATE_REPO/rulesets \
205- -H "Accept: application/vnd.github+json" 2>/dev/null || echo "[]")
206- if ! echo "$RULESETS" | jq -e 'type == "array" and length > 0' > /dev/null; then
207- echo "No valid rulesets array found in template repository. Skipping."
208- exit 0
209- fi
210-
211- # Process the fetched rulesets
212- # debug only
213- echo "$RULESETS" | jq -c '.[]' | while read -r ruleset; do
214- NAME=$(echo "$ruleset " | jq -r '.name')
215- echo "Syncing ruleset: $NAME"
216- PAYLOAD=$(echo "$ruleset" | jq '{name, enforcement, conditions, bypass_actors, rules, target, targets}')
217- echo "$PAYLOAD " | jq
218- echo "$PAYLOAD" > ruleset.json
219-
220- gh api repos/$OWNER/$REPO_NAME/rulesets \
221- -X POST \
222- -H "Accept: application/vnd.github+json" --verbose \
223- --input ruleset.json || echo "Warning: Failed to apply ruleset $NAME"
224- done
200+ TEMPLATE_REPO=$(basename "${{ github.repository }}")
201+ echo "Fetching rulesets from $OWNER/$TEMPLATE_REPO"
202+
203+ RULESETS=$(gh api repos/$OWNER/$TEMPLATE_REPO/ rulesets \
204+ -H "Accept: application/vnd.github+json" 2>/dev/null || echo "[]")
205+
206+ if ! echo "$RULESETS" | jq -e 'type == "array" and length > 0' > /dev/null; then
207+ echo "No valid rulesets array found in template repository. Skipping."
208+ exit 0
209+ fi
210+
211+ echo "$RULESETS" | jq -r '.[].id' | while read -r ruleset_id; do
212+ RULESET=$(gh api repos/$OWNER/$TEMPLATE_REPO/rulesets/$ruleset_id \
213+ -H "Accept: application/vnd.github+json")
214+ NAME=$(echo "$RULESET " | jq -r '.name')
215+ echo "Syncing full ruleset: $NAME"
216+
217+ PAYLOAD=$( echo "$RULESET " | jq 'del(.id, .repository_id, .creator, .created_at, .updated_at)')
218+ echo "$PAYLOAD" > ruleset.json
219+
220+ gh api repos/$OWNER/$REPO_NAME/rulesets \
221+ -X POST \
222+ -H "Accept: application/vnd.github+json" \
223+ --input ruleset.json || echo "Warning: Failed to apply ruleset $NAME"
224+ done
225225
226226 - name : Create initial issues
227227 run : |
0 commit comments