fix(release): report an unknown target clearly, hint to push, and add --verify-tag (follow gh)

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 19:01:19 +02:00
1 parent 9360f39cc8
commit c97044f76c
4 files changed
+142 -1

No files matched your search

+18
View File
@@ -5,9 +5,12 @@ package services
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"strconv"
"strings"
gitea "gitea.dev/sdk"
"gitea.dev/tea/internal/transport"
@@ -103,9 +106,24 @@ func (s Releases) Create(ctx context.Context, opts ReleaseOptions) (Release, err
IsDraft: deref(opts.Draft), IsPrerelease: deref(opts.Prerelease),
})
})
if apiErr, ok := errors.AsType[*transport.APIError](err); ok && apiErr.Status == http.StatusNotFound && strings.Contains(apiErr.Message, "target") {
// The release does not exist yet, so a 404 here names the unresolvable target, not the release.
return item, &NotFoundError{Kind: "target", Key: strconv.Quote(deref(opts.Target)), Scope: s.Repository, Err: err}
}
return item, Classify(err, "release", deref(opts.Tag), s.Repository)
}
// TagExists reports whether the repository on the server has the tag.
func (s Releases) TagExists(ctx context.Context, tag string) (bool, error) {
_, err := repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Tag, *gitea.Response, error) {
return c.Repositories.GetTag(ctx, owner, repo, tag)
})
if IsNotFound(err) {
return false, nil
}
return err == nil, err
}
// Edit changes only supplied release fields; Gitea ignores empty text fields.
func (s Releases) Edit(ctx context.Context, id int64, opts ReleaseOptions) (Release, error) {
return repoConvert(ctx, s.Client, s.Repository, releaseFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Release, *gitea.Response, error) {
+27
View File
@@ -234,3 +234,30 @@ func TestReleaseAssetRenameAndDelete(t *testing.T) {
require.Equal(t, ReleaseAsset{ID: 2, Name: "renamed.bin"}, asset)
require.NoError(t, service.DeleteAsset(context.Background(), 1, 2))
}
func TestReleaseCreateReportsAnUnresolvableTargetNotAMissingRelease(t *testing.T) {
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNotFound)
_, _ = w.Write([]byte(`{"message":"target not found"}`))
}))
target, tag := "deadbeef", "v1"
_, err := Releases{Client: client, Repository: "alice/project"}.Create(context.Background(), ReleaseOptions{Tag: &tag, Title: &tag, Target: &target})
var notFound *NotFoundError
require.ErrorAs(t, err, &notFound)
require.EqualError(t, err, `target "deadbeef" not found in alice/project`)
}
func TestReleaseTagExistsDistinguishesMissingFromFailing(t *testing.T) {
status := http.StatusNotFound
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(status)
_, _ = w.Write([]byte(`{"message":"x"}`))
}))
service := Releases{Client: client, Repository: "alice/project"}
exists, err := service.TagExists(context.Background(), "v1")
require.NoError(t, err)
require.False(t, exists)
status = http.StatusInternalServerError
_, err = service.TagExists(context.Background(), "v1")
require.Error(t, err)
}