Verified Commit 5f2b2300 authored by Sofus Rose's avatar Sofus Rose

Added gitpython logic. First test.

parent 616cfabb
from flask import Flask, request
from git import Repo
import json
import sys
import os, os.path
github_user = 'so-rose'
TOKEN = 'siueyrhg87w35ht8jmwfy7h5g'
app = Flask(__name__)
@app.route('/',methods=['POST'])
def foo():
data = request.get_json()
#~ data = json.loads(request.data)
print("New commit by: {}".format(data['commits'][0]['author']['name']), file=sys.stderr)
print("Header: ", request.headers)
return "OK"
if request.headers['X-Gitlab-Token'] == TOKEN :
proj_name = data['project']['name']
github_link = 'git@github.com/{0}/{1}.git'.format(github_user, proj_name)
gitlab_link = data['project']['git_http_url']
repo_path = "/opt/git-repos/{}".format(proj_name)
#Initialize & prepare repo object.
repo = Repo(repo_path) if os.path.isdir(repo_path) else Repo.clone_from(gitlab_link, repo_path)
#Get remotes, pull and push.
github = repo.create_remote('github', github_link)
gitlab = repo.remotes.origin
for branch in repo.branches :
repo.git.checkout('HEAD', b=branch)
gitlab.pull()
github.push()
print github.fetch()
return "OK"
else :
return 403
if __name__ == '__main__':
app.run(port=7080)
click==6.7
Flask==0.12
gitdb2==2.0.0
GitPython==2.1.1
itsdangerous==0.24
Jinja2==2.9.3
MarkupSafe==0.23
smmap2==2.0.1
Werkzeug==0.11.15
wheel==0.24.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment