diff --git a/README.md b/README.md index 5523b63d36bb305f33afbb1e4275b4a72dfe2b1d..86202da8d6fb09b4419b6f55a49b0b607d3d203e 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 0000000000000000000000000000000000000000..8c0dbe3ce42f92ecf866438a6e428b9da051ee33 --- /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 a9ff9a2f6697fb85c921b05ebff29bf0c6a11e82..7240cd5c68e84475812d9c5efab196403f1eee12 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 4cae152303dbfcadcefe01a0be3fb7d98c9aa1c6..622d113cc741f0a248d93eb7cbf9bdbe44ba286d 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 0000000000000000000000000000000000000000..2435de5d1e0cc2a4de6ff3b6ba41251c308c0f4d --- /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']