• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (c) 2022 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import sys
18import subprocess
19import logging
20
21
22def csct_online(pr_list: list):
23    """
24    pr_list: pull request list, example: https://xxxxx/pulls/1410;https://xxxxx/pulls/250
25    return: status: True or False
26            resutl: check result
27    """
28    if len(pr_list) == 0:
29        sys.stderr.write("error: pr_list is empty.\n")
30        return True, " "
31
32    status = True
33    result = " "
34    root_dir = os.path.dirname(
35        os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
36    )
37    csct_project_path = os.path.join(
38        root_dir, "build/tools/component_tools/static_check/"
39    )
40
41    try:
42        file = "%scsct_online.py" % csct_project_path
43        ret = subprocess.Popen(
44            ["/usr/bin/python3", file, pr_list],
45            shell=False,
46            stdout=subprocess.PIPE,
47            stderr=subprocess.PIPE,
48            errors="replace",
49        )
50        result, errcode = ret.communicate(timeout=30)
51        if len(errcode) != 0:
52            logging.error("Popen error: ", errcode)
53            status = False
54        else:
55            status = False if len(result) != 0 else True
56    except Exception as err:
57        status = False
58        logging.error(err)
59
60    return status, result
61
62
63def test():
64    if len(sys.argv) == 1:
65        sys.stderr.write("test error: pr_list is empty.\n")
66        return False
67
68    prs = sys.argv[1]
69    status, result = csct_online(prs)
70    return status, result
71
72
73if __name__ == "__main__":
74    sys.exit(test())
75