87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
__author__ = 'RemiZOffAlex'
|
|
__email__ = 'remizoffalex@mail.ru'
|
|
|
|
|
|
import os
|
|
import sys
|
|
import base64
|
|
import json
|
|
|
|
|
|
from executor.engine import Engine
|
|
from executor.core import config
|
|
|
|
def json_read(filename):
|
|
with open(filename, 'r') as fd:
|
|
data = json.load(fd)
|
|
return data
|
|
|
|
|
|
def handle_git(args):
|
|
for key in os.environ:
|
|
if key.startswith('INPUT_'):
|
|
print(key, os.getenv(key))
|
|
DEBUG = True
|
|
ACTIONS_RUNTIME_TOKEN = os.getenv('ACTIONS_RUNTIME_TOKEN')
|
|
INPUT_TOKEN = os.getenv('INPUT_TOKEN')
|
|
INPUT_REF = os.getenv('INPUT_REF')
|
|
INPUT_REPOSITORY = os.getenv('INPUT_REPOSITORY')
|
|
INPUT_PATH = os.getenv('INPUT_PATH')
|
|
DEPTH = os.getenv('INPUT_FETCH-DEPTH')
|
|
GITHUB_EVENT_PATH = os.getenv('GITHUB_EVENT_PATH')
|
|
GITHUB_SERVER_URL = os.getenv('GITHUB_SERVER_URL')
|
|
GITHUB_REPOSITORY = os.getenv('GITHUB_REPOSITORY')
|
|
GITHUB_REF = os.getenv('GITHUB_REF')
|
|
GITHUB_REF_NAME = os.getenv('GITHUB_REF_NAME')
|
|
# assert ACTIONS_RUNTIME_TOKEN==INPUT_TOKEN, 'token not equal'
|
|
TOKEN = INPUT_TOKEN
|
|
REPOSITORY = INPUT_REPOSITORY
|
|
REF = INPUT_REF
|
|
|
|
def escape(text):
|
|
return '"' + text + '"'
|
|
|
|
|
|
def exec_cmd(cmd):
|
|
result = os.popen(cmd)
|
|
print(result.read())
|
|
|
|
cmd = 'git init'
|
|
exec_cmd(cmd)
|
|
|
|
sample_string = "x-access-token:" + TOKEN
|
|
sample_string = "x-access-token:" + TOKEN
|
|
sample_string_bytes = sample_string.encode("utf-8")
|
|
|
|
base64_bytes = base64.b64encode(sample_string_bytes)
|
|
base64_string = 'AUTHORIZATION: basic ' + base64_bytes.decode("utf-8")
|
|
|
|
key = 'http.'+GITHUB_SERVER_URL+'/.extraheader'
|
|
value = base64_string
|
|
cmd = 'git config set --local ' + key + ' ' + escape(value)
|
|
exec_cmd(cmd)
|
|
|
|
# key = 'url.https://'+TOKEN+':x-oauth-basic@codex.r10x.net'+'/.insteadOf'
|
|
# value = 'git@"'+base64_string+'"'
|
|
# cmd = 'git config set --local ' + escape(key) + ' ' + escape(GITHUB_SERVER_URL)
|
|
# exec_cmd(cmd)
|
|
|
|
data = json_read(GITHUB_EVENT_PATH)
|
|
org_id = data['repository']['owner']['id']
|
|
org_id=7
|
|
key = 'url."https://codex.r10x.net"/.insteadOf'
|
|
value = 'git@codex.r10x.net:org-'+str(org_id)+'@github.com:'
|
|
exec_cmd(cmd)
|
|
|
|
cmd = 'git remote add origin ' + GITHUB_SERVER_URL + '/' + REPOSITORY
|
|
print(cmd)
|
|
exec_cmd(cmd)
|
|
|
|
cmd = 'git fetch --progress --depth ' + DEPTH + ' origin ' + GITHUB_REF_NAME
|
|
print(cmd)
|
|
exec_cmd(cmd)
|
|
|
|
cmd = 'git checkout ' + GITHUB_REF_NAME
|
|
print(cmd)
|
|
exec_cmd(cmd)
|