added docker compose support and readme

This commit is contained in:
Askill 2024-04-06 16:54:36 +02:00
parent 866ce41945
commit 68d3c4447b
5 changed files with 53 additions and 34 deletions

5
.env Normal file
View File

@ -0,0 +1,5 @@
LOCAL_GIT_ACCESS_TOKEN=your_access_token
LOCAL_GIT_URL=your_git_url
GIT_USER=your_git_user
TARGET_ORG=your_target_org
MODE=your_mode

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# Mirror your starred Github repos to a Gitea organization
### Inspiration for this script:
[Proposal: Mirror an entire github organization into gitea organization](https://github.com/go-gitea/gitea/issues/8424)
## Usage
The script runs forever, every 12 hours it executes API calls to retrieve either your starred or public repositories and mirrors them to your local gitea( or forks from this project) server.
Feel free to change it to a one time only script and calling it in a cronjob.
### Docker Compose
edit ```.env``` the way you need it
docker-compose up --build
### Bash
export LOCAL_GIT_ACCESS_TOKEN="your_access_token"
export LOCAL_GIT_URL="your_git_url"
export GIT_USER="your_git_user"
export TARGET_ORG="your_target_org"
export MODE="your_mode"
bash github-git-mirror.sh "${GIT_USER}" "${TARGET_ORG}" "${MODE}"

View File

@ -1,26 +0,0 @@
#+title: Mirror your starred Github repos to a Gitea organization
* Inspiration for this script
[[https://github.com/go-gitea/gitea/issues/8424][Proposal: Mirror an entire github organization into gitea organization]]
I wanted to mirror my starred repos instead. Mirroring an organization is on the [[*TODOs][TODOs]] list.
* Usage
Using [[https://github.com/][GitHub]] user =juergenhoetzel= and Gitea organization =githubmirror=
#+BEGIN_SRC bash
export ACCESS_TOKEN=3a765a661619136db92aa267d90c457573x98812
export LOCAL_GIT_URL=http://gitea.fritz.box:3000
github2gitea-mirror juergenhoetzel githubmirror
#+END_SRC
* TODOs
- [ ] Mirror github organization
- [ ] Mirror private repos

7
docker-compose.yaml Normal file
View File

@ -0,0 +1,7 @@
version: '3.8'
services:
git-mirror:
build: .
env_file:
- .env
restart: unless-stopped

View File

@ -47,14 +47,19 @@ create_migration_repo() {
repos_to_migration() { repos_to_migration() {
for f in ${jsonoutput}/*.json; do for f in ${jsonoutput}/*.json; do
n=$(jq '.|length'<$f) n=$(jq '.|length'<$f)
(( n-- )) # last element (( n-- )) # last element
for i in $(seq 0 $n); do for i in $(seq 0 $n); do
jq ".[$i]|.uid=${uid}|.mirror=true|.clone_addr=.clone_url|.description=.description[0:255]|.repo_name=.name|{uid,repo_name,clone_addr,description,mirror}" <$f \ jq ".[$i]|.uid=${uid}|.mirror=true|.clone_addr=.clone_url|.description=.description[0:255]|.repo_name=.name|{uid,repo_name,clone_addr,description,mirror}" <$f \
| create_migration_repo | create_migration_repo
done done
done done
} }
fetch_starred_repos main(){
repos_to_migration fetch_starred_repos
repos_to_migration
sleep 43100
}
while :; do main; done