Skip to content

Commit 7a93c93

Browse files
committed
chore(setup): repo setup scripts to get default settings
1 parent 515f8e5 commit 7a93c93

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed

scripts/setup-repo.ps1

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#
2+
# Setup script for new CodingWithCalvin repositories
3+
# Run after creating a repo from a template
4+
#
5+
# Usage: .\setup-repo.ps1 <repo-name>
6+
# Example: .\setup-repo.ps1 VS-MyNewExtension
7+
#
8+
9+
param(
10+
[Parameter(Mandatory=$true, Position=0)]
11+
[string]$RepoName
12+
)
13+
14+
$ErrorActionPreference = "Stop"
15+
16+
$Org = "CodingWithCalvin"
17+
$FullRepo = "$Org/$RepoName"
18+
19+
Write-Host "Setting up repository: $FullRepo" -ForegroundColor Cyan
20+
Write-Host ""
21+
22+
# Check if repo exists
23+
$repoCheck = gh repo view $FullRepo 2>&1
24+
if ($LASTEXITCODE -ne 0) {
25+
Write-Host "Error: Repository $FullRepo not found" -ForegroundColor Red
26+
exit 1
27+
}
28+
29+
Write-Host "1. Configuring repository settings..." -ForegroundColor Yellow
30+
gh api "repos/$FullRepo" -X PATCH `
31+
-F has_issues=true `
32+
-F has_projects=false `
33+
-F has_wiki=false `
34+
-F has_discussions=true `
35+
-F allow_squash_merge=true `
36+
-F allow_merge_commit=false `
37+
-F allow_rebase_merge=false `
38+
-F delete_branch_on_merge=true `
39+
-F allow_auto_merge=false `
40+
-F web_commit_signoff_required=false `
41+
--silent
42+
43+
Write-Host " - Issues: enabled" -ForegroundColor Green
44+
Write-Host " - Projects: disabled" -ForegroundColor Green
45+
Write-Host " - Wiki: disabled" -ForegroundColor Green
46+
Write-Host " - Discussions: enabled" -ForegroundColor Green
47+
Write-Host " - Merge commits: disabled" -ForegroundColor Green
48+
Write-Host " - Rebase merge: disabled" -ForegroundColor Green
49+
Write-Host " - Squash merge: enabled" -ForegroundColor Green
50+
Write-Host " - Delete branch on merge: enabled" -ForegroundColor Green
51+
Write-Host ""
52+
53+
Write-Host "2. Creating branch ruleset..." -ForegroundColor Yellow
54+
55+
$rulesetJson = @'
56+
{
57+
"name": "PRs to Main",
58+
"target": "branch",
59+
"enforcement": "active",
60+
"bypass_actors": [
61+
{
62+
"actor_type": "OrganizationAdmin",
63+
"bypass_mode": "always"
64+
}
65+
],
66+
"conditions": {
67+
"ref_name": {
68+
"include": ["~DEFAULT_BRANCH"],
69+
"exclude": []
70+
}
71+
},
72+
"rules": [
73+
{"type": "deletion"},
74+
{"type": "non_fast_forward"},
75+
{
76+
"type": "pull_request",
77+
"parameters": {
78+
"required_approving_review_count": 1,
79+
"dismiss_stale_reviews_on_push": true,
80+
"require_code_owner_review": false,
81+
"require_last_push_approval": false,
82+
"required_review_thread_resolution": false,
83+
"allowed_merge_methods": ["squash"]
84+
}
85+
}
86+
]
87+
}
88+
'@
89+
90+
$rulesetJson | gh api "repos/$FullRepo/rulesets" -X POST --input - --silent
91+
92+
Write-Host " - Bypass: Organization Admins" -ForegroundColor Green
93+
Write-Host " - Prevent deletion: enabled" -ForegroundColor Green
94+
Write-Host " - Prevent force push: enabled" -ForegroundColor Green
95+
Write-Host " - Require PR: enabled" -ForegroundColor Green
96+
Write-Host " - Required approvals: 1" -ForegroundColor Green
97+
Write-Host " - Dismiss stale reviews: enabled" -ForegroundColor Green
98+
Write-Host " - Allowed merge: squash only" -ForegroundColor Green
99+
Write-Host ""
100+
101+
Write-Host "Done! Repository $FullRepo is configured." -ForegroundColor Cyan
102+
Write-Host ""
103+
Write-Host "View settings: https://github.com/$FullRepo/settings"
104+
Write-Host "View ruleset: https://github.com/$FullRepo/settings/rules"

scripts/setup-repo.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
#
3+
# Setup script for new CodingWithCalvin repositories
4+
# Run after creating a repo from a template
5+
#
6+
# Usage: ./setup-repo.sh <repo-name>
7+
# Example: ./setup-repo.sh VS-MyNewExtension
8+
#
9+
10+
set -e
11+
12+
ORG="CodingWithCalvin"
13+
14+
if [ -z "$1" ]; then
15+
echo "Usage: $0 <repo-name>"
16+
echo "Example: $0 VS-MyNewExtension"
17+
exit 1
18+
fi
19+
20+
REPO="$1"
21+
FULL_REPO="$ORG/$REPO"
22+
23+
echo "Setting up repository: $FULL_REPO"
24+
echo ""
25+
26+
# Check if repo exists
27+
if ! gh repo view "$FULL_REPO" > /dev/null 2>&1; then
28+
echo "Error: Repository $FULL_REPO not found"
29+
exit 1
30+
fi
31+
32+
echo "1. Configuring repository settings..."
33+
gh api "repos/$FULL_REPO" -X PATCH \
34+
-F has_issues=true \
35+
-F has_projects=false \
36+
-F has_wiki=false \
37+
-F has_discussions=true \
38+
-F allow_squash_merge=true \
39+
-F allow_merge_commit=false \
40+
-F allow_rebase_merge=false \
41+
-F delete_branch_on_merge=true \
42+
-F allow_auto_merge=false \
43+
-F web_commit_signoff_required=false \
44+
--silent
45+
46+
echo " - Issues: enabled"
47+
echo " - Projects: disabled"
48+
echo " - Wiki: disabled"
49+
echo " - Discussions: enabled"
50+
echo " - Merge commits: disabled"
51+
echo " - Rebase merge: disabled"
52+
echo " - Squash merge: enabled"
53+
echo " - Delete branch on merge: enabled"
54+
echo ""
55+
56+
echo "2. Creating branch ruleset..."
57+
gh api "repos/$FULL_REPO/rulesets" -X POST --input - --silent << 'EOF'
58+
{
59+
"name": "PRs to Main",
60+
"target": "branch",
61+
"enforcement": "active",
62+
"bypass_actors": [
63+
{
64+
"actor_type": "OrganizationAdmin",
65+
"bypass_mode": "always"
66+
}
67+
],
68+
"conditions": {
69+
"ref_name": {
70+
"include": ["~DEFAULT_BRANCH"],
71+
"exclude": []
72+
}
73+
},
74+
"rules": [
75+
{"type": "deletion"},
76+
{"type": "non_fast_forward"},
77+
{
78+
"type": "pull_request",
79+
"parameters": {
80+
"required_approving_review_count": 1,
81+
"dismiss_stale_reviews_on_push": true,
82+
"require_code_owner_review": false,
83+
"require_last_push_approval": false,
84+
"required_review_thread_resolution": false,
85+
"allowed_merge_methods": ["squash"]
86+
}
87+
}
88+
]
89+
}
90+
EOF
91+
92+
echo " - Bypass: Organization Admins"
93+
echo " - Prevent deletion: enabled"
94+
echo " - Prevent force push: enabled"
95+
echo " - Require PR: enabled"
96+
echo " - Required approvals: 1"
97+
echo " - Dismiss stale reviews: enabled"
98+
echo " - Allowed merge: squash only"
99+
echo ""
100+
101+
echo "Done! Repository $FULL_REPO is configured."
102+
echo ""
103+
echo "View settings: https://github.com/$FULL_REPO/settings"
104+
echo "View ruleset: https://github.com/$FULL_REPO/settings/rules"

0 commit comments

Comments
 (0)