diff --git a/build-driver/generate-changes-list.py b/build-driver/generate-changes-list.py index 8771050f..a3e7e4ba 100755 --- a/build-driver/generate-changes-list.py +++ b/build-driver/generate-changes-list.py @@ -49,6 +49,22 @@ def parse_package_list(s: str) -> dict: return package_dict +def sort_people(people: list[str]) -> list[str]: + """Sort list of names, ignoring case""" + return sorted(people, key=lambda v: v.upper()) + + +def unique_case_insensitive(strings: list[str]): + seen = set() + unique_strings = [] + for string in strings: + upper = string.upper() + if upper not in seen: + seen.add(upper) + unique_strings.append(string) + return unique_strings + + def build_changes( output_filename: Path, dpkg_list_new: Path, @@ -61,6 +77,7 @@ def build_changes( listener: Listener, ): git_repo_workspace.mkdir(parents=True, exist_ok=True) + all_people = [] changelog = f"""------------------------------------------------------------------------ Generated by CI for job {job_name} {build_id} @@ -106,17 +123,22 @@ def build_changes( else: range = f"v{version}" - result = subprocess.run(["git", "log", "--oneline", range], cwd=gitpath, capture_output=True) - if result.returncode != 0: - git_changes = "(failed)" - else: - git_changes = "\n ".join(result.stdout.decode().splitlines()) + commits, people = get_grml_package_changes(gitpath, range) + all_people.extend(people) + commit_list = "\n ".join(commits) + people_list = "\n ".join(sort_people(people)) changelog += f"""Package {package}: {range} {'(new)' if not old_version else ''} - {git_changes} + {commit_list} +People: + {people_list} ------------------------------------------------------------------------ """ except Exception as e: listener.warn(f"Generating change report for package {package} failed: {e}") + changelog += f"""Package {package}: [failed] +------------------------------------------------------------------------ +""" + else: if old_version: if old_version == version: @@ -125,6 +147,14 @@ def build_changes( else: debian_changes["added"].append(package) + + all_people = unique_case_insensitive(all_people) + all_people_list = "\n ".join(sort_people(all_people)) + changelog += f"""All involved people: + {all_people_list} +------------------------------------------------------------------------ +""" + changelog += """Changes to Debian package list: Added: {} @@ -189,5 +219,29 @@ def fetch_grml_package_repo(git_repo_workspace: Path, package: str, git_url: str return gitpath +def get_grml_package_changes(gitpath: Path, range: str) -> tuple[list[str], list[str]]: + trailers = ["Thanks", "Reported-By"] + + git_format = "--format=tformat:Commit: %H %s%nAuthor: %aN%nCommitter: %cN%n" + for trailer in trailers: + git_format += f"%(trailers:key={trailer})%n" + + git_log = run_x(["git", "log", git_format, range], cwd=gitpath, capture_output=True) + + changes = [] + people = [] + for line in git_log.stdout.decode().splitlines(): + line = line.strip() + if not line: + continue + key, value = line.split(': ', 1) + if key == 'Commit': + changes.append(value) + else: + people.append(value) + + return changes, unique_case_insensitive(people) + + if __name__ == "__main__": sys.exit(main())