diff --git a/gh-repo-config b/gh-repo-config index 52ff0eb..34ce4e6 100755 --- a/gh-repo-config +++ b/gh-repo-config @@ -15,65 +15,45 @@ else _GH="gh" fi -JSON_REPO=$( +JSON_REPO_Q=$( cat <<'EOL' { - "allow_auto_merge": false, - "allow_merge_commit": false, - "allow_rebase_merge": false, - "allow_squash_merge": true, - "allow_update_branch": true, - "default_branch": "main", - "delete_branch_on_merge": true, - "description": "", - "has_issues": true, - "has_projects": true, - "has_wiki": true, - "homepage": "", - "security_and_analysis": { - "advanced_security": { - "status": "enabled" - }, - "secret_scanning": { - "status": "enabled" - } - }, - "squash_merge_commit_message": "BLANK", - "squash_merge_commit_title": "PR_TITLE", - "web_commit_signoff_required": false + "name": .name, + "description": .description, + "homepage": .homepage, + "private": .private, + "visibility": .visibility, + "has_issues": .has_issues, + "has_projects": .has_projects, + "has_wiki": .has_wiki, + "default_branch": .default_branch, + "allow_squash_merge": .allow_squash_merge, + "allow_merge_commit": .allow_merge_commit, + "allow_rebase_merge": .allow_rebase_merge, + "allow_auto_merge": .allow_auto_merge, + "delete_branch_on_merge": .delete_branch_on_merge, + "allow_update_branch": .allow_update_branch, + "use_squash_pr_title_as_default": .use_squash_pr_title_as_default, + "archived": .archived, + "web_commit_signoff_required": .web_commit_signoff_required } EOL ) -JSON_TOPICS=$( +JSON_BRANCH_PROTECTION_Q=$( cat <<'EOL' { - "names": [] -} -EOL -) - -JSON_BRANCH_PROTECTION=$( - cat <<'EOL' -{ - "allow_force_pushes": false, - "allow_deletions": false, - "block_creations": false, - "enforce_admins": false, - "required_conversation_resolution": false, - "required_linear_history": true, - "required_pull_request_reviews": { - "dismiss_stale_reviews": true, - "require_code_owner_reviews": true, - "required_approving_review_count": 1, - "require_last_push_approval": false - }, - "required_signatures": true, - "required_status_checks": { - "strict": true, - "checks": [] - }, - "restrictions": null + "enforce_admins": .enforce_admins.enabled, + "required_pull_request_reviews": .required_pull_request_reviews, + "required_status_checks": .required_status_checks, + "restrictions": .restrictions, + "required_linear_history": .required_linear_history.enabled, + "allow_force_pushes": .allow_force_pushes.enabled, + "allow_deletions": .allow_deletions.enabled, + "block_creations": .block_creations.enabled, + "required_conversation_resolution": .required_conversation_resolution.enabled, + "lock_branch": .lock_branch.enabled, + "allow_fork_syncing": .allow_fork_syncing.enabled } EOL ) @@ -91,7 +71,7 @@ log:action() { else local -r eol="\n" fi - printf "[%8s]: %s%b" "${action}" "${msg}" "${eol}" >/dev/stderr + printf "[%s]: %s%b" "${action}" "${msg}" "${eol}" >/dev/stderr } log:api() { @@ -163,12 +143,14 @@ app::help() { } app::init() { + local -r branch="$(git rev-parse --abbrev-ref HEAD)" log "Initializing config..." app::init_dir "${APP_CONFIG}" - app::init_file "${APP_CONFIG}/repo.json" "${JSON_REPO}" - app::init_file "${APP_CONFIG}/topics.json" "${JSON_TOPICS}" + echo "*" > "${APP_CONFIG}/.gitignore" + app::init_file_source "${APP_CONFIG}/repo.json" "/repos/:owner/:repo" "$JSON_REPO_Q" + app::init_file_source "${APP_CONFIG}/topics.json" "/repos/:owner/:repo/topics" "." app::init_dir "${APP_CONFIG}/branch-protection" - app::init_file "${APP_CONFIG}/branch-protection/main.json" "${JSON_BRANCH_PROTECTION}" + app::init_file_source "${APP_CONFIG}/branch-protection/${branch}.json" "/repos/:owner/:repo/branches/${branch}/protection" "$JSON_BRANCH_PROTECTION_Q" log "Done" } @@ -182,9 +164,9 @@ app::init_dir() { fi } -app::init_file() { +app::init_file_source() { local -r path="$1" - local -r content="$2" + local -r content="$(${_GH} api ${2} | jq "${3}")" if [ -f "${path}" ]; then log:action "warn" "${path} already exists!" if app::confirm "Overwrite?"; then