From: Steven R. Loomis Date: Thu, 25 Aug 2022 22:18:03 +0000 (-0500) Subject: ICU-21755 commit checker: section rewrite, summary count X-Git-Tag: cldr/2022-12-02~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3650236abbc5b811bcf49e7d0d39196d06f11e3f;p=icu ICU-21755 commit checker: section rewrite, summary count - rewrite to semi modular code - run the sections first, then get counts - section counts in ToC, skip if empty - many link improvements: linkify bugs and commits rather than separate lines --- diff --git a/tools/commit-checker/check.py b/tools/commit-checker/check.py index 104f7cfab83..a245e51ca1c 100644 --- a/tools/commit-checker/check.py +++ b/tools/commit-checker/check.py @@ -6,6 +6,7 @@ import argparse import itertools import os +import io import re import sys import datetime @@ -159,35 +160,40 @@ def issue_id_to_url(issue_id, jira_hostname, **kwargs): return "https://%s/browse/%s" % (jira_hostname, issue_id) -def pretty_print_commit(commit, github_url, **kwargs): - print("- %s `%s`" % (commit.commit.hexsha[:7], commit.commit.summary)) - print("\t- Authored by %s <%s>" % (commit.commit.author.name, commit.commit.author.email)) - print("\t- Committed at %s" % commit.commit.committed_datetime.isoformat()) - print("\t- GitHub Link: %s" % "%s/commit/%s" % (github_url, commit.commit.hexsha)) +def pretty_print_commit(commit, github_url, file=None, **kwargs): + fixed_summary = commit.commit.summary + if commit.issue_id and fixed_summary[:(len(commit.issue_id)+1)] == commit.issue_id+' ': + # linkify beginning of commit message + fixed_summary = fixed_summary[len(commit.issue_id)+1:] + fixed_summary = '[%s](%s) `%s`' % (commit.issue_id, issue_id_to_url(commit.issue_id, **kwargs), fixed_summary) + else: + fixed_summary = '`%s`' % fixed_summary + print("- [%s](%s) %s" % (commit.commit.hexsha[:7], ("%s/commit/%s" % (github_url, commit.commit.hexsha)), fixed_summary), file=file) + print("\t- Authored by %s <%s>" % (commit.commit.author.name, commit.commit.author.email), file=file) + print("\t- Committed at %s" % commit.commit.committed_datetime.isoformat(), file=file) -def pretty_print_issue(issue, type=None, **kwargs): - print("- %s: `%s`" % (issue.issue_id, issue.issue.fields.summary)) +def pretty_print_issue(issue, type=None, file=None, **kwargs): + print("- [%s](%s): `%s`" % (issue.issue_id, issue_id_to_url(issue.issue_id, **kwargs), issue.issue.fields.summary), file=file) if type: - print("\t- _%s_" % type) + print("\t- _%s_" % type, file=file) if issue.issue.fields.assignee: - print("\t- Assigned to %s" % issue.issue.fields.assignee.displayName) + print("\t- Assigned to %s" % issue.issue.fields.assignee.displayName, file=file) else: - print("\t- No assignee!") + print("\t- No assignee!", file=file) # If actually under review, print reviewer if jira_issue_under_review(issue) and issue.issue.fields.customfield_10031: - print("\t- Reviewer: %s" % issue.issue.fields.customfield_10031.displayName) - print("\t- Jira Link: %s" % issue_id_to_url(issue.issue_id, **kwargs)) - print("\t- Status: %s" % issue.issue.fields.status.name) + print("\t- Reviewer: %s" % issue.issue.fields.customfield_10031.displayName, file=file) + print("\t- Status: %s" % issue.issue.fields.status.name, file=file) if(issue.issue.fields.resolution): - print("\t- Resolution: " + issue.issue.fields.resolution.name) + print("\t- Resolution: " + issue.issue.fields.resolution.name, file=file) if(issue.issue.fields.fixVersions): for version in issue.issue.fields.fixVersions: - print("\t- Fix Version: " + version.name) + print("\t- Fix Version: " + version.name, file=file) else: - print("\t- Fix Version: _none_") + print("\t- Fix Version: _none_", file=file) if issue.issue.fields.components and len(issue.issue.fields.components) > 0: - print("\t- Component(s): " + (' '.join(sorted([str(component.name) for component in issue.issue.fields.components])))) + print("\t- Component(s): " + (' '.join(sorted([str(component.name) for component in issue.issue.fields.components]))), file=file) def get_commits(commit_metadata_obj, repo_root, rev_range, **kwargs): """ @@ -203,7 +209,7 @@ def get_commits(commit_metadata_obj, repo_root, rev_range, **kwargs): (sha, issue_id, message) = from_commit_metadata if message: # Update message if found - commit.message = commit.message + "\nCOMMIT_METADATA: " + message + commit.message = str(commit.message) + "\nCOMMIT_METADATA: " + message if not issue_id: match = re.search(r"^(\w+-\d+) ", commit.message) if match: @@ -335,9 +341,9 @@ def get_single_jira_issue(issue_id, **kwargs): print("Loaded single issue %s (%d in cache) " % (issue_id, len(jira_issue_map)), file=sys.stderr) return icu_issue -def toplink(): - print("[🔝Top](#table-of-contents)") - print() +def toplink(file=None): + print("[🔝Top](#table-of-contents)", file=file) + print(file=file) def sectionToFragment(section): return re.sub(r' ', '-', section.lower()) @@ -346,12 +352,14 @@ def sectionToFragment(section): # """convert section name to am anchor""" # return "" % sectionToFragment(section) -def print_sectionheader(section): +def print_sectionheader(section, file=None): """Print a section (###) header, including anchor""" - print("### %s" % (section)) + print("### %s" % (section), file=file) #print("### %s%s" % (aname(section), section)) def main(): + global total_problems + global commits global fixversion_to_skip args = flag_parser.parse_args() print("TIP: Have you pulled the latest main? This script only looks at local commits.", file=sys.stderr) @@ -406,7 +414,14 @@ def main(): COMMIT_OPEN_JIRA = "Commits with Open Jira Issue" COMMIT_JIRA_NOT_IN_QUERY = "Commits with Jira Issue Not Found" ISSUE_UNDER_REVIEW = "Issue is under Review" - + EXCLUDED_COMMITS = "Excluded Commits" + + # this controls the ordering of the sections + ALL_SECTIONS = [CLOSED_NO_COMMIT, CLOSED_ILLEGAL_RESOLUTION, COMMIT_NO_JIRA, COMMIT_JIRA_NOT_IN_QUERY, COMMIT_OPEN_JIRA, ISSUE_UNDER_REVIEW, EXCLUDED_COMMITS] + # a buffer for each section + section_buffer = {} + # a count for each section + section_count = {} total_problems = 0 if not args.nocopyright: print("