diff options
author | David Skoland <david.skoland@qt.io> | 2021-06-15 12:35:13 +0200 |
---|---|---|
committer | David Skoland <david.skoland@qt.io> | 2021-08-17 15:54:30 +0200 |
commit | c4aba82aeadb17183f09a1415a2dbaead7a9d8a0 (patch) | |
tree | ab4b5be48aff63d75ff5c3e725066aee9102b73d /scripts/api-review/fullrun/gitfunctions.py | |
parent | 746a5c8d6bb7ac1a6807438217b6772e31b1821c (diff) | |
download | qtqa-c4aba82aeadb17183f09a1415a2dbaead7a9d8a0.tar.gz |
Add API Change Review wrapper script
This is a wrapper script that parses .gitmodules of a qt5 checkout and
figures out which version it should be compared to. It then generates a
change review for each module and asks if it should be uploaded. It acts
as a replacement for all-api-modules which also handles the steps of
checking out repos and the otherwise manual git steps.
Change-Id: If2035fe70159d33fad7f5f6375f5ef1ca5e6a8ea
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'scripts/api-review/fullrun/gitfunctions.py')
-rw-r--r-- | scripts/api-review/fullrun/gitfunctions.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/scripts/api-review/fullrun/gitfunctions.py b/scripts/api-review/fullrun/gitfunctions.py new file mode 100644 index 0000000..73adfb2 --- /dev/null +++ b/scripts/api-review/fullrun/gitfunctions.py @@ -0,0 +1,82 @@ +############################################################################# +## +## Copyright (C) 2021 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## + +import os +import subprocess + +# get the current branch of git repo +def get_branch(git_repo : str = '.') -> str: + cwd = os.getcwd() + + os.chdir(git_repo) + + cmd = 'git rev-parse --abbrev-ref HEAD'.split(' ') + completed_process = subprocess.run(cmd, capture_output=True) + output = completed_process.stdout.decode('utf-8').strip() + + #print(output) + + os.chdir(cwd) + + return output + +# Gets a list of submodules from given git repo path and optionally, branch +# Where each module is represented by a dict +def get_submodules(git_repo : str = '.', branch : str = 'current') -> {}: + cwd = os.getcwd() + + os.chdir(git_repo) + current_branch = get_branch() + + if branch != 'current': + os.system(f'git checkout {branch}') + + modules = {} + + modules_path = '.gitmodules' + + if not os.path.exists(modules_path): + print(f'Error: {modules_path} not found') + return modules + + modules_file = open(modules_path, 'r') + + read_state = 0 + current_module = {} + + for line in modules_file: + if line.startswith('[submodule'): + if 'name' in current_module: + modules[current_module['name']] = current_module + + read_state = 1 + module_name = line.split(' ')[1].replace('"', '').replace(']', '').strip() + + current_module = {'name': module_name} + elif read_state == 1: + if '=' in line: + elements = line.split('=') + key = elements[0].strip() + value = elements[1].strip() + + current_module[key] = value + + if branch != 'current': + os.system(f'git checkout {current_branch}') + + os.chdir(cwd) + + return modules + +# Returns a list of active submodules for the given repo and branch +def get_active_submodules(git_repo : str = '.', branch : str = 'current') -> []: + modules = [] + + for module_name, module in get_submodules(git_repo, branch).items(): + if module['status'] != 'ignore': + modules.append(module_name) + + return modules |