1
0
Fork 0
mirror of https://github.com/Findus23/new-github-changelog-generator.git synced 2024-08-27 19:52:18 +02:00

fix config issues

This commit is contained in:
Lukas Winkler 2019-02-14 14:00:59 +01:00
parent cd4c04dc39
commit 2bbf8019ae
3 changed files with 21 additions and 17 deletions

View file

@ -1,7 +1,6 @@
from datetime import date
from typing import Iterable
from urllib.parse import urlencode
from warnings import warn
import requests
@ -16,7 +15,7 @@ class GithubAPI:
if token:
self.s.headers.update({'Authorization': 'token {}'.format(token)})
else:
warn("use Token!", stacklevel=2) # TODO
print("warning: please add a GitHub token_auth to the config file to avoid rate limits!")
self.s.headers.update({'User-Agent': 'github-changelog-generator'})
def call(self, url, parameters=None):

View file

@ -7,7 +7,7 @@ from shutil import copyfile
import pkg_resources
from generator import generate_changelog
from generator import generate_changelog, config
def parsed_date(s):
@ -49,11 +49,13 @@ def main():
help="output as debian changelog file")
args = parser.parse_args()
print(args)
if args.command == "init":
initfile(args.globally)
elif args.command == "generate":
if config.api_token == "none_found":
sys.exit("no config file found\nPlease create one by running\n"
"github-changelog-generator init")
generate_changelog(args.since, args.output, args.previous_version)
else:
raise ValueError("invalid subcommand")

View file

@ -9,24 +9,27 @@ class Config:
config_paths = ["./github-changelog-generator.yaml", "~/.config/github-changelog-generator.yaml"]
def __init__(self):
with open(self.get_config_path(), 'r') as stream:
try:
config = yaml.safe_load(stream)
self.api_token = config["api_token"] # type:str
self.labels_to_ignore = set(config["labels_to_ignore"])
self.sort_by_labels = config["sort_by_labels"] # type:list
self.repositories = config["repositories"] # type:list
self.is_matomo = config["is_matomo"] # type:bool
if self.is_matomo:
self.compare_config()
except KeyError as e:
sys.exit("required option '{}' is missing from the config".format(e.args[0]))
try:
with open(self.get_config_path(), 'r') as stream:
try:
config = yaml.safe_load(stream)
self.api_token = config["api_token"] # type:str
self.labels_to_ignore = set(config["labels_to_ignore"])
self.sort_by_labels = config["sort_by_labels"] # type:list
self.repositories = config["repositories"] # type:list
self.is_matomo = config["is_matomo"] # type:bool
if self.is_matomo:
self.compare_config()
except KeyError as e:
sys.exit("required option '{}' is missing from the config".format(e.args[0]))
except ValueError:
self.api_token = "none_found"
def get_config_path(self) -> str:
for path in self.config_paths:
if os.path.isfile(path):
return path
raise Exception("no config file found") # TODO
raise ValueError()
def compare_config(self) -> None:
used_config = self.__dict__