Skip to content

Commit

Permalink
generate-changes-list: collect involved people
Browse files Browse the repository at this point in the history
  • Loading branch information
zeha committed Dec 19, 2024
1 parent 670c1b1 commit 6f09c0f
Showing 1 changed file with 61 additions and 6 deletions.
67 changes: 61 additions & 6 deletions build-driver/generate-changes-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ 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 in seen:
continue
seen.add(upper)
unique_strings.append(string)
return unique_strings


def build_changes(
output_filename: Path,
dpkg_list_new: Path,
Expand All @@ -61,6 +78,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}
Expand Down Expand Up @@ -106,17 +124,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:
Expand All @@ -125,6 +148,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:
{}
Expand Down Expand Up @@ -189,5 +220,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())

0 comments on commit 6f09c0f

Please sign in to comment.