-
Notifications
You must be signed in to change notification settings - Fork 53
Added read-only attachments to the Releases API #63
Changes from 5 commits
6f90d1d
809b6c0
549beb7
7f04eaa
c6ac402
b8bab7d
dd3b331
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package gitea // import "code.gitea.io/sdk/gitea" | ||
import "time" | ||
|
||
// Attachment a generic attachment | ||
type Attachment struct { | ||
ID int64 `json:"id"` | ||
Name string `json:"name"` | ||
Size int64 `json:"size"` | ||
DownloadCount int64 `json:"download_count"` | ||
Created time.Time `json:"created_at"` | ||
UUID string `json:"uuid"` | ||
DownloadURL string `json:"browser_download_url"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,19 +13,20 @@ import ( | |
|
||
// Release represents a repository release | ||
type Release struct { | ||
ID int64 `json:"id"` | ||
TagName string `json:"tag_name"` | ||
Target string `json:"target_commitish"` | ||
Title string `json:"name"` | ||
Note string `json:"body"` | ||
URL string `json:"url"` | ||
TarURL string `json:"tarball_url"` | ||
ZipURL string `json:"zipball_url"` | ||
IsDraft bool `json:"draft"` | ||
IsPrerelease bool `json:"prerelease"` | ||
CreatedAt time.Time `json:"created_at"` | ||
PublishedAt time.Time `json:"published_at"` | ||
Publisher *User `json:"author"` | ||
ID int64 `json:"id"` | ||
TagName string `json:"tag_name"` | ||
Target string `json:"target_commitish"` | ||
Title string `json:"name"` | ||
Note string `json:"body"` | ||
URL string `json:"url"` | ||
TarURL string `json:"tarball_url"` | ||
ZipURL string `json:"zipball_url"` | ||
IsDraft bool `json:"draft"` | ||
IsPrerelease bool `json:"prerelease"` | ||
CreatedAt time.Time `json:"created_at"` | ||
PublishedAt time.Time `json:"published_at"` | ||
Publisher *User `json:"author"` | ||
Attachments []*Attachment `json:"assets"` | ||
} | ||
|
||
// ListReleases list releases of a repository | ||
|
@@ -46,6 +47,33 @@ func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) { | |
return r, err | ||
} | ||
|
||
// ListReleaseAssets gets all the assets of a release in a repository | ||
func (c *Client) ListReleaseAssets(user, repo string, id int64) (*Release, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bkcsoft but in GitHub api they are called assets and we want API to be compatible with GitHub There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, but the function should still be called Attachment, even though the payload has Assets :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so everywhere in the code we still refer to them as Attachments, and the only place where "asset" appears is in the json for the release? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bkcsoft I think it will be confusing that endpoints and in json it is called assets but in sdk attachments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, how should I name things? A decision has to be reached by you guys... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stefan-lacatus after talking to @bkcsoft we agreed on naming that in golang code we should use name |
||
r := new(Release) | ||
err := c.getParsedResponse("GET", | ||
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, id), | ||
nil, nil, &r) | ||
return r, err | ||
} | ||
|
||
// GetReleaseAsset gets all the assets of a release in a repository | ||
func (c *Client) GetReleaseAsset(user, repo string, releaseID int64, assetID int64) (*Release, error) { | ||
r := new(Release) | ||
err := c.getParsedResponse("GET", | ||
fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, releaseID, assetID), | ||
nil, nil, &r) | ||
return r, err | ||
} | ||
|
||
// GetLatestRelease gets the latest release in a repository | ||
func (c *Client) GetLatestRelease(user, repo string) (*Release, error) { | ||
r := new(Release) | ||
err := c.getParsedResponse("GET", | ||
fmt.Sprintf("/repos/%s/%s/releases/latest", user, repo), | ||
nil, nil, &r) | ||
return r, err | ||
} | ||
|
||
// CreateReleaseOption options when creating a release | ||
type CreateReleaseOption struct { | ||
TagName string `json:"tag_name" binding:"Required"` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in SDK I think we should call it also as
Asset
so that there would not be different names for same thing.Also type comment must start with type name like
// Asset represents a release attachments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But because the Attachments can be used in multiple places (releases, issues, comments) is it worth to make this change? Or should we rename Attachements to assets everywhere? Having two words for the same thing is confusing.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but attachments for issues and comments most probably wont have same structure anyway (in API).