Skip to content

Commit

Permalink
Some old commits does not have bench as last line.
Browse files Browse the repository at this point in the history
  • Loading branch information
peregrineshahin committed Jun 16, 2023
1 parent b73ea49 commit 7870d41
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,19 @@ def get_master_info(url):
bench_search = re.compile(r"(^|\s)[Bb]ench[ :]+([1-9]\d{5,7})(?!\d)")
for idx, commit in enumerate(commits.json()):
message_lines = commit["commit"]["message"].strip().split("\n")
bench = bench_search.search(message_lines[-1].strip())
bench = next(
(
line
for line in reversed(message_lines)
if bench_search.search(line.strip())
),
None,
)
if idx == 0:
message = message_lines[0].strip()
date_str = commit["commit"]["committer"]["date"]
date = datetime.datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ")
if bench:
if bench is not None:
return {
"bench": bench.group(2),
"message": message,
Expand Down Expand Up @@ -664,14 +671,40 @@ def validate_form(request):
if request.POST.get("rescheduled_from"):
data["rescheduled_from"] = request.POST["rescheduled_from"]

def extract_last_occurrence(m):
lines = m.strip().split("\n")

last_occurrence = None

# Find the last occurrence
for line in reversed(lines):
if re.match(r"(^|\s)[Bb]ench[ :]+([1-9]\d{5,7})(?!\d)", line.strip()):
last_occurrence = re.search(
r"([1-9]\d{5,7})(?!\d)", line.strip()
).group(1)
break

return last_occurrence

def strip_message(m):
lines = m.strip().split("\n")
last_line = lines[-1].strip()
if re.match(r"(^|\s)[Bb]ench[ :]+([1-9]\d{5,7})(?!\d)", last_line):
lines[-1] = ""
s = "\n".join(lines)
s = re.sub(r"[ \t]+", " ", s)
s = re.sub(r"\n+", r"\n", s)

last_occurrence = extract_last_occurrence(m)

# Remove the last occurrence if it exists
if last_occurrence:
for i in range(len(lines) - 1, -1, -1):
line = lines[i].strip()
if re.match(
r"(^|\s)[Bb]ench[ :]+" + re.escape(last_occurrence) + r"(?!\d)",
line,
):
lines[i] = ""
break

s = " ".join(lines)
s = re.sub(r"\s+", " ", s)
s = re.sub(r"\n+", "\n", s)
return s.rstrip()

# Fill new_signature/info from commit info if left blank
Expand All @@ -687,10 +720,7 @@ def strip_message(m):
if "commit" not in c:
raise Exception("Cannot find branch in developer repository")
if len(data["new_signature"]) == 0:
bs = re.compile(r"(^|\s)[Bb]ench[ :]+([1-9]\d{5,7})(?!\d)")
lines = c.split("\n")
last_line = lines[-1].strip()
m = bs.search(last_line)
m = extract_last_occurrence(c)
if m:
data["new_signature"] = m.group(2)
else:
Expand Down

0 comments on commit 7870d41

Please sign in to comment.