Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 9c626a3

Browse files
authored
sh to py and 1st script
1 parent 116bc69 commit 9c626a3

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

app/routes/script_launch.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ class Input(BaseModel):
1414
description='url of repository, str',
1515
example='https://github.com/profcomff/print-api.git'
1616
)
17-
commit_hash: str = Field(
18-
description='commit hash, str',
19-
example='f7cf8ea038edfb31cc8f7dd880dbb53e61980d8c')
17+
git_ref: str = Field(
18+
description='git reference, str',
19+
example='f7cf8ea038edfb31cc8f7dd880dbb53e61980d8c'
20+
)
21+
2022

2123
class SendOutput(BaseModel):
2224
code: int = Field(
@@ -30,8 +32,7 @@ class SendOutput(BaseModel):
3032
response_model = SendOutput
3133
)
3234
async def run_script(action: str, inp: Input, user: UnionAuth = Depends(auth)):
33-
"""runs a bash script, located in scripts/{action}. The script takes 2 arguments: commit_hash and repo_url"""
34-
code= await run(f"./scripts/{action}.sh --repo_url {inp.repo_url} --commit_hash {inp.commit_hash}")
35-
return {
36-
'code': code
37-
}
35+
"""runs a bash script, located in scripts/{action}. The script takes 2 arguments: git_ref and repo_url"""
36+
37+
code = await run(f"python3 ./scripts/{action}.py --repo-url {inp.repo_url} --git-ref {inp.git_ref}")
38+
return {'code': code}

scripts/run_pr.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import argparse
2+
import re
3+
from subprocess import Popen
4+
5+
6+
def get_args():
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument('--repo-url', type=str, required=True)
9+
parser.add_argument('--git-ref', type=str, required=True)
10+
return parser.parse_args()
11+
12+
13+
if __name__ == "__main__":
14+
args = get_args()
15+
_, org, repo = args.repo_url.rsplit('/', 2)
16+
pr_num = re.match("^refs/pull/(?P<pr_num>\d+)", args.git_ref).group('pr_num')
17+
Popen([
18+
'docker', 'run',
19+
'--rm', '--detach',
20+
'--network', 'web',
21+
'--name', f'pkff_dev__{repo}__pr{pr_num}',
22+
f'ghcr.io/{org}/{repo}:latest'
23+
]).communicate()
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ POSITIONAL_ARGS=()
44

55
while [[ $# -gt 0 ]]; do
66
case $1 in
7-
--repo_url)
7+
--repo-url)
88
REPO="$2"
99
shift # past argument
1010
shift # past value
1111
;;
12-
--commit_hash)
13-
COMMIT="$2"
12+
--git-ref)
13+
REF="$2"
1414
shift # past argument
1515
shift # past value
1616
;;
@@ -29,4 +29,4 @@ done
2929
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
3030

3131
echo "repo_url=${REPO}"
32-
echo "commit_hash=${COMMIT}"
32+
echo "git_ref=${REF}"

0 commit comments

Comments
 (0)