1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-10-30 23:58:09 +02:00

fix(winget): improve commit msgs (#4199)

closes  #4198
This commit is contained in:
Carlos Alexandro Becker
2023-07-19 22:04:45 -03:00
committed by GitHub
parent e3f494fdc9
commit a726a29d70
4 changed files with 45 additions and 8 deletions

View File

@@ -63,8 +63,9 @@ type ReleaserURLTemplater interface {
// RepoFile is a file to be created.
type RepoFile struct {
Content []byte
Path string
Content []byte
Path string
Identifier string // for the use of the caller.
}
// FileCreator can create the given file to some code repository.

View File

@@ -26,7 +26,7 @@ type Mock struct {
CreatedFile bool
Content string
Path string
Message string
Messages []string
FailToCreateRelease bool
FailToUpload bool
CreatedRelease bool
@@ -89,7 +89,7 @@ func (c *Mock) CreateFile(_ *context.Context, _ config.CommitAuthor, _ Repo, con
c.CreatedFile = true
c.Content = string(content)
c.Path = path
c.Message = msg
c.Messages = append(c.Messages, msg)
return nil
}

View File

@@ -335,8 +335,9 @@ func doPublish(ctx *context.Context, cl client.Client, wingets []*artifact.Artif
return err
}
files = append(files, client.RepoFile{
Content: content,
Path: filepath.Join(winget.Path, pkg.Name),
Content: content,
Path: filepath.Join(winget.Path, pkg.Name),
Identifier: repoFileID(pkg.Type),
})
}
@@ -351,7 +352,14 @@ func doPublish(ctx *context.Context, cl client.Client, wingets []*artifact.Artif
}
for _, file := range files {
if err := cl.CreateFile(ctx, author, repo, file.Content, file.Path, msg); err != nil {
if err := cl.CreateFile(
ctx,
author,
repo,
file.Content,
file.Path,
msg+": add "+file.Identifier,
); err != nil {
return err
}
}
@@ -398,3 +406,17 @@ func extFor(tp artifact.Type) string {
return ""
}
}
func repoFileID(tp artifact.Type) string {
switch tp {
case artifact.WingetVersion:
return "version"
case artifact.WingetInstaller:
return "installer"
case artifact.WingetDefaultLocale:
return "locale"
default:
// should never happen
return ""
}
}

View File

@@ -656,7 +656,21 @@ 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.Len(t, client.Messages, 3)
expected := map[string]bool{
"locale": false,
"version": false,
"installer": false,
}
for _, msg := range client.Messages {
require.Regexp(t, "New version: \\w+\\.[\\w-]+ 1.2.1", msg)
for k, v := range expected {
if strings.Contains(msg, ": add "+k) {
require.False(t, v, "multiple commits for "+k)
expected[k] = true
}
}
}
require.NotEmpty(t, client.Path)
if tt.expectPath != "" {