Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 11e0aa8

Browse files
stefan-lacatusbkcsoft
authored andcommitted
Added read-only attachments to the Releases API (#63)
* Added assets (attachments) to the releases. - Added three new endpoints to the release api for attachments. - List assets: GET /repos/:owner/:repo/releases/:id/assets - Get single asset: GET /repos/:owner/:repo/releases/assets/:id - Get /repos/:owner/:repo/releases/latest` that gets the latest published full release for the repository. Draft releases and prereleases are not returned by this endpoint. Signed-off-by: Petrisor Lacatus <[email protected]>
1 parent bc243ad commit 11e0aa8

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

gitea/attachment.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gitea // import "code.gitea.io/sdk/gitea"
6+
import "time"
7+
8+
// Attachment a generic attachment
9+
type Attachment struct {
10+
ID int64 `json:"id"`
11+
Name string `json:"name"`
12+
Size int64 `json:"size"`
13+
DownloadCount int64 `json:"download_count"`
14+
Created time.Time `json:"created_at"`
15+
UUID string `json:"uuid"`
16+
DownloadURL string `json:"browser_download_url"`
17+
}

gitea/release.go

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ import (
1313

1414
// Release represents a repository release
1515
type Release struct {
16-
ID int64 `json:"id"`
17-
TagName string `json:"tag_name"`
18-
Target string `json:"target_commitish"`
19-
Title string `json:"name"`
20-
Note string `json:"body"`
21-
URL string `json:"url"`
22-
TarURL string `json:"tarball_url"`
23-
ZipURL string `json:"zipball_url"`
24-
IsDraft bool `json:"draft"`
25-
IsPrerelease bool `json:"prerelease"`
26-
CreatedAt time.Time `json:"created_at"`
27-
PublishedAt time.Time `json:"published_at"`
28-
Publisher *User `json:"author"`
16+
ID int64 `json:"id"`
17+
TagName string `json:"tag_name"`
18+
Target string `json:"target_commitish"`
19+
Title string `json:"name"`
20+
Note string `json:"body"`
21+
URL string `json:"url"`
22+
TarURL string `json:"tarball_url"`
23+
ZipURL string `json:"zipball_url"`
24+
IsDraft bool `json:"draft"`
25+
IsPrerelease bool `json:"prerelease"`
26+
CreatedAt time.Time `json:"created_at"`
27+
PublishedAt time.Time `json:"published_at"`
28+
Publisher *User `json:"author"`
29+
Attachments []*Attachment `json:"assets"`
2930
}
3031

3132
// ListReleases list releases of a repository
@@ -46,6 +47,33 @@ func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) {
4647
return r, err
4748
}
4849

50+
// ListReleaseAttachments gets all the assets of a release in a repository
51+
func (c *Client) ListReleaseAttachments(user, repo string, id int64) ([]*Attachment, error) {
52+
attachments := make([]*Attachment, 0, 10)
53+
err := c.getParsedResponse("GET",
54+
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, id),
55+
nil, nil, &attachments)
56+
return attachments, err
57+
}
58+
59+
// GetReleaseAttachment gets a single attachment of a release in a repository
60+
func (c *Client) GetReleaseAttachment(user, repo string, releaseID int64, attachmentID int64) (*Attachment, error) {
61+
attachment := new(Attachment)
62+
err := c.getParsedResponse("GET",
63+
fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, releaseID, attachmentID),
64+
nil, nil, &attachment)
65+
return attachment, err
66+
}
67+
68+
// GetLatestRelease gets the latest release in a repository. This cannot be a draft or prerelease
69+
func (c *Client) GetLatestRelease(user, repo string) (*Release, error) {
70+
r := new(Release)
71+
err := c.getParsedResponse("GET",
72+
fmt.Sprintf("/repos/%s/%s/releases/latest", user, repo),
73+
nil, nil, &r)
74+
return r, err
75+
}
76+
4977
// CreateReleaseOption options when creating a release
5078
type CreateReleaseOption struct {
5179
TagName string `json:"tag_name" binding:"Required"`

0 commit comments

Comments
 (0)