Skip to content

Commit

Permalink
Merge pull request #429 from bbhtt/bbhtt/subj-module
Browse files Browse the repository at this point in the history
main: Set module names as title
  • Loading branch information
wjt authored Jun 10, 2024
2 parents 7f99008 + 2d5d112 commit e4b970e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 26 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,39 @@ class CommittedChanges(t.NamedTuple):
base_branch: t.Optional[str]


def commit_message(changes: t.List[str]) -> str:
assert len(changes) >= 1

if len(changes) == 1:
return changes[0]

module_names = list(dict.fromkeys(list(i.split(":", 1)[0] for i in changes)))
for i in reversed(range(2, len(module_names) + 1)):
xs = module_names[: i - 1]
y = module_names[i - 1]
zs = module_names[i:]

if zs:
tail = f" and {len(zs)} more modules"
xs.append(y)
else:
tail = f" and {y} modules"

subject = "Update " + ", ".join(xs) + tail
if len(subject) <= 70:
return subject

return f"Update {len(module_names)} modules"


def commit_changes(changes: t.List[str]) -> CommittedChanges:
log.info("Committing updates")
body: t.Optional[str]
subject = commit_message(changes)
if len(changes) > 1:
subject = "Update {} modules".format(len(changes))
body = "\n".join(changes)
message = subject + "\n\n" + body
else:
subject = changes[0]
body = None
message = subject

Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def test_full_run(self):
self.assertEqual(await main.run_with_args(args1), (2, 0, True))

commit_data = self._get_commit_data()
self.assertEqual(commit_data["subject"], "Update 2 modules")
self.assertEqual(commit_data["subject"], "Update libXaw and xterm modules")
self.assertEqual(commit_data["author_name"], "Test Runner")
self.assertEqual(commit_data["author_email"], "test@localhost")
self.assertEqual(commit_data["committer_name"], "Test Runner")
Expand All @@ -95,7 +95,7 @@ async def test_git_envvars(self):
self.assertEqual(await main.run_with_args(args1), (2, 0, True))

commit_data = self._get_commit_data()
self.assertEqual(commit_data["subject"], "Update 2 modules")
self.assertEqual(commit_data["subject"], "Update libXaw and xterm modules")
self.assertEqual(commit_data["author_name"], "Some Guy")
self.assertEqual(commit_data["author_email"], "someguy@localhost")
self.assertEqual(commit_data["committer_name"], "Test Runner")
Expand Down

0 comments on commit e4b970e

Please sign in to comment.