Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Put git messages into tmp files
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-shpak committed Jul 8, 2020
1 parent 896c79e commit d7f5cd4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
24 changes: 22 additions & 2 deletions pkg/git/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/update/automated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
28 changes: 1 addition & 27 deletions pkg/update/automated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"): {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d7f5cd4

Please sign in to comment.