Skip to content

Commit

Permalink
Improve commit messages to include change detail. (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossigee authored Oct 9, 2024
1 parent d77d877 commit 2f43914
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions task/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func KoboldHandler(ctx context.Context, cache string, g model.TaskGroup, runner

msg, err = GetCommitMessage(changes)
if err != nil {
msg = "chore(kobold): Update image refs"
return nil, fmt.Errorf("unable to get commit message: %w", err)
}

if err := git.Publish(ctx, cache, g.DestBranch.String, msg); err != nil {
Expand All @@ -71,19 +71,18 @@ func GetCommitMessage(changes []krm.Change) (string, error) {
seen := make(map[string]struct{})

msg := strings.Builder{}
msg.WriteString("chore(kobold): ")
msg.WriteString("chore(kobold):\n")

for _, change := range changes {
if _, ok := seen[change.Repo]; ok {
continue
}
msg.WriteString(change.Repo)
msg.WriteString(", ")
msg.WriteString(fmt.Sprintf(" * %s: %s\n", change.Repo, change.Description))

seen[change.Repo] = struct{}{}
}

return msg.String()[:msg.Len()-2], nil
return msg.String()[:msg.Len()-1], nil
}

var _ Handler = KoboldHandler
Expand Down
6 changes: 3 additions & 3 deletions task/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestGetCommitMessage(t *testing.T) {
},
},
},
want: "chore(kobold): busybox",
want: "chore(kobold):\n * busybox: busybox:1.0.0 -> busybox:1.0.1",
wantErr: false,
},
{
Expand All @@ -43,7 +43,7 @@ func TestGetCommitMessage(t *testing.T) {
},
},
},
want: "chore(kobold): busybox, somerepo",
want: "chore(kobold):\n * busybox: busybox:1.0.0 -> busybox:1.0.1\n * somerepo: somerepo:2.0.0 -> somerepo:2.0.1",
wantErr: false,
},
{
Expand All @@ -60,7 +60,7 @@ func TestGetCommitMessage(t *testing.T) {
},
},
},
want: "chore(kobold): busybox",
want: "chore(kobold):\n * busybox: busybox:1.0.0 -> busybox:1.0.1",
wantErr: false,
},
}
Expand Down

0 comments on commit 2f43914

Please sign in to comment.