Skip to content

Commit

Permalink
add option to auto-select ref_2 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
bdattoma committed May 21, 2024
1 parent f1a0b03 commit 6520df1
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions ods_ci/utils/scripts/fetch_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,29 @@ def checkout_repository(ref):
ret = execute_command("git checkout")


def extract_test_cases_from_ref(repo_local_path, ref):
def get_latest_updated_branch(ref_to_exclude):
"""
List the remote branches and sort by last commit date (ASC order), exclude $ref_to_exclude and get latest
"""
ret = execute_command(f"git branch -a --sort=committerdate | grep -v {ref_to_exclude}$ | tail -1")
if ret != "":
print(f"Done. {ret} branch selected as ref_2")
return ret
else:
raise Exception("Failed to auto-selecting ref_2 branch.")


def extract_test_cases_from_ref(repo_local_path, ref, auto=False, ref_to_exclude=None):
"""
Navigate to the $test_repo directory, checkouts the target branch/commit ($ref) and extracts
the test case titles leveraging RobotFramework TestSuiteBuilder() and TestCasesFinder() classes
"""
curr_dir = os.getcwd()
try:
os.chdir(repo_local_path)
if auto:
print("\n---| Auto-selecting ref_2 branch")
ref = get_latest_updated_branch(ref_to_exclude)
checkout_repository(ref)
builder = TestSuiteBuilder()
testsuite = builder.build("ods_ci/tests/")
Expand Down Expand Up @@ -86,7 +101,7 @@ def generate_rf_argument_file(tests, output_filepath):
print(err)


def extract_new_test_cases(test_repo, ref_1, ref_2, output_argument_file):
def extract_new_test_cases(test_repo, ref_1, ref_2, ref_2_auto, output_argument_file):
"""
Wrapping function for all the new tests extraction stages.
"""
Expand All @@ -95,7 +110,7 @@ def extract_new_test_cases(test_repo, ref_1, ref_2, output_argument_file):
tests_1 = extract_test_cases_from_ref(repo_local_path, ref_1)
print(f"\nDone. Found {len(tests_1)} test cases")
print(f"\n---| Extracting test cases from {ref_2} branch/commit |---")
tests_2 = extract_test_cases_from_ref(repo_local_path, ref_2)
tests_2 = extract_test_cases_from_ref(repo_local_path, ref_2, ref_2_auto, ref_1)
print(f"Done. Found {len(tests_2)} test cases")
print("\n---| Computing differences |----")
new_tests = list(set(tests_1) - set(tests_2))
Expand Down Expand Up @@ -146,12 +161,20 @@ def extract_new_test_cases(test_repo, ref_1, ref_2, output_argument_file):
dest="ref_2",
default="releases/2.8.0",
)
parser.add_argument(
"--ref2-auto",
help="Auto select the second branch to use for comparison (i.e., latest updated branch)",
action="store",
dest="ref_2_auto",
default=False,
)

args = parser.parse_args()

extract_new_test_cases(
args.test_repo,
args.ref_1,
args.ref_2,
args.ref_2_auto,
args.output_argument_file,
)

0 comments on commit 6520df1

Please sign in to comment.