diff --git a/galaxy_release_util/bootstrap_history.py b/galaxy_release_util/bootstrap_history.py index ebcbf57..cbd49b1 100644 --- a/galaxy_release_util/bootstrap_history.py +++ b/galaxy_release_util/bootstrap_history.py @@ -1,6 +1,7 @@ # Little script to make HISTORY.rst more easy to format properly, lots TODO # pull message down and embed, handle multiple, etc... +import logging import calendar import datetime import os @@ -13,12 +14,11 @@ import click from github.PullRequest import PullRequest +from github import GithubException from packaging.version import Version from .cli.options import ( ClickVersion, - #next_version_option, - freeze_date_option, galaxy_root_option, group_options, ) @@ -336,18 +336,29 @@ help="Next release version.", ) +freeze_date_option = click.option( + "--freeze-date", + type=click.DateTime(), + default=datetime.datetime.today(), +) + +dry_run_option = click.option( + "--dry-run", + type=bool, + default=False, +) + +log = logging.getLogger(__name__) + @click.group(help="Subcommands of this script can perform various tasks around creating Galaxy releases") def cli(): pass @cli.command(help="Create release checklist issue on GitHub") -@group_options(release_version_argument, next_version_option, freeze_date_option, galaxy_root_option) -def create_release_issue(release_version: Version, next_version: Version, freeze_date, galaxy_root: Path): - """ - TODO - """ # TODO ADD COMMENT - +@group_options(release_version_argument, next_version_option, freeze_date_option, galaxy_root_option, dry_run_option) +def create_release_issue(release_version: Version, next_version: Version, freeze_date, galaxy_root: Path, dry_run: bool): + """ Create release publication issue.""" previous_version = _get_previous_release_version(galaxy_root, release_version) next_version = next_version or _get_next_release_version(release_version) assert next_version > release_version, "Next release version should be greater than release version" @@ -358,21 +369,25 @@ def create_release_issue(release_version: Version, next_version: Version, freeze previous_version=previous_version, freeze_date=freeze_date, ) - release_issue_contents = RELEASE_ISSUE_TEMPLATE.safe_substitute(**release_issue_template_params) - #print(release_issue_contents) github = github_client() repo = github.get_repo(f"{PROJECT_OWNER}/{PROJECT_NAME}") - # TODO error: must enable github tokern !!!!! - assert token????? - - release_issue = repo.create_issue( - title=f"Publication of Galaxy Release v {release_version}", - body=release_issue_contents, - ) - return release_issue + if dry_run: + print(release_issue_contents) + return None + try: + release_issue = repo.create_issue( + title=f"Publication of Galaxy Release v {release_version}", + body=release_issue_contents, + ) + return release_issue + except GithubException: + log.exception( + "Failed to create an issue on GitHub. You need to be authenticated to use GitHub API." + "\nSee galaxy_release_util/github_client.py" + ) @cli.command(help="Create or update release changelog") diff --git a/galaxy_release_util/cli/options.py b/galaxy_release_util/cli/options.py index a4dadb8..8c9f1b7 100644 --- a/galaxy_release_util/cli/options.py +++ b/galaxy_release_util/cli/options.py @@ -20,18 +20,6 @@ ) -release_date_option = click.option( - "--release-date", - type=click.DateTime(), -) - -freeze_date_option = click.option( - "--freeze-date", - type=click.DateTime(), - default=datetime.datetime.today(), -) - - def group_options(*options): def wrapper(function): for option in reversed(options):