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

Added read-only attachments to the Releases API #63

Merged
merged 7 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gitea/attachment.go
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 {
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

@lafriks lafriks Jun 30, 2017

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).

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"`
}
54 changes: 41 additions & 13 deletions gitea/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return a []*Attachment, not *Release https://developer.github.com/v3/repos/releases/#list-assets-for-a-release

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, []*Attachment

Copy link
Author

@stefan-lacatus stefan-lacatus Jul 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it should have been a *Attachment since we are only returning one instance. I've also updated the function description as it was incorrect

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"`
Expand Down