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 5 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
}

// ListReleaseAssets gets all the assets of a release in a repository
func (c *Client) ListReleaseAssets(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.

These should be be named Attachments instead of Assets since Gitea calls them that :)

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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 :)

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

The 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 Attachment and in json payloads and url's use GitHub name asset

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