Dry run by default: the script reads from both hosts (tokens, owners, names, license, SSH) and prints a plan; --apply creates the repositories and the Gitea -> GitHub push mirror after a final yes. Choosing GitHub applies the AGPL-3.0 license to the Gitea repository. A failed step is reported with what exists and how to continue; nothing is ever deleted. create-project.sh is now the entry point; the work lives in src/lib/, one responsibility per file. .gitignore gets !src/lib (the Python template ignores any lib/ folder). Tests grow to 599 checks, with a stub curl and ssh, and guards for the file structure. Task: MIL-002#1 Task: MIL-002#2 Task: MIL-002#3 Task: MIL-002#4 Task: MIL-002#5 Task: MIL-002#6 Refs #9 Refs #10 Refs #11 Refs #12 Refs #13 Refs #14 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
48 lines
1.6 KiB
Bash
48 lines
1.6 KiB
Bash
# shellcheck shell=bash
|
|
# shellcheck disable=SC2004,SC2034,SC2154 # shared state and arrays are declared in constants.sh
|
|
# repositories.sh - Creating the GitHub and Gitea repositories.
|
|
#
|
|
# Part of create-project.sh: sourced by it, never run on its own.
|
|
#
|
|
# Provides: repo_body, create_repository
|
|
|
|
# repo_body HOST: the JSON body that creates the repository on HOST.
|
|
repo_body() {
|
|
local host="$1" description private=true extra=""
|
|
description="$(json_escape "${PROJECT[description]}")"
|
|
if [[ ${PROJECT[visibility]} != private ]]; then
|
|
private=false
|
|
fi
|
|
if [[ $host == github ]]; then
|
|
printf '{"name":"%s","description":"%s","private":%s,"auto_init":false}' \
|
|
"${PROJECT[name]}" "$description" "$private"
|
|
return 0
|
|
fi
|
|
if ((PROJECT[has_github])); then
|
|
extra=',"auto_init":true,"license":"'"$AGPL_LICENSE_KEY"'"'
|
|
else
|
|
extra=',"auto_init":false'
|
|
fi
|
|
printf '{"name":"%s","description":"%s","private":%s,"default_branch":"%s"%s}' \
|
|
"${PROJECT[name]}" "$description" "$private" "$DEFAULT_BRANCH" "$extra"
|
|
}
|
|
|
|
# create_repository HOST: create the repository, or reuse the existing one.
|
|
create_repository() {
|
|
local host="$1" label owner path
|
|
label="$(host_label "$host") repository"
|
|
owner="$(repo_owner "$host")"
|
|
if is_reused "$host"; then
|
|
finish_step "$label" "reused" "$(repo_url "$host")"
|
|
return 0
|
|
fi
|
|
begin_step "$label"
|
|
path="/user/repos"
|
|
if [[ ${STATE[${host}_owner_kind]} == organization ]]; then
|
|
path="/orgs/$owner/repos"
|
|
fi
|
|
api_call "$host" POST "$path" "$(repo_body "$host")"
|
|
expect_status "cannot create the $label" 201
|
|
finish_step "$label" "created" "$(repo_url "$host")"
|
|
}
|