Repository: scikit-learn/scikit-learn
File: maint_tools/update_tracking_issue.py (Python)

Code before:
    sys.exit(1)

if args.junit_file is None and args.tests_passed is None:
    print("Either --junit-file or --test-passed must be passed in")
    sys.exit(1)

gh = Github(args.bot_github_token)
issue_repo = gh.get_repo(args.issue_repo)
dt_now = datetime.now(tz=timezone.utc)
date_str = dt_now.strftime("%b %d, %Y")
title_query = f"CI failed on {args.ci_name}"
title = f"⚠️ {title_query} (last failure: {date_str}) ⚠️"

url = args.link_to_ci_run

if args.job_name is not None:
    run_id = int(args.link_to_ci_run.split("/")[-1])
    workflow_run = issue_repo.get_workflow_run(run_id)
    jobs = workflow_run.jobs()

    for job in jobs:
        if job.name == args.job_name:
            url = f"{url}/job/{job.id}"
            break
    else:
        raise UserWarning(
            f"Job '{args.job_name}' not found, the URL in the issue will link to the"
            " whole workflow's log rather than the job's one."
        )


def get_issue():
    login = gh.get_user().login
    issues = gh.search_issues(
        f"repo:{args.issue_repo} {title_query} in:title state:open author:{login}"
        " is:issue"
    )
    first_page = issues.get_page(0)
    # Return issue if it exist
    return first_page[0] if first_page else None


def create_or_update_issue(body=""):
    # Interact with GitHub API to create issue
    link = f"[{args.ci_name}]({url})"
    issue = get_issue()

    max_body_length = 60_000
    original_body_length = len(body)
    # Avoid "body is too long (maximum is 65536 characters)" error from github REST API
    if original_body_length > max_body_length:

Review comment (suggestion):
This is supposed to be a warning right not an exception? If that's the case use `warnings.warn(...)`


Code after:
if args.junit_file is not None and args.tests_passed is not None:
    print("--junit-file and --test-passed can not be set together")
    sys.exit(1)

if args.junit_file is None and args.tests_passed is None:
    print("Either --junit-file or --test-passed must be passed in")
    sys.exit(1)

gh = Github(args.bot_github_token)
issue_repo = gh.get_repo(args.issue_repo)
dt_now = datetime.now(tz=timezone.utc)
date_str = dt_now.strftime("%b %d, %Y")
title_query = f"CI failed on {args.ci_name}"
title = f"⚠️ {title_query} (last failure: {date_str}) ⚠️"

url = args.link_to_ci_run

if args.job_name is not None:
    run_id = int(args.link_to_ci_run.split("/")[-1])
    workflow_run = issue_repo.get_workflow_run(run_id)
    jobs = workflow_run.jobs()

    for job in jobs:
        if job.name == args.job_name:
            url = f"{url}/job/{job.id}"
            break
    else:
        warnings.warn(
            f"Job '{args.job_name}' not found, the URL in the issue will link to the"
            " whole workflow's log rather than the job's one."
        )


def get_issue():
    login = gh.get_user().login
    issues = gh.search_issues(
        f"repo:{args.issue_repo} {title_query} in:title state:open author:{login}"
        " is:issue"
    )
    first_page = issues.get_page(0)
    # Return issue if it exist
    return first_page[0] if first_page else None


def create_or_update_issue(body=""):
    # Interact with GitHub API to create issue
    link = f"[{args.ci_name}]({url})"
    issue = get_issue()

    max_body_length = 60_000
    original_body_length = len(body)