def replace_cve_id()

in foundation_security_advisories/common_cve.py [0:0]


def replace_cve_id(cve: CVEAdvisory):
    """
    Replace the id of a given `CVEAdvisory` with a new CVE-ID.
    Returns True if the id of the given advisory has been changed and False
    if it hasn't.
    """
    old_id = cve.id
    if not prompt_yes_no(f"Should a new CVE-ID be reserved to replace {old_id}?"):
        print(f"Skipping {old_id}")
        return False
    print(f"Replacing CVE-ID for {old_id}")
    new_id = reserve_cve_id(cve.year)
    print(f"Reserved {new_id}")
    cve.id = new_id
    for instance in cve.instances:
        with open(instance.file_name) as r:
            file_content = r.read().replace(old_id + ":", new_id + ":")
        with open(instance.file_name, "w") as w:
            w.write(file_content)
        if os.getenv("CI"):
            subprocess.run(["git", "add", instance.file_name])
    print(f"Renamed {old_id} to {new_id}")
    return True