import os

from util import determine_version, get_changes
from util.codeberg import CodebergHelper


if __name__ == "__main__":
    token = os.environ.get("CODEBERG_TOKEN")

    if not token:
        raise ValueError("CODEBERG_TOKEN not set")

    helper = CodebergHelper(token=token)

    print(f"Repo base url: {helper.repo_base_url}")

    milestone = determine_version()
    changes = get_changes(milestone)

    if not changes:
        raise ValueError("No changes found")

    print(f"Running for milestone {milestone}")

    helper.close_milestone(milestone)
    helper.create_release(milestone, changes)
