Ivar Eriksen преди 9 години
родител
ревизия
8923381532
променени са 2 файла, в които са добавени 87 реда и са изтрити 0 реда
  1. 3 0
      README.md
  2. 84 0
      import.sh

+ 3 - 0
README.md

@@ -1,2 +1,5 @@
 # gogs-import
 Shell script to import existing repositories to Gogs
+
+TODO:
+* Parse output from curl

+ 84 - 0
import.sh

@@ -0,0 +1,84 @@
+#!/bin/bash
+
+INTERACTIVE=1
+
+REPO_DIR="/gitlab/repositories"
+
+GOGS_URL=""
+GOGS_TOKEN=""
+
+GOGS_UID="1"
+GOGS_MIRROR="false"
+GOGS_PRIVATE="false"
+
+# Ignore gitlab wiki repositories
+IGNORE_WIKI=1
+
+#Hack to add directory the repository is in to name
+LONG_NAME=1
+
+# Remove trailing .git from directory
+REMOVE_TRAILING_GIT=1
+
+import() {
+    if [[ $IGNORE_WIKI == 1 && $1 == *".wiki.git" ]]; then
+	return
+    fi
+    description=$(<description)
+
+   if [[ $LONG_NAME == 1 ]]; then
+        name=$(basename $(dirname `pwd`))
+	name+="_$1"
+    else
+	name=$1
+    fi
+
+    if [[ $REMOVE_TRAILING_GIT == 1 ]]; then
+	name="${name%????}"
+    fi
+ 
+    if [[ $INTERACTIVE == 1 ]]; then
+	read -n 1 -r -p "Import from "`pwd`" with name: $name (y/n): "
+        echo ''	
+	if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+	   echo $'Skipping repository\n'
+           return
+        fi
+    fi
+    
+    curl -k -H "Content-Type: application/json" \
+    -H "Authorization: token $GOGS_TOKEN" \
+    -X POST -d '{ 
+	"clone_addr": "'`pwd`'", 
+	"uid": '"$GOGS_UID"',
+	"repo_name": "'"$name"'",
+	"mirror": '"$GOGS_MIRROR"',
+	"private": '"$GOGS_PRIVATE"',
+	"description": "'"$description"'" }' "$GOGS_URL/api/v1/repos/migrate"
+
+   echo $'\n'
+    
+}
+
+searchdir() {
+    for d in "$@"; do
+        test -d "$d" -a \! -L "$d" || continue
+        cd "$d"
+        if [ -f "HEAD" ]; then
+	    import $d
+        else
+            searchdir *
+        fi
+        cd ..
+    done
+}
+
+
+if [[ -d "$REPO_DIR" ]]; then
+    cd "$REPO_DIR"
+else
+    exit "Repo directory not found"
+fi
+	
+searchdir *
+