From 6f90d1dc843610bcfe23c6195bee901449da85bf Mon Sep 17 00:00:00 2001 From: Petrisor Lacatus Date: Fri, 30 Jun 2017 09:06:44 +0300 Subject: [PATCH 1/7] Added assets (attachments) to the releases. --- gitea/attachment.go | 17 +++++++++++++++++ gitea/release.go | 27 ++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 gitea/attachment.go diff --git a/gitea/attachment.go b/gitea/attachment.go new file mode 100644 index 0000000..d1c03a2 --- /dev/null +++ b/gitea/attachment.go @@ -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" + +// 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"` +} diff --git a/gitea/release.go b/gitea/release.go index cc84146..6156eeb 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -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 From 809b6c099d5cf25c80e94dd35796a7cac4284ba9 Mon Sep 17 00:00:00 2001 From: Petrisor Lacatus Date: Fri, 30 Jun 2017 10:28:19 +0300 Subject: [PATCH 2/7] Added two 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 --- gitea/release.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gitea/release.go b/gitea/release.go index 6156eeb..46feb67 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -47,6 +47,24 @@ 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) { + 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 +} + // CreateReleaseOption options when creating a release type CreateReleaseOption struct { TagName string `json:"tag_name" binding:"Required"` From 549beb73e83152687120bddc6853edcb9958f63b Mon Sep 17 00:00:00 2001 From: Petrisor Lacatus Date: Fri, 30 Jun 2017 10:51:27 +0300 Subject: [PATCH 3/7] Fix linting errors --- gitea/attachment.go | 2 +- gitea/release.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gitea/attachment.go b/gitea/attachment.go index d1c03a2..10e7a1d 100644 --- a/gitea/attachment.go +++ b/gitea/attachment.go @@ -5,7 +5,7 @@ package gitea // import "code.gitea.io/sdk/gitea" import "time" -// a generic attachment +// Attachment a generic attachment type Attachment struct { ID int64 `json:"id"` Name string `json:"name"` diff --git a/gitea/release.go b/gitea/release.go index 46feb67..2882d62 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -57,10 +57,10 @@ func (c *Client) ListReleaseAssets(user, repo string, id int64) (*Release, error } // GetReleaseAsset gets all the assets of a release in a repository -func (c *Client) GetReleaseAsset(user, repo string, releaseId int64, assetId int64) (*Release, error) { +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), + fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, releaseID, assetID), nil, nil, &r) return r, err } From 7f04eaacfe3a493f8c36be9fe4404311387934ef Mon Sep 17 00:00:00 2001 From: Petrisor Lacatus Date: Fri, 30 Jun 2017 16:38:19 +0300 Subject: [PATCH 4/7] Added the endpoint `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 --- gitea/release.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gitea/release.go b/gitea/release.go index 2882d62..b89b14d 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -65,6 +65,15 @@ func (c *Client) GetReleaseAsset(user, repo string, releaseID int64, assetID int return r, err } +// GetLatestRelease gets the latest release in a repository +func (c *Client) GetLatestRelease(user, repo string, id int64) (*Release, error) { + r := new(Release) + err := c.getParsedResponse("GET", + fmt.Sprintf("/repos/%s/%s/releases/latest", user, repo, id), + nil, nil, &r) + return r, err +} + // CreateReleaseOption options when creating a release type CreateReleaseOption struct { TagName string `json:"tag_name" binding:"Required"` From c6ac40210a8574371cab28ca3eae7c8cccbb61a3 Mon Sep 17 00:00:00 2001 From: Petrisor Lacatus Date: Fri, 30 Jun 2017 16:49:04 +0300 Subject: [PATCH 5/7] Fixed small issues Signed-off-by: Petrisor Lacatus --- gitea/release.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitea/release.go b/gitea/release.go index b89b14d..61e87ea 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -66,10 +66,10 @@ func (c *Client) GetReleaseAsset(user, repo string, releaseID int64, assetID int } // GetLatestRelease gets the latest release in a repository -func (c *Client) GetLatestRelease(user, repo string, id int64) (*Release, error) { +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, id), + fmt.Sprintf("/repos/%s/%s/releases/latest", user, repo), nil, nil, &r) return r, err } From b8bab7dcc4a2e5ad09d47c7855bd8c114e0fcfc7 Mon Sep 17 00:00:00 2001 From: Petrisor Lacatus Date: Mon, 3 Jul 2017 15:52:20 +0300 Subject: [PATCH 6/7] Renamed methods having to do with Assets to Attachments. The only place we refer to attachments as assets is in the api json response Signed-off-by: Petrisor Lacatus --- gitea/release.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gitea/release.go b/gitea/release.go index 61e87ea..b842adf 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -47,8 +47,8 @@ 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) { +// ListReleaseAttachments gets all the assets of a release in a repository +func (c *Client) ListReleaseAttachments(user, repo string, id int64) (*Release, error) { r := new(Release) err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, id), @@ -56,11 +56,11 @@ func (c *Client) ListReleaseAssets(user, repo string, id int64) (*Release, error 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) { +// GetReleaseAttachment gets all the assets of a release in a repository +func (c *Client) GetReleaseAttachment(user, repo string, releaseID int64, attachmentID int64) (*Release, error) { r := new(Release) err := c.getParsedResponse("GET", - fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, releaseID, assetID), + fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, releaseID, attachmentID), nil, nil, &r) return r, err } From dd3b33128c3425d8448862eefd9a3b5483ae2797 Mon Sep 17 00:00:00 2001 From: Petrisor Lacatus Date: Tue, 4 Jul 2017 09:26:05 +0300 Subject: [PATCH 7/7] Fixed methods having the wrong return type Updated method description Signed-off-by: Petrisor Lacatus --- gitea/release.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gitea/release.go b/gitea/release.go index b842adf..179e739 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -48,24 +48,24 @@ func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) { } // ListReleaseAttachments gets all the assets of a release in a repository -func (c *Client) ListReleaseAttachments(user, repo string, id int64) (*Release, error) { - r := new(Release) +func (c *Client) ListReleaseAttachments(user, repo string, id int64) ([]*Attachment, error) { + attachments := make([]*Attachment, 0, 10) err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, id), - nil, nil, &r) - return r, err + nil, nil, &attachments) + return attachments, 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) { - r := new(Release) +// GetReleaseAttachment gets a single attachment of a release in a repository +func (c *Client) GetReleaseAttachment(user, repo string, releaseID int64, attachmentID int64) (*Attachment, error) { + attachment := new(Attachment) err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, releaseID, attachmentID), - nil, nil, &r) - return r, err + nil, nil, &attachment) + return attachment, err } -// GetLatestRelease gets the latest release in a repository +// GetLatestRelease gets the latest release in a repository. This cannot be a draft or prerelease func (c *Client) GetLatestRelease(user, repo string) (*Release, error) { r := new(Release) err := c.getParsedResponse("GET",