@@ -52,6 +52,7 @@ TOKEN_TYPE="app"
5252GHES_HOST=" "
5353APP_ID=" "
5454APP_PEM=" "
55+ BASE_BRANCH=" main"
5556DRY_RUN=false
5657
5758# ─── colours ─────────────────────────────────────────────────────────────────
@@ -115,14 +116,15 @@ _tag_ruleset_ui_instructions() {
115116# ─── argument parsing ─────────────────────────────────────────────────────────
116117while [[ $# -gt 0 ]]; do
117118 case " $1 " in
118- --owner) OWNER=" $2 " ; shift 2 ;;
119- --repo) REPO=" $2 " ; shift 2 ;;
120- --scope) SCOPE=" $2 " ; shift 2 ;;
121- --token-type) TOKEN_TYPE=" $2 " ; shift 2 ;;
122- --ghes-host) GHES_HOST=" $2 " ; shift 2 ;;
123- --app-id) APP_ID=" $2 " ; shift 2 ;;
124- --app-pem) APP_PEM=" $2 " ; shift 2 ;;
125- --dry-run) DRY_RUN=true; shift ;;
119+ --owner) OWNER=" $2 " ; shift 2 ;;
120+ --repo) REPO=" $2 " ; shift 2 ;;
121+ --scope) SCOPE=" $2 " ; shift 2 ;;
122+ --token-type) TOKEN_TYPE=" $2 " ; shift 2 ;;
123+ --ghes-host) GHES_HOST=" $2 " ; shift 2 ;;
124+ --app-id) APP_ID=" $2 " ; shift 2 ;;
125+ --app-pem) APP_PEM=" $2 " ; shift 2 ;;
126+ --base-branch) BASE_BRANCH=" $2 " ; shift 2 ;;
127+ --dry-run) DRY_RUN=true; shift ;;
126128 -h|--help)
127129 print_help
128130 exit 0
@@ -167,8 +169,42 @@ echo -e " Token type: ${TOKEN_TYPE}"
167169[[ " ${DRY_RUN} " == true ]] && echo -e " ${YELLOW} DRY RUN — no changes will be made${RESET} "
168170echo " "
169171
172+ # ── Step 0: .changeset/config.json ───────────────────────────────────────────
173+ header " Step 0/5 — .changeset/config.json"
174+
175+ CHANGESET_CONFIG=" .changeset/config.json"
176+
177+ if [[ -f " ${CHANGESET_CONFIG} " ]]; then
178+ current_repo=" $( python3 -c " import json,sys; d=json.load(open('${CHANGESET_CONFIG} ')); cfg=d.get('changelog'); print(cfg[1]['repo'] if isinstance(cfg,list) else '')" 2> /dev/null || true) "
179+
180+ if [[ " ${current_repo} " == " ${FULL_REPO} " ]]; then
181+ success " .changeset/config.json already points to ${FULL_REPO} — skipping."
182+ else
183+ info " Patching .changeset/config.json: repo → ${FULL_REPO} , baseBranch → ${BASE_BRANCH} "
184+ if [[ " ${DRY_RUN} " == true ]]; then
185+ dry " python3: update changelog[1].repo=${FULL_REPO} , baseBranch=${BASE_BRANCH} in ${CHANGESET_CONFIG} "
186+ else
187+ python3 - << PYEOF
188+ import json, sys
189+ with open("${CHANGESET_CONFIG} ") as f:
190+ d = json.load(f)
191+ if isinstance(d.get("changelog"), list) and len(d["changelog"]) > 1 and isinstance(d["changelog"][1], dict):
192+ d["changelog"][1]["repo"] = "${FULL_REPO} "
193+ d["baseBranch"] = "${BASE_BRANCH} "
194+ with open("${CHANGESET_CONFIG} ", "w") as f:
195+ json.dump(d, f, indent=2)
196+ f.write("\n")
197+ PYEOF
198+ success " .changeset/config.json updated."
199+ fi
200+ fi
201+ else
202+ warning " .changeset/config.json not found — run 'npx changeset init' first, then re-run this script."
203+ fi
204+
170205# ── Step 1: branch ruleset ────────────────────────────────────────────────────
171- header " Step 1/4 — Branch ruleset (protect main)"
206+
207+ header " Step 1/5 — Branch ruleset (protect main)"
172208
173209BRANCH_RULESET_NAME=" Protect main branch"
174210
@@ -220,7 +256,7 @@ ENDJSON
220256fi
221257
222258# ── Step 2: tag ruleset ───────────────────────────────────────────────────────
223- header " Step 2/4 — Tag ruleset (protect v* tags)"
259+ header " Step 2/5 — Tag ruleset (protect v* tags)"
224260
225261TAG_RULESET_NAME=" Protect release tags"
226262
@@ -273,7 +309,7 @@ ENDJSON
273309fi
274310
275311# ── Step 3: skip-changeset label ──────────────────────────────────────────────
276- header " Step 3/4 — GitHub label: skip-changeset"
312+ header " Step 3/5 — GitHub label: skip-changeset"
277313
278314if label_exists " skip-changeset" ; then
279315 success " Label 'skip-changeset' already exists — skipping."
294330fi
295331
296332# ── Step 4: secrets guidance ──────────────────────────────────────────────────
297- header " Step 4/4 — Repository secrets"
333+ header " Step 4/5 — Repository secrets"
298334
299335_check_secret () {
300336 local secret_name=" $1 "
0 commit comments