From 68d3c4447b476f5337eb64429afb7dcc6c4a2620 Mon Sep 17 00:00:00 2001 From: Askill Date: Sat, 6 Apr 2024 16:54:36 +0200 Subject: [PATCH] added docker compose support and readme --- .env | 5 +++++ README.md | 28 ++++++++++++++++++++++++++++ README.org | 26 -------------------------- docker-compose.yaml | 7 +++++++ github-git-mirror.sh | 21 +++++++++++++-------- 5 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 .env create mode 100644 README.md delete mode 100644 README.org create mode 100644 docker-compose.yaml diff --git a/.env b/.env new file mode 100644 index 0000000..b2402af --- /dev/null +++ b/.env @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..2c04e46 --- /dev/null +++ b/README.md @@ -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}" diff --git a/README.org b/README.org deleted file mode 100644 index adff136..0000000 --- a/README.org +++ /dev/null @@ -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 - - - - diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..aeca53b --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,7 @@ +version: '3.8' +services: + git-mirror: + build: . + env_file: + - .env + restart: unless-stopped \ No newline at end of file diff --git a/github-git-mirror.sh b/github-git-mirror.sh index 9cebf31..bf73fe0 100644 --- a/github-git-mirror.sh +++ b/github-git-mirror.sh @@ -47,14 +47,19 @@ create_migration_repo() { repos_to_migration() { for f in ${jsonoutput}/*.json; do - n=$(jq '.|length'<$f) - (( n-- )) # last element - 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 \ - | create_migration_repo - done + n=$(jq '.|length'<$f) + (( n-- )) # last element + 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 \ + | create_migration_repo + done done } -fetch_starred_repos -repos_to_migration +main(){ + fetch_starred_repos + repos_to_migration + sleep 43100 + +} +while :; do main; done