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 datetime import date
from typing import Iterable from typing import Iterable
from urllib.parse import urlencode from urllib.parse import urlencode
from warnings import warn
import requests import requests
@ -16,7 +15,7 @@ class GithubAPI:
if token: if token:
self.s.headers.update({'Authorization': 'token {}'.format(token)}) self.s.headers.update({'Authorization': 'token {}'.format(token)})
else: 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'}) self.s.headers.update({'User-Agent': 'github-changelog-generator'})
def call(self, url, parameters=None): def call(self, url, parameters=None):

View file

@ -7,7 +7,7 @@ from shutil import copyfile
import pkg_resources import pkg_resources
from generator import generate_changelog from generator import generate_changelog, config
def parsed_date(s): def parsed_date(s):
@ -49,11 +49,13 @@ def main():
help="output as debian changelog file") help="output as debian changelog file")
args = parser.parse_args() args = parser.parse_args()
print(args)
if args.command == "init": if args.command == "init":
initfile(args.globally) initfile(args.globally)
elif args.command == "generate": 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) generate_changelog(args.since, args.output, args.previous_version)
else: else:
raise ValueError("invalid subcommand") raise ValueError("invalid subcommand")

View file

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