Skip to content

Commit

Permalink
Merge pull request #23 from d3b-center/default-repo
Browse files Browse the repository at this point in the history
✨ Set default repo from git
  • Loading branch information
fiendish committed Jul 2, 2020
2 parents 365747d + 907b4ff commit aae22a3
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions d3b_release_maker/cli.py
@@ -1,10 +1,29 @@
#!/usr/bin/env python
import click
import re
import subprocess

from d3b_release_maker.release_maker import (
make_release,
new_notes,
)
from d3b_release_maker.release_maker import make_release, new_notes


def get_repository():
"""
Try to retrieve the github repository by extracting it from the current git
repository's 'origin' url.
"""
try:
result = subprocess.check_output(
["git", "remote", "get-url", "origin"], stderr=subprocess.DEVNULL
)
except subprocess.CalledProcessError:
# If the git command fails, bail early
return None

result = result.decode().strip()
match = re.match(r".*:([\w\d0-9-]+\/[\w\d-]+)", result)
if match:
return match.group(1)
return None


@click.group(context_settings={"help_option_names": ["-h", "--help"]})
Expand All @@ -26,6 +45,7 @@ def options(function):
"--repo",
prompt="The github repository (e.g. my-organization/my-project-name)",
help="The github organization/repository to make a release for",
default=get_repository,
)(function)
return function

Expand Down

0 comments on commit aae22a3

Please sign in to comment.