From 403056e17b5298f6901269e80993230d124ff65e Mon Sep 17 00:00:00 2001 From: Askill Date: Sat, 6 Apr 2024 16:36:38 +0200 Subject: [PATCH] added support for starred --- .vscode/settings.json | 3 +++ Dockerfile | 8 ++++++++ README.org | 2 +- github2gitea-mirror => github-git-mirror.sh | 15 ++++++++------- 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 Dockerfile rename github2gitea-mirror => github-git-mirror.sh (62%) mode change 100755 => 100644 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..13ee2b0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nuxt.isNuxtApp": false +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e24f17 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM bash:4.3.48-alpine3.19 +COPY github-git-mirror.sh / +ENV LOCAL_GIT_ACCESS_TOKEN="" +ENV LOCAL_GIT_URL="" +ENV GIT_USER="" +ENV TARGET_ORG="" +ENV MODDE="" +CMD ["bash", "/github-git-mirror.sh", "${GIT_USER}", "${TARGET_ORG}", "${MODE}"] \ No newline at end of file diff --git a/README.org b/README.org index 0bdb4b1..adff136 100644 --- a/README.org +++ b/README.org @@ -12,7 +12,7 @@ Using [[https://github.com/][GitHub]] user =juergenhoetzel= and Gitea organizati #+BEGIN_SRC bash export ACCESS_TOKEN=3a765a661619136db92aa267d90c457573x98812 - export GITEA_URL=http://gitea.fritz.box:3000 + export LOCAL_GIT_URL=http://gitea.fritz.box:3000 github2gitea-mirror juergenhoetzel githubmirror #+END_SRC diff --git a/github2gitea-mirror b/github-git-mirror.sh old mode 100755 new mode 100644 similarity index 62% rename from github2gitea-mirror rename to github-git-mirror.sh index b262a9b..9cebf31 --- a/github2gitea-mirror +++ b/github-git-mirror.sh @@ -5,37 +5,39 @@ set -euo pipefail # Mirror starred Github repos to a Gitea Organization CURL="curl -f -S -s" -if [[ -z "${ACCESS_TOKEN}" || -z "${GITEA_URL}" ]];then - echo -e "Please set gitea access token and url in environment:\nexport ACCESS_TOKEN=abc\nexport GITEA_URL=http://gitea:3000\n" >&2 +if [[ -z "${LOCAL_GIT_ACCESS_TOKEN}" || -z "${LOCAL_GIT_URL}" ]];then + echo -e "Please set gitea LOCAL_GIT_ACCESS token and url in environment:\nexport LOCAL_GIT_ACCESS_TOKEN=abc\nexport LOCAL_GIT_URL=http://gitea:3000\n\nexport MODE=repos\n" >&2 echo -e "Don't use trailing slash in URL!" exit 1 fi github_user="${1:-}" gitea_organization="${2:-}" +# starred or repos2 +mode="${3:-}" if [[ -z "${github_user}" || -z "${gitea_organization}" ]]; then echo "Usage: $0 github_user gitea_organization" >&2 exit 1 fi -header_options=(-H "Authorization: Bearer ${ACCESS_TOKEN}" -H "accept: application/json" -H "Content-Type: application/json") +header_options=(-H "Authorization: Bearer ${LOCAL_GIT_ACCESS_TOKEN}" -H "accept: application/json" -H "Content-Type: application/json") jsonoutput=$(mktemp -d -t github-repos-XXXXXXXX) trap "rm -rvf ${jsonoutput}" EXIT -uid=$($CURL "${header_options[@]}" $GITEA_URL/api/v1/orgs/${gitea_organization} |jq .id) +uid=$($CURL "${header_options[@]}" $LOCAL_GIT_URL/api/v1/orgs/${gitea_organization} |jq .id) fetch_starred_repos(){ i=1 # Github API just returns empty arrays instead of 404 - while $CURL "https://api.github.com/users/${github_user}/starred?page=${i}&per_page=100" >${jsonoutput}/${i}.json \ + while $CURL "https://api.github.com/users/${github_user}/${mode}?page=${i}&per_page=100" >${jsonoutput}/${i}.json \ && (( $(jq <${jsonoutput}/${i}.json '.|length') > 0 )) ; do (( i++ )) done } create_migration_repo() { - if ! $CURL -w "%{http_code}\n" "${header_options[@]}" -d @- -X POST $GITEA_URL/api/v1/repos/migrate > ${jsonoutput}/result.txt 2>${jsonoutput}/stderr.txt;then + if ! $CURL -w "%{http_code}\n" "${header_options[@]}" -d @- -X POST $LOCAL_GIT_URL/api/v1/repos/migrate > ${jsonoutput}/result.txt 2>${jsonoutput}/stderr.txt;then local code=$(<${jsonoutput}/result.txt) if (( code != 409 ));then # 409 == repo already exits cat ${jsonoutput}/stderr.txt >&2 @@ -56,4 +58,3 @@ repos_to_migration() { fetch_starred_repos repos_to_migration -