mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
feat(release): show notes and assets, upload with --clobber, download like gh
release view printed "v0.1.0 v0.1.0" and a URL: the notes and assets were only in --json. It now shows the title and tag, a Latest, Pre-release or Draft badge, who released it when and the target, the assets with their sizes and the notes, rendered on a terminal. Without a tag it shows the latest release, and --web opens it. release asset upload silently attached a second asset with the same name; it now refuses unless --clobber replaces the existing one. release delete printed the deleted release as a live row; it reports "✓ Deleted release v2.0.0 ... (tag kept; use --delete-tag)". release list shows TITLE, TYPE, TAG and PUBLISHED. release create takes asset files after the tag, -t/-n/-F/-e/-d/-p (--body and --body-file still work) and the new alias. Downloads select assets by name or ID or with --pattern, default to every asset of the latest release, write to ./NAME, --dir or --output with --clobber/--skip-existing, and --archive fetches the source code. release upload and release download are shortcuts for the asset commands, asset edit and delete take names or IDs, and the release JSON gains author and assets. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
11 files changed
+984
-357
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
"gitea.dev/tea/internal/transport"
|
||||
@@ -14,22 +15,25 @@ import (
|
||||
|
||||
// Release describes a repository release.
|
||||
type Release struct {
|
||||
ID int64 `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Target string `json:"target"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
URL string `json:"url"`
|
||||
Draft bool `json:"draft"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
PublishedAt *string `json:"published_at"`
|
||||
ID int64 `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Target string `json:"target"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
URL string `json:"url"`
|
||||
Draft bool `json:"draft"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
Author string `json:"author"`
|
||||
Assets []ReleaseAsset `json:"assets"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
PublishedAt *string `json:"published_at"`
|
||||
}
|
||||
|
||||
func releaseFrom(release *gitea.Release) Release {
|
||||
return Release{
|
||||
ID: release.ID, Tag: release.TagName, Target: release.Target, Title: release.Title, Body: release.Note, URL: release.HTMLURL,
|
||||
Draft: release.IsDraft, Prerelease: release.IsPrerelease, CreatedAt: timestamp(release.CreatedAt), PublishedAt: optionalTimestamp(&release.PublishedAt),
|
||||
Draft: release.IsDraft, Prerelease: release.IsPrerelease, Author: login(release.Publisher), Assets: convertAll(release.Attachments, assetFrom),
|
||||
CreatedAt: timestamp(release.CreatedAt), PublishedAt: optionalTimestamp(&release.PublishedAt),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +57,25 @@ func (s Releases) endpoint() string { return "repos/" + s.Repository + "/release
|
||||
|
||||
// List returns a non-nil page of releases.
|
||||
func (s Releases) List(ctx context.Context, limit, page int) ([]Release, error) {
|
||||
releases, err := repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) ([]*gitea.Release, *gitea.Response, error) {
|
||||
return c.Releases.ListReleases(ctx, owner, repo, gitea.ListReleasesOptions{ListOptions: listOptions(limit, page)})
|
||||
window, err := s.ListPage(ctx, limit, page)
|
||||
return window.Items, err
|
||||
}
|
||||
|
||||
// ListPage is List that also reports whether more releases follow and how many there are.
|
||||
func (s Releases) ListPage(ctx context.Context, limit, page int) (Page[Release], error) {
|
||||
window, err := listPage(limit, page, func(limit, page int) ([]*gitea.Release, http.Header, error) {
|
||||
var headers http.Header
|
||||
releases, err := repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) ([]*gitea.Release, *gitea.Response, error) {
|
||||
releases, resp, err := c.Releases.ListReleases(ctx, owner, repo, gitea.ListReleasesOptions{ListOptions: listOptions(limit, page)})
|
||||
headers = headerOf(resp)
|
||||
return releases, resp, err
|
||||
})
|
||||
return releases, headers, err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return Page[Release]{}, err
|
||||
}
|
||||
return convertAll(releases, releaseFrom), nil
|
||||
return Page[Release]{Items: convertAll(window.Items, releaseFrom), More: window.More, Total: window.Total, Counted: window.Counted}, nil
|
||||
}
|
||||
|
||||
// View retrieves a release by its tag, including numeric tags.
|
||||
@@ -69,6 +85,21 @@ func (s Releases) View(ctx context.Context, tag string) (Release, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// Latest retrieves the most recent release that is neither a draft nor a prerelease.
|
||||
func (s Releases) Latest(ctx context.Context) (Release, error) {
|
||||
release, err := repoConvert(ctx, s.Client, s.Repository, releaseFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Release, *gitea.Response, error) {
|
||||
return c.Releases.GetLatestRelease(ctx, owner, repo)
|
||||
})
|
||||
return release, Classify(err, "latest release", "", s.Repository)
|
||||
}
|
||||
|
||||
// Archive opens the source archive of the repository at ref; format is zip or tar.gz.
|
||||
func (s Releases) Archive(ctx context.Context, ref, format string) (io.ReadCloser, error) {
|
||||
return repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) (io.ReadCloser, *gitea.Response, error) {
|
||||
return c.Repositories.GetArchiveReader(ctx, owner, repo, ref, gitea.ArchiveType("."+format))
|
||||
})
|
||||
}
|
||||
|
||||
// Create creates a release and lets Gitea create a missing tag at the supplied target.
|
||||
func (s Releases) Create(ctx context.Context, 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) {
|
||||
|
||||
Reference in new issue
Block a user