diff --git a/pkg/git/operations.go b/pkg/git/operations.go index 02324fd77d..eb3db7fb59 100644 --- a/pkg/git/operations.go +++ b/pkg/git/operations.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "io" + "io/ioutil" "os" "os/exec" "strings" @@ -141,7 +142,16 @@ func secretUnseal(ctx context.Context, workingDir string) error { } func commit(ctx context.Context, workingDir string, commitAction CommitAction) error { - args := []string{"commit", "--no-verify", "-a", "-m", commitAction.Message} + message, err := ioutil.TempFile("", "flux-commit-*.txt") + if err != nil { + return err + } + defer os.Remove(message.Name()) + if _, err := message.WriteString(commitAction.Message); err != nil { + return err + } + + args := []string{"commit", "--no-verify", "-a", "--file", message.Name()} var env []string if commitAction.Author != "" { args = append(args, "--author", commitAction.Author) @@ -205,7 +215,17 @@ func addNote(ctx context.Context, workingDir, rev, notesRef string, note interfa if err != nil { return err } - args := []string{"notes", "--ref", notesRef, "add", "-m", string(b), rev} + + message, err := ioutil.TempFile("", "flux-note-*.json") + if err != nil { + return err + } + defer os.Remove(message.Name()) + if _, err := message.Write(b); err != nil { + return err + } + + args := []string{"notes", "--ref", notesRef, "add", "--file", message.Name(), rev} return execGitCmd(ctx, args, gitCmdConfig{dir: workingDir}) } diff --git a/pkg/update/automated.go b/pkg/update/automated.go index e4bc129e32..5a093e1c47 100644 --- a/pkg/update/automated.go +++ b/pkg/update/automated.go @@ -69,19 +69,10 @@ func (a *Automated) CommitMessage(result Result) string { fmt.Fprintf(buf, "Auto-release %s", images[0]) default: - limit := 10 - fmt.Fprintf(buf, "Auto-release multiple (%d) images\n\n", total) - if total > limit { - // Take first 10 images to keep commit message size in bounds - images = images[:limit] - } for _, im := range images { fmt.Fprintf(buf, " - %s\n", im) } - if total > limit { - fmt.Fprintln(buf, " ...") - } } return buf.String() } diff --git a/pkg/update/automated_test.go b/pkg/update/automated_test.go index 740eab6ee6..501c3b0ad1 100644 --- a/pkg/update/automated_test.go +++ b/pkg/update/automated_test.go @@ -7,32 +7,6 @@ import ( ) func TestCommitMessage(t *testing.T) { - automated := Automated{} - result := Result{ - resource.MakeID("ns", "kind", "1"): { - Status: ReleaseStatusSuccess, - PerContainer: []ContainerUpdate{ - {Target: mustParseRef("docker.io/image:v1")}, - {Target: mustParseRef("docker.io/image:v2")}, - {Target: mustParseRef("docker.io/image:v3")}, - }, - }, - } - result.ChangedImages() - - actual := automated.CommitMessage(result) - expected := `Auto-release multiple (3) images - - - docker.io/image:v1 - - docker.io/image:v2 - - docker.io/image:v3 -` - if actual != expected { - t.Fatalf("Expected git commit message: '%s', was '%s'", expected, actual) - } -} - -func TestCommitMessage10Max(t *testing.T) { automated := Automated{} result := Result{ resource.MakeID("ns", "kind", "1"): { @@ -67,7 +41,7 @@ func TestCommitMessage10Max(t *testing.T) { - docker.io/image:v6 - docker.io/image:v7 - docker.io/image:v8 - ... + - docker.io/image:v9 ` if actual != expected { t.Fatalf("Expected git commit message: '%s', was '%s'", expected, actual)