Skip to content

Commit

Permalink
gh_release: Support deleting releases based on release type
Browse files Browse the repository at this point in the history
This commit updates the release delete subcommand to support deleting
based on release type: 'draft', 'prerelease' or 'release'.

Co-authored-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
  • Loading branch information
Flamefire and jcfr committed Mar 29, 2020
1 parent 7e73cf9 commit fc7e693
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ CLI

* ``release-notes``: Report a meaningful error if user omitted to set ``EDITOR`` env. variable.


Features (CLI and Python API)
-----------------------------

* ``delete`` command:

* `delete`:

* Add support for ``--release-type``. Fix issue [#50](https://github.com/j0057/github-release/pull/50). Contributed by [@Flamefire](https://github.com/Flamefire).


Issues (CLI and Python API)
---------------------------

Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ It understands the following commands:
--publish
--prerelease
--target-commitish TARGET_COMMITISH
--help
[ASSET_PATTERN]...
```

Expand All @@ -199,8 +200,19 @@ It understands the following commands:
--prerelease/--release
--dry-run
--verbose
--help
```

* delete:

```bash
--keep-pattern KEEP_PATTERN
--type [all, draft, prerelease, release]
--dry-run
--verbose
--help
[ASSET_PATTERN]...
```

## ``asset`` command

Expand Down Expand Up @@ -464,4 +476,4 @@ It is covered by the Apache License, Version 2.0:
http://www.apache.org/licenses/LICENSE-2.0

The license file was added at revision 0393859 on 2017-02-12, but you may
consider that the license applies to all prior revisions as well.
consider that the license applies to all prior revisions as well.
20 changes: 19 additions & 1 deletion github_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ def print_release_info(release, title=None, indent=""):
print_asset_info(i, asset, indent=indent)


def get_release_type(release):
"""Return the type of the release
Either 'draft', 'prerelease' (no draft) or 'release' (neither)
"""
if release['draft']:
return 'draft'
if release['prerelease']:
return 'prerelease'
return 'release'


def get_releases(repo_name, verbose=False):

releases = []
Expand Down Expand Up @@ -515,6 +527,7 @@ def gh_release_edit(repo_name, current_tag_name,
@gh_release.command("delete")
@click.argument("pattern")
@click.option("--keep-pattern")
@click.option("--release-type", type=click.Choice(['all', 'draft', 'prerelease', 'release']), default='all')
@click.option("--dry-run", is_flag=True, default=False)
@click.option("--verbose", is_flag=True, default=False)
@click.pass_obj
Expand All @@ -524,7 +537,7 @@ def _cli_release_delete(*args, **kwargs):


@_check_for_credentials
def gh_release_delete(repo_name, pattern, keep_pattern=None,
def gh_release_delete(repo_name, pattern, keep_pattern=None, release_type='all',
dry_run=False, verbose=False):
releases = get_releases(repo_name)
candidates = []
Expand All @@ -538,6 +551,11 @@ def gh_release_delete(repo_name, pattern, keep_pattern=None,
if keep_pattern is not None:
if fnmatch.fnmatch(release['tag_name'], keep_pattern):
continue
if release_type != 'all' and release_type != get_release_type(release):
if verbose:
print('skipping release {0}: type {1} is not {2}'.format(
release['tag_name'], get_release_type(release), release_type))
continue
candidates.append(release)
for release in candidates:
print('deleting release {0}'.format(release['tag_name']))
Expand Down

0 comments on commit fc7e693

Please sign in to comment.