From 2a418fe9b94767a750febcc09b5bce6e05dd807c Mon Sep 17 00:00:00 2001 From: Roland Schilter Date: Fri, 26 Oct 2018 10:42:56 -0700 Subject: [PATCH] Improve commit message for containers releases Changes the Git commit message for containers release from ``` Release containers default:deployment/foo - quay.io/bar/nginx:master-d9500ad8 - quay.io/bar/logger:master-d9500ad8 default:deployment/moo - quay.io/bar/nginx:master-d9500ad8 ``` to ``` Update image refs in default:deployment/foo, default:deployment/moo default:deployment/foo - quay.io/bar/nginx:master-d9500ad8 - quay.io/bar/logger:master-d9500ad8 default:deployment/moo - quay.io/bar/nginx:master-d9500ad8 ``` --- release/releaser_test.go | 10 +++++----- update/containers.go | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/release/releaser_test.go b/release/releaser_test.go index 47577354a..449d1ba60 100644 --- a/release/releaser_test.go +++ b/release/releaser_test.go @@ -871,7 +871,7 @@ func Test_UpdateContainers(t *testing.T) { Target: newSidecarRef, }}, }, - Commit: "Release containers\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n- weaveworks/sidecar:master-a000002\n", + Commit: "Update image refs in default:deployment/helloworld\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n- weaveworks/sidecar:master-a000002\n", }, false: { Result: update.ControllerResult{ @@ -886,7 +886,7 @@ func Test_UpdateContainers(t *testing.T) { Target: newSidecarRef, }}, }, - Commit: "Release containers\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n- weaveworks/sidecar:master-a000002\n", + Commit: "Update image refs in default:deployment/helloworld\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n- weaveworks/sidecar:master-a000002\n", }, }, }, @@ -918,7 +918,7 @@ func Test_UpdateContainers(t *testing.T) { }, }, }, - Commit: "Release containers\n\ndefault:deployment/helloworld\n- weaveworks/sidecar:master-a000002\n", + Commit: "Update image refs in default:deployment/helloworld\n\ndefault:deployment/helloworld\n- weaveworks/sidecar:master-a000002\n", }, false: {Err: errors.New("cannot satisfy specs")}, }, @@ -996,7 +996,7 @@ func Test_UpdateContainers(t *testing.T) { }, }, }, - Commit: "Release containers\n\ndefault:deployment/locked-service\n- quay.io/weaveworks/locked-service:2\n", + Commit: "Update image refs in default:deployment/locked-service\n\ndefault:deployment/locked-service\n- quay.io/weaveworks/locked-service:2\n", }, false: { Result: update.ControllerResult{ @@ -1009,7 +1009,7 @@ func Test_UpdateContainers(t *testing.T) { }, }, }, - Commit: "Release containers\n\ndefault:deployment/locked-service\n- quay.io/weaveworks/locked-service:2\n", + Commit: "Update image refs in default:deployment/locked-service\n\ndefault:deployment/locked-service\n- quay.io/weaveworks/locked-service:2\n", }, }, }, diff --git a/update/containers.go b/update/containers.go index 75ea5e445..624a3c2f3 100644 --- a/update/containers.go +++ b/update/containers.go @@ -166,17 +166,18 @@ func (s ContainerSpecs) ReleaseType() ReleaseType { } func (s ContainerSpecs) CommitMessage(result Result) string { - buf := &bytes.Buffer{} - fmt.Fprintln(buf, "Release containers") + var workloads []string + body := &bytes.Buffer{} for _, res := range result.AffectedResources() { - fmt.Fprintf(buf, "\n%s", res) + workloads = append(workloads, res.String()) + fmt.Fprintf(body, "\n%s", res) for _, upd := range result[res].PerContainer { - fmt.Fprintf(buf, "\n- %s", upd.Target) + fmt.Fprintf(body, "\n- %s", upd.Target) } - fmt.Fprintln(buf) + fmt.Fprintln(body) } if err := result.Error(); err != "" { - fmt.Fprintf(buf, "\n%s", result.Error()) + fmt.Fprintf(body, "\n%s", result.Error()) } - return buf.String() + return fmt.Sprintf("Update image refs in %s\n%s", strings.Join(workloads, ", "), body.String()) }