From dde2a527b0b84dd10ac4b7ac2692ba67e04f367f Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 16 Jan 2018 15:49:53 +0100 Subject: [PATCH] changelog.py: Adjust categories and labels: Enhancement, Bug, ITL, Documentation, Support This PR allows to adjust the categories and matching labels. If no label matches, "Support" is the old hardcoded default. Issues with the "Documentation" and "ITL" label will be put into their respective category at the bottom before "Support". This increases readability and allows users to focus on the core vs additional config and docs. "Support" also applies to labels such as "code-quality", "Tests" and "Packages"/"Installation". Note: Labels are case sensitive. The order of the categories dictionary is important too. Since issues and PRs are the same for GitHub, and we don't require an issue for a PR anymore, we sometimes have duplicates. This patch adds an inline label called "PR" to highlight these PRs in the Changelog. refs #5989 --- changelog.py | 53 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/changelog.py b/changelog.py index 7b0da34ad..a6bf2afbc 100755 --- a/changelog.py +++ b/changelog.py @@ -8,6 +8,10 @@ import sys import os from datetime import datetime from collections import defaultdict +from collections import OrderedDict + +################################# +## Env Config try: github_auth_username = os.environ['ICINGA_GITHUB_AUTH_USERNAME'] @@ -27,10 +31,34 @@ except: print "ERROR: Environment variable 'ICINGA_GITHUB_PROJECT' is not set." sys.exit(1) +################################# +## Config + changelog_file = "CHANGELOG.md" # TODO: config param debug = 1 -ignored_labels = ["high", "low", "bug", "enhancement", "feedback", "question", "backported"] +# Keep this in sync with GitHub labels. +ignored_labels = [ + "high-priority", "low-priority", + "bug", "enhancement", + "needs-feedback", "question", "duplicate", "invalid", "wontfix", + "backported", "build-fix" +] + +# Selectively show and collect specific categories +# +# (category, list of case sensitive matching labels) +# The order is important! +# Keep this in sync with GitHub labels. +categories = OrderedDict( +[ + ("Enhancement", ["enhancement"]), + ("Bug", ["bug", "crash"]), + ("ITL", ["ITL"]), + ("Documentation", ["Documentation"]), + ("Support", ["code-quality", "Tests", "Packages", "Installation"]) +] +) ################################# ## Helpers @@ -74,12 +102,17 @@ def fetch_github_resources(uri, params = {}): return resources def issue_type(issue): - if "bug" in [label["name"] for label in issue["labels"]]: - return "Bug" - elif "enhancement" in [label["name"] for label in issue["labels"]]: - return "Enhancement" - else: - return "Support" + issue_labels = [label["name"] for label in issue["labels"]] + + # start with the least important first (e.g. "Support", "Documentation", "Bug", "Enhancement" as order) + for category in reversed(categories): + labels = categories[category] + + for label in labels: + if label in issue_labels: + return category + + return "Support" def escape_markdown(text): #tmp = text.replace('&', '&').replace('<', '<').replace('>', '>') @@ -91,6 +124,10 @@ def escape_markdown(text): def format_labels(issue): labels = filter(lambda label: label not in ignored_labels, [label["name"] for label in issue["labels"]]) + # Mark PRs as custom label + if "pull_request" in issue: + labels.append("PR") + if len(labels): return " (" + ", ".join(labels) + ")" else: @@ -175,7 +212,7 @@ for milestone in sorted(milestones.values(), key=lambda ms: (ms["due_on"], ms["t if len(ms_description) > 0: write_changelog("### Notes\n\n" + ms_description + "\n") # Don't escape anything, we take care on Github for valid Markdown - for category in ["Enhancement", "Bug", "Support"]: + for category, labels in categories.iteritems(): try: ms_issues = issues[milestone["title"]][category] except KeyError: