From 6887f2d53beba3c1aff4f503ade46f7f0d5402b8 Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Thu, 14 Feb 2019 13:47:07 +0100 Subject: [PATCH] better cli and README.md --- README.md | 31 ++++++++++++++++++++++++++++ generator/cli.py | 40 ++++++++++++++++++++++++++++++------ generator/defaultconfig.yaml | 4 ++-- setup.py | 7 +++---- 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4f4f60e --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# github-changelog-generator + +*quickly generate changelogs based on closed github issues and merged PRs since the last release* + +## Install + +```bash +pip3 install --user https://github.com/Findus23/new-github-changelog-generator/archive/master.zip +``` +(at least until it is published on pypi) + +## Usage + +Run `github-changelog-generator init` to create an example config file. +The GitHub API limits to 60 requests per hour by default, so to use this properly, create a [*personal access token*](https://github.com/settings/tokens) (you don't need to tick any box) and paste it into the `api_token` setting in the config file. + +Afterwards you can simply create changelogs by specifying the tag or date of the previous release: + +```bash + github-changelog-generator generate --since "2019-01-25 00:00:00" --debian-changelog + + github-changelog-generator generate --previous-version="3.8.0" --html + ``` + + You can find more options with `--help`: + + ```bash + github-changelog-generator --help + github-changelog-generator init --help + github-changelog-generator generate --help + ``` \ No newline at end of file diff --git a/generator/cli.py b/generator/cli.py index 6f5a142..c32c6d1 100644 --- a/generator/cli.py +++ b/generator/cli.py @@ -1,5 +1,11 @@ import argparse -from datetime import datetime, timedelta +import sys +from datetime import datetime +from os import path +from os.path import expanduser +from shutil import copyfile + +import pkg_resources from generator import generate_changelog @@ -12,20 +18,42 @@ def parsed_date(s): raise argparse.ArgumentTypeError(msg) -def main(): - since = datetime.today() - timedelta(5) +def initfile(globally: bool): + home = expanduser("~") + targetfile = home + "/.config/github-changelog-generator.yaml" if globally else "./github-changelog-generator.yaml" + if path.exists(targetfile): + sys.exit("The config file at '{path}' already exists.".format(path=targetfile)) + default_config_file = pkg_resources.resource_filename('generator', 'defaultconfig.yaml') + copyfile(default_config_file, targetfile) + print("An example config has been copied to '{path}'. \n".format(path=targetfile) + + "Please edit it to your use case and don't forget to add a GitHub api_token to not run into rate limits.") + +def main(): parser = argparse.ArgumentParser(description='Generate changelogs from closed GitHub issues and merged PRs.') - sincegroup = parser.add_mutually_exclusive_group() + subparsers = parser.add_subparsers(dest="command") + + init = subparsers.add_parser("init") + init.add_argument("--global", dest="globally", action='store_true', help="store config file in ~/.config/") + init.set_defaults(globally=False) + generate = subparsers.add_parser("generate") + sincegroup = generate.add_mutually_exclusive_group() sincegroup.add_argument('--since', metavar='"YYYY-MM-DD HH:MM:SS"', type=parsed_date, help='date of previous release') sincegroup.add_argument('--previous-version', type=str) - group = parser.add_mutually_exclusive_group(required=True) + group = generate.add_mutually_exclusive_group(required=True) group.add_argument('--html', action='store_const', const="html", dest="output", help="output as HTML") group.add_argument('--markdown', action='store_const', const="markdown", dest="output", help="output as markdown") group.add_argument('--debian-changelog', action='store_const', const="debianchangelog", dest="output", help="output as debian changelog file") args = parser.parse_args() - generate_changelog(args.since, args.output, args.previous_version) + print(args) + + if args.command == "init": + initfile(args.globally) + elif args.command == "generate": + generate_changelog(args.since, args.output, args.previous_version) + else: + raise ValueError("invalid subcommand") diff --git a/generator/defaultconfig.yaml b/generator/defaultconfig.yaml index 249d9d5..f44d709 100644 --- a/generator/defaultconfig.yaml +++ b/generator/defaultconfig.yaml @@ -1,4 +1,4 @@ -api_token: null +api_token: null # replace 'null' with a proper token from https://github.com/settings/tokens to avoid rate limiting issues. repositories: - matomo-org/matomo - matomo-org/tag-manager @@ -39,4 +39,4 @@ sort_by_labels: - 'c: i18n' - RFC -is_matomo: True \ No newline at end of file +is_matomo: True # set to False if you don't want to generate changelogs for the Matomo project \ No newline at end of file diff --git a/setup.py b/setup.py index c13a85d..1b475e7 100644 --- a/setup.py +++ b/setup.py @@ -6,9 +6,8 @@ setup( name='github-changelog-generator', version='0.0.1', packages=setuptools.find_packages(), - entry_points = { + entry_points={ 'console_scripts': ['github-changelog-generator=generator.cli:main'], - } - # license='Creative Commons Attribution-Noncommercial-Share Alike license', - # long_description=open('README.md').read(), + }, + long_description=open('README.md').read() )