From b98bfdeac11520a467d3794d417b483098814360 Mon Sep 17 00:00:00 2001 From: Sam Gleske <sag47@drexel.edu> Date: Tue, 10 Sep 2013 21:13:21 -0400 Subject: [PATCH] Adding simple add_mirror.sh * It doesn't function as intended yet. * Depends on create_gitlab_project.py. * Updated the readme for some prereqs. * The python script currently only lists an existing project. Returns http clone URL. --- README.md | 7 ++++++ add_mirror.sh | 8 +++++++ config.sh | 4 ++++ git-mirrors.sh | 5 ++++- lib/create_gitlab_project.py | 42 ++++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 add_mirror.sh create mode 100755 lib/create_gitlab_project.py diff --git a/README.md b/README.md index 5523b63..86202da 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,10 @@ This adds git mirror functionality to gitlab. The whole purpose of this project * [Git Mirror](http://stackoverflow.com/questions/2756747/mirror-a-git-repository-by-pulling) * [Git Push all Branches](http://stackoverflow.com/questions/1914579/set-up-git-to-pull-and-push-all-branches) + +# Prereqs + + yum install python-setuptools + git clone https://github.com/Itxaka/python-gitlab.git + cd python-gitlab + python setup.py diff --git a/add_mirror.sh b/add_mirror.sh new file mode 100755 index 0000000..8c0dbe3 --- /dev/null +++ b/add_mirror.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +#Include all user options +. "$(dirname $0)/config.sh" +cd $(dirname $0) + +export token_secret gitlab_url gitlab_namespace +python lib/create_gitlab_project.py test2 diff --git a/config.sh b/config.sh index a9ff9a2..7240cd5 100644 --- a/config.sh +++ b/config.sh @@ -2,3 +2,7 @@ repo_dir="/home/gitmirror/repositories" mirror_list=("gitlabhq") +token_secret="$(head -n1 /home/gitmirror/private_token)" +#This group will contain all code mirrors +gitlab_namespace="Mirrors" +gitlab_url="https://comet.irt.drexel.edu" diff --git a/git-mirrors.sh b/git-mirrors.sh index 4cae152..622d113 100755 --- a/git-mirrors.sh +++ b/git-mirrors.sh @@ -1,4 +1,7 @@ #!/bin/bash #Include all user options -. /home/gitmirror/gitlab-mirrors/config.sh + +. "$(dirname $0)/config.sh" +echo "repo $repo_dir" +echo "GitLab Group $gitlab_group" diff --git a/lib/create_gitlab_project.py b/lib/create_gitlab_project.py new file mode 100755 index 0000000..2435de5 --- /dev/null +++ b/lib/create_gitlab_project.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +from sys import argv,exit +import os +import gitlab + +try: + project_name=argv[1] + token_secret=os.environ['token_secret'] + gitlab_url=os.environ['gitlab_url'] + gitlab_namespace=os.environ['gitlab_namespace'] +except KeyError: + print "Environment config missing. Do not run this script standalone." + exit(1) +except IndexError: + print "No project name specified. Do not run this script standalone." + exit(1) + +git=gitlab.Gitlab(gitlab_url,token_secret) + +#Locate the group +found_group=False +for group in git.getGroups(): + if group['name'] == gitlab_namespace: + found_group=group + break +else: + if not found_group: + print "Project namespace (user or group) not found or user does not have permission of existing group." + exit(1) + +#Locate existing repository, if it doesn't exist then create it in gitlab +found_project=False +for project in git.getProjects(): + if project['namespace']['name'] == gitlab_namespace and project['name'] == project_name: + found_project=project + break +if not found_project: + print "not found" + pass + +print found_project['http_url_to_repo'] -- GitLab