mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(release): create download directories, refuse duplicate asset names and empty notes (follow gh)
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+41
No files matched your search
@@ -87,6 +87,9 @@ func (a *application) download(cmd *cobra.Command, f downloadFlags, path string,
|
||||
if path == "-" {
|
||||
return writeTerminalSafe(cmd.OutOrStdout(), a.deps.Streams.OutTTY, body)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o777); err != nil {
|
||||
return err
|
||||
}
|
||||
return publish(cmd, path, false, f.clobber, func(destination io.Writer) error {
|
||||
_, err := io.Copy(destination, body)
|
||||
return err
|
||||
|
||||
@@ -217,10 +217,15 @@ $ tea release download v1.0.0 --archive zip`,
|
||||
}
|
||||
paths := make([]string, len(assets))
|
||||
skipped := make([]bool, len(assets))
|
||||
seen := map[string]services.ReleaseAsset{}
|
||||
for i, asset := range assets {
|
||||
if paths[i], skipped[i], err = flags.destination(asset.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
if first, dup := seen[paths[i]]; dup && paths[i] != "-" {
|
||||
return clierr.Wrap(clierr.Usage, fmt.Errorf("assets %d and %d are both named %s; download one at a time with --output", first.ID, asset.ID, asset.Name))
|
||||
}
|
||||
seen[paths[i]] = asset
|
||||
}
|
||||
for i, asset := range assets {
|
||||
if skipped[i] {
|
||||
|
||||
@@ -121,3 +121,29 @@ func TestReleaseDownloadSelectsAssetsOfTheLatestRelease(t *testing.T) {
|
||||
err = Execute(context.Background(), deps, []string{"release", "download", "v1", "notes.txt", "tea-linux", "-O", filepath.Join(dir, "one"), "-R", "owner/repo"})
|
||||
require.ErrorContains(t, err, "--output names one file, but 2 assets match; pass --dir")
|
||||
}
|
||||
|
||||
func TestReleaseDownloadCreatesDirAndRefusesDuplicateNames(t *testing.T) {
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case r.URL.Path == "/api/v1/repos/owner/repo/releases/tags/v1":
|
||||
_, _ = w.Write([]byte(`{"id":1,"tag_name":"v1","assets":[{"id":1,"name":"app","size":5,"uuid":"aaa"},{"id":2,"name":"app","size":5,"uuid":"bbb"},{"id":3,"name":"other","size":5,"uuid":"ccc"}]}`))
|
||||
case strings.HasPrefix(r.URL.Path, "/api/v1/repos/owner/repo/releases/1/assets/"):
|
||||
id := strings.TrimPrefix(r.URL.Path, "/api/v1/repos/owner/repo/releases/1/assets/")
|
||||
_, _ = w.Write([]byte(`{"id":` + id + `,"uuid":"ccc"}`))
|
||||
case strings.HasPrefix(r.URL.Path, "/attachments/"):
|
||||
_, _ = w.Write([]byte("bytes"))
|
||||
default:
|
||||
t.Errorf("unexpected request %s", r.URL.Path)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, _, _ := repoTTYDeps(t, server.URL)
|
||||
dir := filepath.Join(t.TempDir(), "new", "dist")
|
||||
err := Execute(context.Background(), deps, []string{"release", "download", "v1", "--dir", dir, "-R", "owner/repo"})
|
||||
require.ErrorContains(t, err, "assets 1 and 2 are both named app")
|
||||
_, statErr := os.Stat(filepath.Join(dir, "other"))
|
||||
require.Error(t, statErr, "nothing is downloaded before the duplicate is reported")
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"release", "download", "v1", "other", "--dir", dir, "-R", "owner/repo"}))
|
||||
_, statErr = os.Stat(filepath.Join(dir, "other"))
|
||||
require.NoError(t, statErr)
|
||||
}
|
||||
@@ -415,6 +415,9 @@ $ tea release edit v1.0.0-rc1 v1.0.0-rc2 --prerelease=false`,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.Body != nil && *opts.Body == "" {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("release notes cannot be cleared; Gitea ignores empty notes"))
|
||||
}
|
||||
if cmd.Flags().Changed("tag") {
|
||||
if len(args) != 1 || strings.TrimSpace(fields.tag) == "" {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--tag requires one release and a nonempty new tag"))
|
||||
@@ -439,6 +442,9 @@ $ tea release edit v1.0.0-rc1 v1.0.0-rc2 --prerelease=false`,
|
||||
}
|
||||
opts.Body = &editorDraft.Body
|
||||
}
|
||||
if editorDraft.Body == "" && fields.editor {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("release notes cannot be cleared; Gitea ignores empty notes"))
|
||||
}
|
||||
return batchDone(a, cmd, args, func(tag string) string { return "release " + tag }, func(tag string) (services.Release, error) {
|
||||
item, err := service.View(cmd.Context(), tag)
|
||||
if err != nil {
|
||||
|
||||
@@ -147,6 +147,7 @@ func TestUsageErrorsPrecedeRequests(t *testing.T) {
|
||||
{[]string{"release", "create", "v1", "--tag", "v2"}, "supply a tag argument or --tag, not both"},
|
||||
{[]string{"release", "create", "--body-file", "-"}, "--notes-file - requires a tag"},
|
||||
{[]string{"release", "edit", "v1"}, "supply release fields to edit"},
|
||||
{[]string{"release", "edit", "v1", "--notes", ""}, "release notes cannot be cleared"},
|
||||
{[]string{"release", "edit", "v1", "v2", "--tag", "v3"}, "--tag requires one release and a nonempty new tag"},
|
||||
{[]string{"release", "edit", "v1", "--draft", "false"}, "--draft takes no value; use --draft or --draft=false"},
|
||||
{[]string{"release", "edit", "v1", "-d", "false", "-p", "False"}, "--draft takes no value; use --draft or --draft=false"},
|
||||
|
||||
Reference in new issue
Block a user