This repository was archived by the owner on Jun 8, 2019. It is now read-only.
forked from gogs/go-gogs-client
-
Notifications
You must be signed in to change notification settings - Fork 53
Added read-only attachments to the Releases API #63
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6f90d1d
Added assets (attachments) to the releases.
stefan-lacatus 809b6c0
Added two new endpoints to the release api for attachments.
stefan-lacatus 549beb7
Fix linting errors
stefan-lacatus 7f04eaa
Added the endpoint `GET /repos/:owner/:repo/releases/latest` that get…
stefan-lacatus c6ac402
Fixed small issues
stefan-lacatus b8bab7d
Renamed methods having to do with Assets to Attachments.
stefan-lacatus dd3b331
Fixed methods having the wrong return type
stefan-lacatus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
// ListReleaseAttachments gets all the assets of a release in a repository | ||
func (c *Client) ListReleaseAttachments(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. This should return a |
||
r := new(Release) | ||
err := c.getParsedResponse("GET", | ||
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, id), | ||
nil, nil, &r) | ||
return r, err | ||
} | ||
|
||
// GetReleaseAttachment gets all the assets of a release in a repository | ||
func (c *Client) GetReleaseAttachment(user, repo string, releaseID int64, attachmentID 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. Same here, 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. Here it should have been a |
||
r := new(Release) | ||
err := c.getParsedResponse("GET", | ||
fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, releaseID, attachmentID), | ||
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"` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).