-
Notifications
You must be signed in to change notification settings - Fork 39
/
gitlab-project-import.py
executable file
·73 lines (61 loc) · 2.18 KB
/
gitlab-project-import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
from __future__ import print_function
import sys
import os
import argparse
import yaml
from datetime import date
import requests
# Find our libs
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from gitlab_export import config, gitlab
return_code = 0
if __name__ == '__main__':
# Parsing arguments
parser = argparse.ArgumentParser(
description="""
GitLab Project Import is
small project using Gitlab API for exporting whole gitlab
project with wikis, issues etc.
Good for migration or simple backup your gitlab projects.
""",
epilog='Created by Robert Vojcik <[email protected]>')
# Arguments
parser.add_argument(
'-c', dest='config', default='config.yaml',
help='config file')
parser.add_argument(
'-f', dest='filepath', default=False,
help='Path to gitlab exported project file')
parser.add_argument(
'-p', dest='project_path', default=False,
help='Project path')
parser.add_argument(
'-d', dest='debug', default=False, action='store_const', const=True,
help='Debug mode')
args = parser.parse_args()
if not os.path.isfile(args.config):
print("Unable to find config file %s" % (args.config))
c = config.Config(args.config)
token = c.config["gitlab"]["access"]["token"]
gitlab_url = c.config["gitlab"]["access"]["gitlab_url"]
ssl_verify = c.config["gitlab"]["access"]["ssl_verify"]
# Init gitlab api object
if args.debug:
print("%s, token" % (gitlab_url))
gitlab = gitlab.Api(gitlab_url, token, ssl_verify)
# import project
if args.project_path and args.filepath and os.path.isfile(args.filepath):
if args.debug:
print("Importing %s" % (args.project_path))
status = gitlab.project_import(args.project_path, args.filepath)
# Import successful
if status:
print("Import success for %s" % (args.project_path))
sys.exit(0)
else:
print("Import was not successful")
sys.exit(1)
else:
print("Error, you have to specify correct project_path and filepath")
sys.exit(1)