Skip to content

Commit

Permalink
fix(winget): default commit message
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Jun 26, 2023
1 parent faf3d2a commit 7d485d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
4 changes: 3 additions & 1 deletion internal/client/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Mock struct {
CreatedFile bool
Content string
Path string
Message string
FailToCreateRelease bool
FailToUpload bool
CreatedRelease bool
Expand Down Expand Up @@ -84,10 +85,11 @@ func (c *Mock) ReleaseURLTemplate(_ *context.Context) (string, error) {
return "https://dummyhost/download/{{ .Tag }}/{{ .ArtifactName }}", nil
}

func (c *Mock) CreateFile(_ *context.Context, _ config.CommitAuthor, _ Repo, content []byte, path, _ string) error {
func (c *Mock) CreateFile(_ *context.Context, _ config.CommitAuthor, _ Repo, content []byte, path, msg string) error {
c.CreatedFile = true
c.Content = string(content)
c.Path = path
c.Message = msg
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions internal/pipe/winget/winget.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (Pipe) Default(ctx *context.Context) error {
winget.CommitAuthor = commitauthor.Default(winget.CommitAuthor)

if winget.CommitMessageTemplate == "" {
winget.CommitMessageTemplate = "{{ .ProjectName }}: {{ .PreviousTag }} -> {{ .Tag }}"
winget.CommitMessageTemplate = "New version: {{ .PackageIdentifier }} {{ .Version }}"
}
if winget.Name == "" {
winget.Name = ctx.Config.ProjectName
Expand Down Expand Up @@ -352,7 +352,9 @@ func doPublish(ctx *context.Context, cl client.Client, wingets []*artifact.Artif
return errSkipUploadAuto
}

msg, err := tmpl.New(ctx).Apply(winget.CommitMessageTemplate)
msg, err := tmpl.New(ctx).WithExtraFields(tmpl.Fields{
"PackageIdentifier": winget.PackageIdentifier,
}).Apply(winget.CommitMessageTemplate)
if err != nil {
return err
}
Expand Down
27 changes: 14 additions & 13 deletions internal/pipe/winget/winget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ func TestRunPipe(t *testing.T) {
name: "full",
expectPath: "manifests/b/Beckersoft LTDA/foo/1.2.1",
winget: config.Winget{
Name: "foo",
Publisher: "Beckersoft",
PublisherURL: "https://carlosbecker.com",
Copyright: "bla bla bla",
Author: "Carlos Becker",
Path: "manifests/b/Beckersoft LTDA/foo/{{.Version}}",
Repository: config.RepoRef{Owner: "foo", Name: "bar"},
CommitAuthor: config.CommitAuthor{},
CommitMessageTemplate: "update foo to latest and greatest",
IDs: []string{"foo"},
Goamd64: "v1",
SkipUpload: "false",
ShortDescription: "foo",
Name: "foo",
Publisher: "Beckersoft",
PublisherURL: "https://carlosbecker.com",
Copyright: "bla bla bla",
Author: "Carlos Becker",
Path: "manifests/b/Beckersoft LTDA/foo/{{.Version}}",
Repository: config.RepoRef{Owner: "foo", Name: "bar"},
CommitAuthor: config.CommitAuthor{},
IDs: []string{"foo"},
Goamd64: "v1",
SkipUpload: "false",
ShortDescription: "foo",
Description: `long foo bar
yadaa yada yada loooaaasssss
Expand Down Expand Up @@ -557,6 +556,8 @@ func TestRunPipe(t *testing.T) {
require.NoError(t, pipe.publishAll(ctx, client))
require.True(t, client.CreatedFile)

require.Regexp(t, "New version: \\w+\\.[\\w-]+ 1.2.1", client.Message)

require.NotEmpty(t, client.Path)
if tt.expectPath != "" {
require.Truef(t, strings.HasPrefix(client.Path, tt.expectPath), "expected %q to begin with %q", client.Path, tt.expectPath)
Expand Down
2 changes: 1 addition & 1 deletion www/docs/customization/winget.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ winget:
# The project name and current git tag are used in the format string.
#
# Templates: allowed
commit_msg_template: "{{ .ProjectName }}: {{ .Tag }}"
commit_msg_template: "{{ .PackageIdentifier }}: {{ .Tag }}"

# Path for the file inside the repository.
#
Expand Down

0 comments on commit 7d485d6

Please sign in to comment.