2015-03-17 9 views

risposta

6

Non proprio, a meno che:

  • si ha un progetto 21 che fa riferimento l'altro 20 come submodules.
    (nel qual caso un clone seguita da un modulo git aggiornare --init sarebbe sufficiente per ottenere tutti i 20 progetti clonati e controllato)

  • o in qualche modo si elencano i progetti cui si ha accesso (GitLab API for projects) e anello su quel risultato per clonare ciascuno (significato che può essere script, e poi eseguito come comando di "uno")

13

Ecco un esempio in Python 3:

from urllib.request import urlopen 
import json 
import subprocess, shlex 

allProjects  = urlopen("http://[yourServer:port]/api/v3/projects/all?private_token=[yourPrivateTokenFromUserProfile]") 
allProjectsDict = json.loads(allProjects.read().decode()) 
for thisProject in allProjectsDict: 
    try: 
     thisProjectURL = thisProject['ssh_url_to_repo'] 
     command  = shlex.split('git clone %s' % thisProjectURL) 
     resultCode = subprocess.Popen(command) 

    except Exception as e: 
     print("Error on %s: %s" % (thisProjectURL, e.strerror)) 
+1

Ho avuto alcuni problemi deserializzazione JSON a causa di problemi di codifica sconosciuti, in questo caso una modifica parse tramite espressione regolare aiutato: 'urls = re.findall ('http [s]?: // (?: [a-zA-Z] | [0-9] | [$ -_ @. & +] | [ ! * \ (\),] | (?:% [0-9a-fA-F] [0-9a-fA-F])) +. Git ', allProjects.read(). Decode ("latin-1 ")) ' – 79E09796

+0

Lo script funziona bene. Ho avuto due problemi: http://stackoverflow.com/a/31601343/2777965 e ho dovuto usare https: // invece di http – 030

+0

Questo script usa la vecchia versione api, un url corrente sarebbe https: // [yourServer : port]/api/v4/projects? private_token = [yourPrivateTokenFromUserProfile] & per_page = 100 – user322049

4

C'è una calle strumento d myrepos, che gestisce più repository di controlli di versione. Aggiornamento di tutti gli archivi richiede semplicemente un comando:

mr update 

Per convalidare tutti i progetti gitlab a mr, ecco un piccolo script python. Si richiede il pacchetto python-gitlab installato:

import os 
from subprocess import call 
from gitlab import Gitlab 

# Register a connection to a gitlab instance, using its URL and a user private token 
gl = Gitlab('http://192.168.123.107', 'JVNSESs8EwWRx5yDxM5q') 
groupsToSkip = ['aGroupYouDontWantToBeAdded'] 

gl.auth() # Connect to get the current user 

gitBasePathRelative = "git/" 
gitBasePathRelativeAbsolut = os.path.expanduser("~/" + gitBasePathRelative) 
os.makedirs(gitBasePathRelativeAbsolut,exist_ok=True) 

for p in gl.Project(): 
    if not any(p.namespace.path in s for s in groupsToSkip): 
     pathToFolder = gitBasePathRelative + p.namespace.name + "/" + p.name 
     commandArray = ["mr", "config", pathToFolder, "checkout=git clone '" + p.ssh_url_to_repo + "' '" + p.name + "'"] 
     call(commandArray) 

os.chdir(gitBasePathRelativeAbsolut) 

call(["mr", "update"]) 
+0

Ecco una versione aggiornata (gl.Project non esiste come API, ora è gl.proejcts.list) e una versione python 2: https: //gist.github.com/maxgalbu/995a42a9a4e8594b4a628df93985fc2f – maxgalbu

+0

Inoltre ho aggiunto tutto = True per evitare l'impaginazione – maxgalbu

2

È possibile fare riferimento a questo script ruby ​​qui: https://gist.github.com/thegauraw/da2a3429f19f603cf1c9b3b09553728b

Ma è necessario assicurarsi di avere il link all'URL organizzazione gitlab (che assomiglia a: https://gitlab.example.com/api/v3/ per esempio organizzazione) e token privato (che assomiglia a: QALWKQFAGZDWQYDGHADS e si può accedere a: https://gitlab.example.com/profile/account dopo aver effettuato l'accesso). Assicurati inoltre di aver installato httparty gem o gem install httparty

5

Ho creato uno script (curl, git, jq richiesto) solo per quello. L'usiamo e funziona bene: https://gist.github.com/JonasGroeger/1b5155e461036b557d0fb4b3307e1e75

Per scoprire lo spazio dei nomi, è meglio controllare l'API rapida:

curl "https://domain.com/api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN" 

C'è, utilizzare "namespace.name" come NAMESPACE per il vostro gruppo.

Lo script fa essenzialmente:

  1. ottenere tutti i progetti che corrispondono alla vostra PROJECT_SEARCH_PARAM
  2. Ottenere il loro path e ssh_url_to_repo

    2,1. Se esiste la directory path, inseriscici cd e chiama git pull

    2.2.Se la directory path non esiste, chiamare git clone

2

Ecco un altro esempio di uno script bash per copiare tutti i pronti contro termine in un gruppo. L'unica dipendenza che è necessario installare è jq (https://stedolan.github.io/jq/). È sufficiente posizionare lo script nella directory in cui si desidera clonare i propri progetti. Quindi eseguirlo nel modo seguente:

./myscript <group name> <private token> <gitlab url> 

cioè

./myscript group1 abc123tyn234 http://yourserver.git.com

Script:

#!/bin/bash 
if command -v jq >/dev/null 2>&1; then 
    echo "jq parser found"; 
else 
    echo "this script requires the 'jq' json parser (https://stedolan.github.io/jq/)."; 
    exit 1; 
fi 

if [ -z "$1" ] 
    then 
    echo "a group name arg is required" 
    exit 1; 
fi 

if [ -z "$2" ] 
    then 
    echo "an auth token arg is required. See $3/profile/account" 
    exit 1; 
fi 

if [ -z "$3" ] 
    then 
    echo "a gitlab URL is required." 
    exit 1; 
fi 

TOKEN="$2"; 
URL="$3/api/v3" 
PREFIX="ssh_url_to_repo"; 

echo "Cloning all git projects in group $1"; 

GROUP_ID=$(curl --header "PRIVATE-TOKEN: $TOKEN" $URL/groups?search=$1 | jq '.[].id') 
echo "group id was $GROUP_ID"; 
curl --header "PRIVATE-TOKEN: $TOKEN" $URL/groups/$GROUP_ID/projects?per_page=100 | jq --arg p "$PREFIX" '.[] | .[$p]' | xargs -L1 git clone 
Problemi correlati