-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
29 lines (24 loc) · 990 Bytes
/
handler.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
import os
import subprocess
import shutil
token = os.environ["github_token"]
source = os.environ["source_repo"]
target = os.environ["target_repo"]
source = "https://" + token + "@github.com/" + source
target = "https://" + token + "@github.com/" + target
folder = "mirror"
def hello(event, context):
os.chdir("/tmp")
print(subprocess.getoutput("git --version"))
if os.path.exists(folder):
os.chdir(folder)
print()
a = subprocess.getoutput('git fetch -p origin')
b = subprocess.getoutput('git push --mirror')
return ("Cached run: \n---\n" + str(a) + "\n---\n" + str(b)).replace(token, '')
os.mkdir(folder)
a = subprocess.getoutput('git clone --mirror ' + source + " " + folder)
os.chdir(folder)
b = subprocess.getoutput('git remote set-url --push origin ' + target)
c = subprocess.getoutput('git push --mirror')
return ("Non-Cached run: " + str(a) + "\n---\n" + str(b) + "\n---\n" + str(c)).replace(token, '')