-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-create
More file actions
executable file
·146 lines (122 loc) · 3.69 KB
/
git-create
File metadata and controls
executable file
·146 lines (122 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
# Determine Repo Name
REPO_NAME=${1:-$(basename "$PWD")}
# --- CONFIG ---
# Replace these with your actual values or export them in your .bashrc
FORGEJO_URL="http://192.168.50.44:3000"
FORGEJO_USER="${FORGEJO_USER}"
GITHUB_USER="${GITHUB_USER}"
FORGEJO_TOKEN="${FORGEJO_TOKEN}"
GITHUB_TOKEN="${GITHUB_TOKEN}"
# Define colors
red=$(tput setaf 1)
green=$(tput setaf 2)
cyan=$(tput setaf 6)
reset=$(tput sgr0)
if [[ -z "$FORGEJO_TOKEN" || -z "$GITHUB_TOKEN" ]]; then
echo "${red}Error: FORGEJO_TOKEN or GITHUB_TOKEN not found in environment.${reset}"
exit 1
fi
echo "${cyan}Targeting repository: '$REPO_NAME'${reset}"
# --- Visibility Selection ---
echo "${cyan}Should this repository be Private or Public? (p/P for Private, any other key for Public)${reset}"
read -r -n 1 VISIBILITY_CHOICE
echo ""
if [[ "$VISIBILITY_CHOICE" == "p" || "$VISIBILITY_CHOICE" == "P" ]]; then
IS_PRIVATE="true"
echo "${cyan}Setting repository to PRIVATE...${reset}"
else
IS_PRIVATE="false"
echo "${cyan}Setting repository to PUBLIC...${reset}"
fi
# Creating repositories on GitHub and Forgejo
echo "${cyan}1. Creating repository on GitHub...${reset}"
curl -s -o /dev/null -X POST "https://api.github.com/user/repos" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\":\"$REPO_NAME\", \"private\": $IS_PRIVATE}"
echo "${cyan}2. Creating repository on Forgejo...${reset}"
curl -s -o /dev/null -X POST "$FORGEJO_URL/api/v1/user/repos" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\":\"$REPO_NAME\", \"private\": $IS_PRIVATE}"
# Local Initialization
if [ "$(basename "$PWD")" != "$REPO_NAME" ]; then
mkdir -p "$REPO_NAME" && cd "$REPO_NAME" || exit
fi
git init > /dev/null
if [ ! -f README.md ]; then
echo "# $REPO_NAME" > README.md
fi
# Edit as needed
if [ ! -f LICENSE ]; then
cat > LICENSE << EOF
MIT License
Copyright(c)2026 Spreadneck
EOF
fi
# Edit as needed
if [ ! -f .gitignore ]; then
cat > .gitignore << 'EOF'
# Go
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
vendor/
# Python
__pycache__/
*.py[cod]
*.pyo
*.pyd
.venv/
venv/
dist/
build/
*.egg-info/
.env
# GoLand / JetBrains
.idea/
*.iml
EOF
echo "${cyan}3. Created .gitignore${reset}"
fi
# --- Language Selection ---
echo ""
echo "${cyan}Select project type:${reset}"
select PROJECT_TYPE in "Go" "Python" "Bash" "Exit"; do
case $PROJECT_TYPE in
"Go")
go mod init "$REPO_NAME"
# echo 'package main; import "fmt"; func main() { fmt.Println("Hello") }' > main.go
printf 'package main\n\nfunc main() {\n\n}\n' > main.go
break ;;
"Python")
if command -v uv &> /dev/null; then uv init; mv hello.py main.py 2>/dev/null; else touch main.py; fi
break ;;
"Bash")
echo "#!/bin/bash" > main.sh; chmod +x main.sh
break ;;
"Exit") exit 0 ;;
esac
done
# Setup remote
git branch -M main 2>/dev/null || true
git remote remove origin 2>/dev/null
git remote add origin "forgejo:$FORGEJO_USER/$REPO_NAME.git"
# Setup GitHub push mirror
echo "${cyan}4. Setting up GitHub Push Mirror...${reset}"
curl -s -o /dev/null -X POST "$FORGEJO_URL/api/v1/repos/$FORGEJO_USER/$REPO_NAME/push_mirrors" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"remote_address\": \"git@github.com:$GITHUB_USER/$REPO_NAME.git\",
\"remote_username\": \"$GITHUB_USER\",
\"remote_password\": \"$GITHUB_TOKEN\",
\"interval\": \"8h0m0s\",
\"sync_on_commit\": true
}"
echo "${green}SUCCESS: $REPO_NAME created and mirror configured.${reset}"