Skip to content

Commit

Permalink
Improve the generated text for the build reports
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardkaindl committed Oct 17, 2024
1 parent 05c2ebf commit 835cb84
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions build_pr_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,13 +1148,13 @@ def failure_summary(fails: List[Tuple[str, str]]) -> str:
def generate_build_results(installed, passed, fails, about_build_host) -> str:
"""Generate a report in markdown format for cut-and-paste into the PR comment."""

build_results = f"Auto-submitted build results{about_build_host}: (see disclaimer below)\n"
build_results = f"Build results{about_build_host}:\n"
build_results += "The following specs were checked (extracted from `gh pr diff`):\n"
build_results += "- `" + "`\n- `".join(installed + passed) + "`\n\n"

if installed or passed:
build_results += "The following specs were installed or passed building in this run:"
build_results += " (variants are shortened, e.g. no disabled variants)\n"
build_results += "These specs were installed:"
build_results += " (`~disabled` variants are hidden using `sed`)\n"
build_results += "```py\n"
cmd = ["bin/spack", "find", "--variants", *(installed + passed)]
build_results += " ".join(cmd)
Expand All @@ -1177,19 +1177,10 @@ def generate_build_results(installed, passed, fails, about_build_host) -> str:
build_results += failure_summary(fails)
if fails:
build_results += (
"\nThis report was generated by a script and may contain errors.\n"
"The idea would be that I/we can improve this script to get fast checks for PRs!\n"
"I think this is already much better than just checking checksums manually,"
"and it should get better as more build error cases get covered properly.\n\n"
"If the build report contains real errors, please fix them and push the changes.\n\n"
"The script tries to add a label to indicate the build status,\n"
"and set the 'draft' status of the PR.\n\n"
"After the correct fix is pushed, to the PR branch and change the"
" PR status to 'Ready for review'.\n\n"
"Generated and submitted by "
"\nThis report was generated by a script that is a work-in-progress.\n"
"If this found a real issue, please fix it and push the changes.\n\n"
)
else:
build_results += "Generated and submitted by "
build_results += "Generated by "
git_dir = os.path.dirname(os.path.realpath(__file__))
err, stdout, stderr = run(["git", "-C", git_dir, "config", "--get", "remote.origin.url"])
if not err:
Expand Down Expand Up @@ -1299,7 +1290,7 @@ def is_approved_or_changes_requested_by_me(pr: Dict[str, Any]) -> bool:

approvers = get_reviews(pr, "APPROVED")
if approvers:
print("Approved by" + ", ".join(approvers))
print("Approved by " + ", ".join(approvers))

requesters = get_reviews(pr, "CHANGES_REQUESTED")
if requesters:
Expand Down Expand Up @@ -1330,13 +1321,22 @@ def pull_request_is_ready_for_review(args: argparse.Namespace) -> bool:
def create_change_request(args: argparse.Namespace, build_results: str) -> ExitCode:
"""Create a change request for the failed specs."""
print(build_results)
if not (args.yes or input("Create a change request for the failed specs [y/n]: ") == "y"):
return 1

print("Creating a change request for the failed specs.")
if not pull_request_is_ready_for_review(args):
print("The PR is not ready for review, skipping creating a change request.")
return Success

if not (args.yes or input("Create a change request for the failed specs [y/n]: ") == "y"):
return 1
print("Creating a change request for the failed specs.")

if args.yes:
build_results += (
"The script automatically adds a label for tracking to indicate the build status,\n"
"and sets the 'draft' status of the PR.\n\n"
"If there is no (longer) an issue, please change the PR to 'Ready for review' again."
)

# Remove ANSI color codes from the output:
build_results = re.sub(r"\x1b\[[0-9;]*m", "", build_results)

Expand Down

0 comments on commit 835cb84

Please sign in to comment.