Files
tools/executor/cli/git.py
T
RemiZOffAlex 45541155c3
Test Actions / Builder (push) Failing after 6s
Обновить executor/cli/git.py
2026-03-21 22:41:01 +03:00

121 lines
3.4 KiB
Python

__author__ = 'RemiZOffAlex'
__email__ = 'remizoffalex@mail.ru'
import os
import sys
import base64
import json
import requests
from executor.visitor import Visitor
from executor.state import State
from executor.core import config
from executor.handlers.config import handle_config
from executor.octokit import Octokit
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))
handle_config(config)
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
response = requests.get(
url='https://codex.r10x.net/api/v1/repos/meta/dsl',
headers={
# 'Authorization': INPUT_TOKEN,
# 'Authorization': f'token {INPUT_TOKEN}',
'Authorization': f'Bearer {INPUT_TOKEN}',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
)
print(response)
print(response.status_code)
print(response.json())
octokit = Octokit(
url='https://codex.r10x.net/api/v1',
headers={
'Authorization': f'Bearer {INPUT_TOKEN}'
}
)
owner = 'meta'
repo = 'dsl'
client = octokit.repo(owner, repo)
response = client.get()
print(response)
def escape(text):
return '"' + text + '"'
def exec_cmd(cmd):
result = os.popen(cmd)
print(result.read())
cmd = f'git -C ' + INPUT_PATH + ' 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 -C ' + INPUT_PATH + ' remote add origin ' + GITHUB_SERVER_URL + '/' + REPOSITORY
print(cmd)
exec_cmd(cmd)
cmd = 'git -C ' + INPUT_PATH + ' fetch --progress --depth ' + DEPTH + ' origin ' + INPUT_REF
print(cmd)
exec_cmd(cmd)
cmd = 'git -C ' + INPUT_PATH + ' checkout ' + GITHUB_REF_NAME # config['ref']
print(cmd)
exec_cmd(cmd)