import os
import sys
import subprocess
import logging
def csct_online(pr_list: list):
"""
pr_list: pull request list, example: https://xxxxx/pulls/1410;https://xxxxx/pulls/250
return: status: True or False
resutl: check result
"""
if len(pr_list) == 0:
sys.stderr.write("error: pr_list is empty.\n")
return True, " "
status = True
result = " "
root_dir = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
csct_project_path = os.path.join(
root_dir, "build/tools/component_tools/static_check/"
)
try:
file = "%scsct_online.py" % csct_project_path
ret = subprocess.Popen(
["/usr/bin/python3", file, pr_list],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
errors="replace",
)
result, errcode = ret.communicate(timeout=30)
if len(errcode) != 0:
logging.error("Popen error: ", errcode)
status = False
else:
status = False if len(result) != 0 else True
except Exception as err:
status = False
logging.error(err)
return status, result
def test():
if len(sys.argv) == 1:
sys.stderr.write("test error: pr_list is empty.\n")
return False
prs = sys.argv[1]
status, result = csct_online(prs)
return status, result
if __name__ == "__main__":
sys.exit(test())