Skip to content

Commit acbb357

Browse files
committed
Fixing fetch job success/fail evaluation
1 parent c76a385 commit acbb357

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

src/source_repo/svn.py

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def convert(ctx: Context) -> None:
7575
# If the repo already exists, and is already up to date, then exit early
7676
### EXTERNAL COMMAND: svn log ###
7777
_cleanup(ctx, commands)
78-
log(ctx, "Ending svn repo conversion job", "info")
78+
log(ctx, "Ending svn repo conversion job; repo up to date", "info")
7979
return
8080

8181
### EXTERNAL COMMAND: svn log ###
@@ -687,9 +687,9 @@ def _log_number_of_revs_out_of_date(ctx: Context, commands: dict) -> None:
687687

688688
if log_remaining_revs:
689689

690-
git_repo_latest_converted_svn_rev_start = ctx.job.get("stats",{}).get("local",{}).get("git_repo_latest_converted_svn_rev_start","")
691-
cmd_svn_log_remaining_revs = commands["cmd_svn_log"] + ["--revision", f"{git_repo_latest_converted_svn_rev_start}:HEAD"]
692-
password = job_config.get("password","")
690+
git_repo_latest_converted_svn_rev_start = ctx.job.get("stats",{}).get("local",{}).get("git_repo_latest_converted_svn_rev_start", 1)
691+
cmd_svn_log_remaining_revs = commands["cmd_svn_log"] + ["--revision", f"{git_repo_latest_converted_svn_rev_start}:HEAD"]
692+
password = job_config.get("password","")
693693

694694
# Parse the output to get the number of remaining revs
695695
svn_log = cmd.run_subprocess(ctx, cmd_svn_log_remaining_revs, password, name="svn_log_remaining_revs")
@@ -707,13 +707,13 @@ def _calculate_batch_revisions(ctx: Context, commands: dict) -> bool:
707707
"""
708708

709709
# Get config values
710-
job_config = ctx.job.get("config",{})
711-
fetch_batch_size = int(job_config.get("fetch_batch_size", 0))
712-
password = job_config.get("password","")
713-
cmd_svn_log = commands["cmd_svn_log"]
714-
git_repo_latest_converted_svn_rev_start = int(ctx.job.get("stats",{}).get("local",{}).get("git_repo_latest_converted_svn_rev_start", 0))
715-
this_batch_end_rev = 0
716-
log_failure_message = ""
710+
job_config = ctx.job.get("config",{})
711+
fetch_batch_size = int(job_config.get("fetch_batch_size", 0))
712+
password = job_config.get("password","")
713+
cmd_svn_log = commands["cmd_svn_log"]
714+
git_repo_latest_converted_svn_rev_start = int(ctx.job.get("stats",{}).get("local",{}).get("git_repo_latest_converted_svn_rev_start", 0))
715+
this_batch_end_rev = 0
716+
log_failure_message = ""
717717

718718
# Pick a revision number to start with; may or may not be a real rev number
719719
this_batch_start_rev = int(git_repo_latest_converted_svn_rev_start + 1)
@@ -868,7 +868,8 @@ def _verify_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> N
868868

869869
## Gather needed inputs
870870
action = "git svn fetch"
871-
ctx.job["result"]["failures"] = []
871+
errors = []
872+
warnings = []
872873
git_svn_fetch_output_for_errors = list(git_svn_fetch_result.get("output",""))
873874
git_svn_fetch_output = list(git_svn_fetch_result.get("output",""))
874875
job_config = ctx.job.get("config","")
@@ -877,8 +878,8 @@ def _verify_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> N
877878

878879

879880
# Check if the repo is valid after the fetch
880-
if _check_if_repo_exists_locally(ctx, "end"):
881-
pass
881+
if not _check_if_repo_exists_locally(ctx, "end"):
882+
errors.append("Repo not valid")
882883

883884

884885
## Check for any errors in the command output
@@ -887,8 +888,11 @@ def _verify_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> N
887888
# Shorten the number of lines in the git svn output,
888889
# by removing lines which we know are not errors / may be false positives
889890
not_errors = [
890-
r"Checked through r[0-9]+", # "Checked through r123456" <- likely most of the lines
891-
"Ignoring error from SVN", # "W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found..."
891+
r"\"\\tA\\t", # "\tA\tdir/file.ext", # Add a new file
892+
r"\"\\tM\\t", # "\tM\tdir/file.ext", # Modify a file
893+
r"\"\\tD\\t", # "\tD\tdir/file.ext", # Delete a file
894+
r"Checked through r[0-9]+", # "Checked through r123456" # Many of the lines
895+
"Ignoring error from SVN", # "W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found..."
892896
]
893897

894898
# Remove the not_error lines from the output list
@@ -980,7 +984,7 @@ def _verify_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> N
980984

981985
if line_match:
982986

983-
ctx.job["result"]["failures"].append(f"Error message: {error_category}: {line}")
987+
errors.append(f"Error message: {error_category}: {line}")
984988

985989
# Remove the svn fetch error line from the process output list to avoid duplicate output,
986990
# if one line in the error message matches multiple error_messages
@@ -995,36 +999,55 @@ def _verify_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> N
995999
# then we know we succeeded
9961000
this_batch_end_rev = int(job_stats_local.get("this_batch_end_rev",""))
9971001
if not (latest_converted_svn_rev and this_batch_end_rev and latest_converted_svn_rev == this_batch_end_rev):
998-
ctx.job["result"]["failures"].append(f"git_repo_latest_converted_svn_rev_end: {latest_converted_svn_rev} != this_batch_end_rev: {this_batch_end_rev}")
1002+
warnings.append(f"git_repo_latest_converted_svn_rev_end: {latest_converted_svn_rev} != this_batch_end_rev: {this_batch_end_rev}")
9991003

10001004

10011005
## Get the batch size, and git commits before and after, to check if they add up
10021006
fetching_batch_count = int(job_stats_local.get("fetching_batch_count", 0))
10031007
git_repo_commit_count_end = int(job_stats_local.get("git_repo_commit_count_end", 0))
10041008
git_repo_commit_count_start = int(job_stats_local.get("git_repo_commit_count_start", 0))
10051009
git_commits_added = int(git_repo_commit_count_end - git_repo_commit_count_start)
1010+
git_commits_missed = int(git_commits_added - fetching_batch_count)
10061011

10071012
ctx.job["stats"]["local"].update({"git_commits_added": git_commits_added})
1013+
ctx.job["stats"]["local"].update({"git_commits_missed": git_commits_missed})
10081014

1009-
if git_commits_added != fetching_batch_count:
1010-
ctx.job["result"]["failures"].append(f"git_commits_added: {git_commits_added} != fetching_batch_count: {fetching_batch_count}")
1015+
if git_commits_added == 0:
1016+
errors.append(f"git_commits_added == 0, fetch failed to add any new commits")
1017+
1018+
elif git_commits_added != fetching_batch_count:
1019+
warnings.append(f"git_commits_added: {git_commits_added} != fetching_batch_count: {fetching_batch_count}; git_commits_missed {git_commits_missed}")
10111020

10121021

10131022
## Count how many, and which revs were checked in this fetch
10141023
# Verify each of them are in the git log output
10151024
# TODO: Implement this
10161025
# git_svn_fetch_output
10171026

1018-
## Make final success / fail call
10191027

1020-
if len(ctx.job["result"]["failures"]) > 0:
1028+
1029+
1030+
1031+
# Assign the lists to the job result data for log output
1032+
ctx.job["result"]["errors"] = errors
1033+
ctx.job["result"]["warnings"] = warnings
1034+
10211035

1022-
reason = "output failed verification"
1036+
## Make final success / fail call
1037+
if len(errors) > 0:
1038+
1039+
reason = "fetch failed with errors"
10231040
set_job_result(ctx, action, reason, False)
10241041
log(ctx, f"git svn fetch incomplete", "error", structured_log_dict)
10251042

1043+
elif len(warnings) > 0:
1044+
1045+
reason = "fetch passed with warnings"
1046+
set_job_result(ctx, action, reason, True)
1047+
log(ctx, f"git svn fetch incomplete", "error", structured_log_dict)
1048+
10261049
else:
10271050

1028-
reason = "output passed verification"
1051+
reason = "fetch completed successfully"
10291052
set_job_result(ctx, action, reason, True)
10301053
log(ctx, f"git svn fetch complete", "info", structured_log_dict)

0 commit comments

Comments
 (0)