From 25615b1430ddfdb6efeb3482bc71d0b0feb1b4d0 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Thu, 8 Feb 2018 22:20:52 +0100 Subject: [PATCH 01/18] Add Attachment API * repos/:owner/:repo/releases (add attachments) * repos/:owner/:repo/releases/:id (add attachments) * repos/:owner/:repo/releases/:id/attachments * repos/:owner/:repo/releases/:id/attachments/:attachment_id Signed-off-by: Jonas Franz --- models/attachment.go | 47 +++- models/release.go | 8 + public/swagger.v1.json | 220 ++++++++++++++++++ routers/api/v1/api.go | 12 +- routers/api/v1/repo/release.go | 4 +- routers/api/v1/repo/release_attachment.go | 97 ++++++++ routers/api/v1/swagger/repo.go | 12 + vendor/code.gitea.io/sdk/gitea/admin_user.go | 28 +-- vendor/code.gitea.io/sdk/gitea/attachment.go | 16 +- vendor/code.gitea.io/sdk/gitea/gitea.go | 3 + vendor/code.gitea.io/sdk/gitea/hook.go | 26 +-- vendor/code.gitea.io/sdk/gitea/issue.go | 20 +- .../code.gitea.io/sdk/gitea/issue_comment.go | 16 +- vendor/code.gitea.io/sdk/gitea/issue_label.go | 6 +- .../sdk/gitea/issue_milestone.go | 22 +- .../sdk/gitea/issue_tracked_time.go | 2 +- vendor/code.gitea.io/sdk/gitea/org.go | 8 +- vendor/code.gitea.io/sdk/gitea/org_team.go | 6 +- vendor/code.gitea.io/sdk/gitea/pull.go | 4 +- vendor/code.gitea.io/sdk/gitea/release.go | 27 +-- vendor/code.gitea.io/sdk/gitea/repo.go | 14 +- vendor/code.gitea.io/sdk/gitea/repo_key.go | 8 +- vendor/code.gitea.io/sdk/gitea/status.go | 4 +- vendor/code.gitea.io/sdk/gitea/user.go | 8 +- vendor/code.gitea.io/sdk/gitea/user_gpgkey.go | 4 +- vendor/vendor.json | 9 +- 26 files changed, 514 insertions(+), 117 deletions(-) create mode 100644 routers/api/v1/repo/release_attachment.go diff --git a/models/attachment.go b/models/attachment.go index acb1f0716ce7c..ffa747256cae2 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -13,8 +13,9 @@ import ( gouuid "github.com/satori/go.uuid" - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/setting" + api "code.gitea.io/sdk/gitea" ) // Attachment represent a attachment of issue/comment/release. @@ -39,6 +40,19 @@ func (a *Attachment) IncreaseDownloadCount() error { return nil } +func (a *Attachment) APIFormat() *api.Attachment { + size, _ := a.Size() + return &api.Attachment{ + ID: a.ID, + Name: a.Name, + Created: a.CreatedUnix.AsTime(), + DownloadCount: a.DownloadCount, + Size: size, + UUID: a.UUID, + DownloadURL: a.DownloadURL(), + } +} + // AttachmentLocalPath returns where attachment is stored in local file // system based on given UUID. func AttachmentLocalPath(uuid string) string { @@ -50,6 +64,20 @@ func (a *Attachment) LocalPath() string { return AttachmentLocalPath(a.UUID) } +// Size returns the file's size of the attachment +func (a *Attachment) Size() (int64, error) { + fi, err := os.Stat(a.LocalPath()) + if err != nil { + return 0, err + } + return fi.Size(), nil +} + +// DownloadURL returns the download url of the attached file +func (a *Attachment) DownloadURL() string { + return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID) +} + // NewAttachment creates a new attachment object. func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment, err error) { attach := &Attachment{ @@ -81,6 +109,23 @@ func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment, return attach, nil } +// GetAttachmentByID returns attachment by given id +func GetAttachmentByID(id int64) (*Attachment, error) { + return getAttachmentByID(x, id) +} + +func getAttachmentByID(e Engine, id int64) (*Attachment, error) { + attach := &Attachment{ID: id} + + if has, err := e.Get(attach); err != nil { + return nil, err + } else if !has { + return nil, ErrAttachmentNotExist{ID: id, UUID: ""} + } + return attach, nil +} + + func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) { attach := &Attachment{UUID: uuid} has, err := e.Get(attach) diff --git a/models/release.go b/models/release.go index 1e1d339a7cbcd..455cfc38ca7e1 100644 --- a/models/release.go +++ b/models/release.go @@ -53,6 +53,9 @@ func (r *Release) loadAttributes(e Engine) error { return err } } + if err := GetReleaseAttachments(r); err != nil { + return err + } return nil } @@ -79,6 +82,10 @@ func (r *Release) TarURL() string { // APIFormat convert a Release to api.Release func (r *Release) APIFormat() *api.Release { + assets := make([]*api.Attachment, 0) + for _, att := range r.Attachments { + assets = append(assets, att.APIFormat()) + } return &api.Release{ ID: r.ID, TagName: r.TagName, @@ -92,6 +99,7 @@ func (r *Release) APIFormat() *api.Release { CreatedAt: r.CreatedUnix.AsTime(), PublishedAt: r.CreatedUnix.AsTime(), Publisher: r.Publisher.APIFormat(), + Attachments: assets, } } diff --git a/public/swagger.v1.json b/public/swagger.v1.json index cc918e015a3fa..f204fdd1c80bd 100644 --- a/public/swagger.v1.json +++ b/public/swagger.v1.json @@ -3225,6 +3225,37 @@ }, "/repos/{owner}/{repo}/releases": { "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List a repo's releases", + "operationId": "repoListReleases", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ReleaseList" + } + } + }, + "post": { "consumes": [ "application/json" ], @@ -3267,6 +3298,44 @@ } }, "/repos/{owner}/{repo}/releases/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Get a release", + "operationId": "repoGetRelease", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the release to get", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/Release" + } + } + }, "delete": { "tags": [ "repository" @@ -3351,6 +3420,93 @@ } } }, + "/repos/{owner}/{repo}/releases/{id}/attachments": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List release's attachments", + "operationId": "repoListReleaseAttachments", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the release", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/AttachmentList" + } + } + } + }, + "/repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Get a release attachment", + "operationId": "repoGetReleaseAttachment", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the release", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the attachment to get", + "name": "attachment_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/Attachment" + } + } + } + }, "/repos/{owner}/{repo}/stargazers": { "get": { "produces": [ @@ -4994,6 +5150,45 @@ }, "x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea" }, + "Attachment": { + "description": "Attachment a generic attachment", + "type": "object", + "properties": { + "browser_download_url": { + "type": "string", + "x-go-name": "DownloadURL" + }, + "created_at": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, + "download_count": { + "type": "integer", + "format": "int64", + "x-go-name": "DownloadCount" + }, + "id": { + "type": "integer", + "format": "int64", + "x-go-name": "ID" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "size": { + "type": "integer", + "format": "int64", + "x-go-name": "Size" + }, + "uuid": { + "type": "string", + "x-go-name": "UUID" + } + }, + "x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea" + }, "Branch": { "description": "Branch represents a repository branch", "type": "object", @@ -5202,6 +5397,11 @@ "uniqueItems": true, "x-go-name": "Key" }, + "read_only": { + "description": "Describe if the key has only read access or read/write", + "type": "boolean", + "x-go-name": "ReadOnly" + }, "title": { "description": "Title of the key to add", "type": "string", @@ -6459,6 +6659,13 @@ "description": "Release represents a repository release", "type": "object", "properties": { + "assets": { + "type": "array", + "items": { + "$ref": "#/definitions/Attachment" + }, + "x-go-name": "Assets" + }, "author": { "$ref": "#/definitions/User" }, @@ -6848,6 +7055,19 @@ "AccessTokenList": { "description": "AccessTokenList represents a list of API access token." }, + "Attachment": { + "schema": { + "$ref": "#/definitions/Attachment" + } + }, + "AttachmentList": { + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Attachment" + } + } + }, "Branch": { "schema": { "$ref": "#/definitions/Branch" diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 6bbc014266eed..913ccb025e49e 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -464,9 +464,15 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/releases", func() { m.Combo("").Get(repo.ListReleases). Post(reqToken(), reqRepoWriter(), context.ReferencesGitRepo(), bind(api.CreateReleaseOption{}), repo.CreateRelease) - m.Combo("/:id").Get(repo.GetRelease). - Patch(reqToken(), reqRepoWriter(), context.ReferencesGitRepo(), bind(api.EditReleaseOption{}), repo.EditRelease). - Delete(reqToken(), reqRepoWriter(), repo.DeleteRelease) + m.Group("/:id", func() { + m.Combo("").Get(repo.GetRelease). + Patch(reqToken(), reqRepoWriter(), context.ReferencesGitRepo(), bind(api.EditReleaseOption{}), repo.EditRelease). + Delete(reqToken(), reqRepoWriter(), repo.DeleteRelease) + m.Group("/attachments", func() { + m.Combo("").Get(repo.ListReleaseAttachments) + m.Combo("/:attachment").Get(repo.GetReleaseAttachment) + }) + }) }) m.Post("/mirror-sync", reqToken(), reqRepoWriter(), repo.MirrorSync) m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig) diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index 41efa482ddca7..629fb2ea57cf9 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -13,7 +13,7 @@ import ( // GetRelease get a single release of a repository func GetRelease(ctx *context.APIContext) { - // swagger:operation GET /repos/{owner}/{repo}/releases repository repoGetRelease + // swagger:operation GET /repos/{owner}/{repo}/releases/{id} repository repoGetRelease // --- // summary: Get a release // produces: @@ -29,7 +29,7 @@ func GetRelease(ctx *context.APIContext) { // description: name of the repo // type: string // required: true - // - name: repo + // - name: id // in: path // description: id of the release to get // type: integer diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go new file mode 100644 index 0000000000000..98b61c518d0f7 --- /dev/null +++ b/routers/api/v1/repo/release_attachment.go @@ -0,0 +1,97 @@ +package repo + +import ( + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/models" +) + +// GetReleaseAttachment gets a single attachment of the release +func GetReleaseAttachment(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id} repository repoGetReleaseAttachment + // --- + // summary: Get a release attachment + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: id + // in: path + // description: id of the release + // type: integer + // required: true + // - name: attachment_id + // in: path + // description: id of the attachment to get + // type: integer + // required: true + // responses: + // "200": + // "$ref": "#/responses/Attachment" + releaseId := ctx.ParamsInt64(":id") + attachId := ctx.ParamsInt64(":attachment") + attach, err := models.GetAttachmentByID(attachId) + if err != nil { + ctx.Error(500, "GetAttachmentByID", err) + return + } + if attach.ReleaseID != releaseId { + ctx.Status(404) + return + } + // FIXME Should prove the existence of the given repo, but results in unnecessary database requests + ctx.JSON(200, attach.APIFormat()) +} + + +// ListReleaseAttachments lists all attachments of the release +func ListReleaseAttachments(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/releases/{id}/attachments repository repoListReleaseAttachments + // --- + // summary: List release's attachments + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: id + // in: path + // description: id of the release + // type: integer + // required: true + // responses: + // "200": + // "$ref": "#/responses/AttachmentList" + releaseId := ctx.ParamsInt64(":id") + release, err := models.GetReleaseByID(releaseId) + if err != nil { + ctx.Error(500, "GetReleaseByID", err) + return + } + if release.RepoID != ctx.Repo.Repository.ID { + ctx.Status(404) + return + } + if err := release.LoadAttributes(); err != nil { + ctx.Error(500, "LoadAttributes", err) + return + } + ctx.JSON(200, release.APIFormat().Attachments) +} + diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index 703f7d18dde07..dbfb2edbd0635 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -90,3 +90,15 @@ type swaggerResponseWatchInfo struct { type swaggerResponseSearchResults struct { Body api.SearchResults `json:"body"` } + +// swagger:response AttachmentList +type swaggerResponseAttachmentList struct { + //in: body + Body []api.Attachment `json:"body` +} + +// swagger:response Attachment +type swaggerResponseAttachment struct { + //in: body + Body api.Attachment `json:"body"` +} diff --git a/vendor/code.gitea.io/sdk/gitea/admin_user.go b/vendor/code.gitea.io/sdk/gitea/admin_user.go index 6d736d3462fc0..bc0f36994d3c3 100644 --- a/vendor/code.gitea.io/sdk/gitea/admin_user.go +++ b/vendor/code.gitea.io/sdk/gitea/admin_user.go @@ -12,7 +12,7 @@ import ( // CreateUserOption create user options type CreateUserOption struct { - SourceID int64 `json:"source_id"` + SourceID int64 `json:"source_id"` LoginName string `json:"login_name"` // required: true Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"` @@ -21,8 +21,8 @@ type CreateUserOption struct { // swagger:strfmt email Email string `json:"email" binding:"Required;Email;MaxSize(254)"` // required: true - Password string `json:"password" binding:"Required;MaxSize(255)"` - SendNotify bool `json:"send_notify"` + Password string `json:"password" binding:"Required;MaxSize(255)"` + SendNotify bool `json:"send_notify"` } // AdminCreateUser create a user @@ -37,20 +37,20 @@ func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) { // EditUserOption edit user options type EditUserOption struct { - SourceID int64 `json:"source_id"` + SourceID int64 `json:"source_id"` LoginName string `json:"login_name"` - FullName string `json:"full_name" binding:"MaxSize(100)"` + FullName string `json:"full_name" binding:"MaxSize(100)"` // required: true // swagger:strfmt email - Email string `json:"email" binding:"Required;Email;MaxSize(254)"` - Password string `json:"password" binding:"MaxSize(255)"` - Website string `json:"website" binding:"MaxSize(50)"` - Location string `json:"location" binding:"MaxSize(50)"` - Active *bool `json:"active"` - Admin *bool `json:"admin"` - AllowGitHook *bool `json:"allow_git_hook"` - AllowImportLocal *bool `json:"allow_import_local"` - MaxRepoCreation *int `json:"max_repo_creation"` + Email string `json:"email" binding:"Required;Email;MaxSize(254)"` + Password string `json:"password" binding:"MaxSize(255)"` + Website string `json:"website" binding:"MaxSize(50)"` + Location string `json:"location" binding:"MaxSize(50)"` + Active *bool `json:"active"` + Admin *bool `json:"admin"` + AllowGitHook *bool `json:"allow_git_hook"` + AllowImportLocal *bool `json:"allow_import_local"` + MaxRepoCreation *int `json:"max_repo_creation"` } // AdminEditUser modify user informations diff --git a/vendor/code.gitea.io/sdk/gitea/attachment.go b/vendor/code.gitea.io/sdk/gitea/attachment.go index 10e7a1d56ad57..4f2b4a1a9e2ea 100644 --- a/vendor/code.gitea.io/sdk/gitea/attachment.go +++ b/vendor/code.gitea.io/sdk/gitea/attachment.go @@ -6,12 +6,14 @@ package gitea // import "code.gitea.io/sdk/gitea" import "time" // Attachment a generic attachment +// swagger:model 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"` + ID int64 `json:"id"` + Name string `json:"name"` + Size int64 `json:"size"` + DownloadCount int64 `json:"download_count"` + // swagger:strfmt date-time + Created time.Time `json:"created_at"` + UUID string `json:"uuid"` + DownloadURL string `json:"browser_download_url"` } diff --git a/vendor/code.gitea.io/sdk/gitea/gitea.go b/vendor/code.gitea.io/sdk/gitea/gitea.go index 20cb44feed7ee..374a3faa9604c 100644 --- a/vendor/code.gitea.io/sdk/gitea/gitea.go +++ b/vendor/code.gitea.io/sdk/gitea/gitea.go @@ -7,6 +7,7 @@ package gitea import ( "encoding/json" "errors" + "fmt" "io" "io/ioutil" "net/http" @@ -69,6 +70,8 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re return nil, errors.New("403 Forbidden") case 404: return nil, errors.New("404 Not Found") + case 422: + return nil, fmt.Errorf("422 Unprocessable Entity: %s", string(data)) } if resp.StatusCode/100 != 2 { diff --git a/vendor/code.gitea.io/sdk/gitea/hook.go b/vendor/code.gitea.io/sdk/gitea/hook.go index b7109482f8cde..a9b0bdbd066b8 100644 --- a/vendor/code.gitea.io/sdk/gitea/hook.go +++ b/vendor/code.gitea.io/sdk/gitea/hook.go @@ -21,16 +21,16 @@ var ( // Hook a hook is a web hook when one repository changed type Hook struct { - ID int64 `json:"id"` - Type string `json:"type"` - URL string `json:"-"` - Config map[string]string `json:"config"` - Events []string `json:"events"` - Active bool `json:"active"` + ID int64 `json:"id"` + Type string `json:"type"` + URL string `json:"-"` + Config map[string]string `json:"config"` + Events []string `json:"events"` + Active bool `json:"active"` // swagger:strfmt date-time - Updated time.Time `json:"updated_at"` + Updated time.Time `json:"updated_at"` // swagger:strfmt date-time - Created time.Time `json:"created_at"` + Created time.Time `json:"created_at"` } // HookList represents a list of API hook. @@ -67,7 +67,7 @@ type CreateHookOption struct { Type string `json:"type" binding:"Required"` // required: true Config map[string]string `json:"config" binding:"Required"` - Events []string `json:"events"` + Events []string `json:"events"` // default: false Active bool `json:"active"` } @@ -95,8 +95,8 @@ func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, // EditHookOption options when modify one hook type EditHookOption struct { Config map[string]string `json:"config"` - Events []string `json:"events"` - Active *bool `json:"active"` + Events []string `json:"events"` + Active *bool `json:"active"` } // EditOrgHook modify one hook of an organization, with hook id and options @@ -140,7 +140,7 @@ type Payloader interface { // PayloadUser represents the author or committer of a commit type PayloadUser struct { // Full name of the commit author - Name string `json:"name"` + Name string `json:"name"` // swagger:strfmt email Email string `json:"email"` UserName string `json:"username"` @@ -159,7 +159,7 @@ type PayloadCommit struct { Committer *PayloadUser `json:"committer"` Verification *PayloadCommitVerification `json:"verification"` // swagger:strfmt date-time - Timestamp time.Time `json:"timestamp"` + Timestamp time.Time `json:"timestamp"` } // PayloadCommitVerification represents the GPG verification of a commit diff --git a/vendor/code.gitea.io/sdk/gitea/issue.go b/vendor/code.gitea.io/sdk/gitea/issue.go index 720f54caae103..206c52a59e4ba 100644 --- a/vendor/code.gitea.io/sdk/gitea/issue.go +++ b/vendor/code.gitea.io/sdk/gitea/issue.go @@ -43,12 +43,12 @@ type Issue struct { // // type: string // enum: open,closed - State StateType `json:"state"` - Comments int `json:"comments"` + State StateType `json:"state"` + Comments int `json:"comments"` // swagger:strfmt date-time - Created time.Time `json:"created_at"` + Created time.Time `json:"created_at"` // swagger:strfmt date-time - Updated time.Time `json:"updated_at"` + Updated time.Time `json:"updated_at"` PullRequest *PullRequestMeta `json:"pull_request"` } @@ -86,15 +86,15 @@ func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) { // CreateIssueOption options to create one issue type CreateIssueOption struct { // required:true - Title string `json:"title" binding:"Required"` - Body string `json:"body"` + Title string `json:"title" binding:"Required"` + Body string `json:"body"` // username of assignee - Assignee string `json:"assignee"` + Assignee string `json:"assignee"` // milestone id - Milestone int64 `json:"milestone"` + Milestone int64 `json:"milestone"` // list of label ids - Labels []int64 `json:"labels"` - Closed bool `json:"closed"` + Labels []int64 `json:"labels"` + Closed bool `json:"closed"` } // CreateIssue create a new issue for a given repository diff --git a/vendor/code.gitea.io/sdk/gitea/issue_comment.go b/vendor/code.gitea.io/sdk/gitea/issue_comment.go index f146c1fe2db2e..2c8127c609734 100644 --- a/vendor/code.gitea.io/sdk/gitea/issue_comment.go +++ b/vendor/code.gitea.io/sdk/gitea/issue_comment.go @@ -13,16 +13,16 @@ import ( // Comment represents a comment on a commit or issue type Comment struct { - ID int64 `json:"id"` - HTMLURL string `json:"html_url"` - PRURL string `json:"pull_request_url"` - IssueURL string `json:"issue_url"` - Poster *User `json:"user"` - Body string `json:"body"` + ID int64 `json:"id"` + HTMLURL string `json:"html_url"` + PRURL string `json:"pull_request_url"` + IssueURL string `json:"issue_url"` + Poster *User `json:"user"` + Body string `json:"body"` // swagger:strfmt date-time - Created time.Time `json:"created_at"` + Created time.Time `json:"created_at"` // swagger:strfmt date-time - Updated time.Time `json:"updated_at"` + Updated time.Time `json:"updated_at"` } // ListIssueComments list comments on an issue. diff --git a/vendor/code.gitea.io/sdk/gitea/issue_label.go b/vendor/code.gitea.io/sdk/gitea/issue_label.go index 3acf1440b45fd..47d1b8221e98b 100644 --- a/vendor/code.gitea.io/sdk/gitea/issue_label.go +++ b/vendor/code.gitea.io/sdk/gitea/issue_label.go @@ -13,8 +13,8 @@ import ( // Label a label to an issue or a pr // swagger:model type Label struct { - ID int64 `json:"id"` - Name string `json:"name"` + ID int64 `json:"id"` + Name string `json:"name"` // example: 00aabb Color string `json:"color"` URL string `json:"url"` @@ -36,7 +36,7 @@ func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) { // CreateLabelOption options for creating a label type CreateLabelOption struct { // required:true - Name string `json:"name" binding:"Required"` + Name string `json:"name" binding:"Required"` // required:true // example: #00aabb Color string `json:"color" binding:"Required;Size(7)"` diff --git a/vendor/code.gitea.io/sdk/gitea/issue_milestone.go b/vendor/code.gitea.io/sdk/gitea/issue_milestone.go index d82006742244b..775a6a9117510 100644 --- a/vendor/code.gitea.io/sdk/gitea/issue_milestone.go +++ b/vendor/code.gitea.io/sdk/gitea/issue_milestone.go @@ -13,16 +13,16 @@ import ( // Milestone milestone is a collection of issues on one repository type Milestone struct { - ID int64 `json:"id"` - Title string `json:"title"` - Description string `json:"description"` - State StateType `json:"state"` - OpenIssues int `json:"open_issues"` - ClosedIssues int `json:"closed_issues"` + ID int64 `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + State StateType `json:"state"` + OpenIssues int `json:"open_issues"` + ClosedIssues int `json:"closed_issues"` // swagger:strfmt date-time - Closed *time.Time `json:"closed_at"` + Closed *time.Time `json:"closed_at"` // swagger:strfmt date-time - Deadline *time.Time `json:"due_on"` + Deadline *time.Time `json:"due_on"` } // ListRepoMilestones list all the milestones of one repository @@ -39,10 +39,10 @@ func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) // CreateMilestoneOption options for creating a milestone type CreateMilestoneOption struct { - Title string `json:"title"` - Description string `json:"description"` + Title string `json:"title"` + Description string `json:"description"` // swagger:strfmt date-time - Deadline *time.Time `json:"due_on"` + Deadline *time.Time `json:"due_on"` } // CreateMilestone create one milestone with options diff --git a/vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go b/vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go index dcdecbb2a2b14..7f4b64cbb3f99 100644 --- a/vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go +++ b/vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go @@ -13,7 +13,7 @@ import ( // TrackedTime worked time for an issue / pr type TrackedTime struct { - ID int64 `json:"id"` + ID int64 `json:"id"` // swagger:strfmt date-time Created time.Time `json:"created"` // Time in seconds diff --git a/vendor/code.gitea.io/sdk/gitea/org.go b/vendor/code.gitea.io/sdk/gitea/org.go index d67d707e7b0e5..19238d1028453 100644 --- a/vendor/code.gitea.io/sdk/gitea/org.go +++ b/vendor/code.gitea.io/sdk/gitea/org.go @@ -42,11 +42,11 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) { // CreateOrgOption options for creating an organization type CreateOrgOption struct { // required: true - UserName string `json:"username" binding:"Required"` - FullName string `json:"full_name"` + UserName string `json:"username" binding:"Required"` + FullName string `json:"full_name"` Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` + Website string `json:"website"` + Location string `json:"location"` } // EditOrgOption options for editing an organization diff --git a/vendor/code.gitea.io/sdk/gitea/org_team.go b/vendor/code.gitea.io/sdk/gitea/org_team.go index 0c9a740350fb9..2fc6796d43ff9 100644 --- a/vendor/code.gitea.io/sdk/gitea/org_team.go +++ b/vendor/code.gitea.io/sdk/gitea/org_team.go @@ -10,7 +10,7 @@ type Team struct { Name string `json:"name"` Description string `json:"description"` // enum: none,read,write,admin,owner - Permission string `json:"permission"` + Permission string `json:"permission"` } // CreateTeamOption options for creating a team @@ -19,7 +19,7 @@ type CreateTeamOption struct { Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` Description string `json:"description" binding:"MaxSize(255)"` // enum: read,write,admin - Permission string `json:"permission"` + Permission string `json:"permission"` } // EditTeamOption options for editing a team @@ -28,5 +28,5 @@ type EditTeamOption struct { Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` Description string `json:"description" binding:"MaxSize(255)"` // enum: read,write,admin - Permission string `json:"permission"` + Permission string `json:"permission"` } diff --git a/vendor/code.gitea.io/sdk/gitea/pull.go b/vendor/code.gitea.io/sdk/gitea/pull.go index 0aa0ea8cc1f27..ee3fe116de7a2 100644 --- a/vendor/code.gitea.io/sdk/gitea/pull.go +++ b/vendor/code.gitea.io/sdk/gitea/pull.go @@ -29,8 +29,8 @@ type PullRequest struct { DiffURL string `json:"diff_url"` PatchURL string `json:"patch_url"` - Mergeable bool `json:"mergeable"` - HasMerged bool `json:"merged"` + Mergeable bool `json:"mergeable"` + HasMerged bool `json:"merged"` // swagger:strfmt date-time Merged *time.Time `json:"merged_at"` MergedCommitID *string `json:"merge_commit_sha"` diff --git a/vendor/code.gitea.io/sdk/gitea/release.go b/vendor/code.gitea.io/sdk/gitea/release.go index 01e41e35a69ab..e2aea693c5a3c 100644 --- a/vendor/code.gitea.io/sdk/gitea/release.go +++ b/vendor/code.gitea.io/sdk/gitea/release.go @@ -13,21 +13,22 @@ 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"` + 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"` // swagger:strfmt date-time - CreatedAt time.Time `json:"created_at"` + CreatedAt time.Time `json:"created_at"` // swagger:strfmt date-time - PublishedAt time.Time `json:"published_at"` - Publisher *User `json:"author"` + PublishedAt time.Time `json:"published_at"` + Publisher *User `json:"author"` + Attachments []*Attachment `json:"attachments"` } // ListReleases list releases of a repository diff --git a/vendor/code.gitea.io/sdk/gitea/repo.go b/vendor/code.gitea.io/sdk/gitea/repo.go index 3def6e26ceee9..339cbd33deaac 100644 --- a/vendor/code.gitea.io/sdk/gitea/repo.go +++ b/vendor/code.gitea.io/sdk/gitea/repo.go @@ -41,10 +41,10 @@ type Repository struct { OpenIssues int `json:"open_issues_count"` DefaultBranch string `json:"default_branch"` // swagger:strfmt date-time - Created time.Time `json:"created_at"` + Created time.Time `json:"created_at"` // swagger:strfmt date-time - Updated time.Time `json:"updated_at"` - Permissions *Permission `json:"permissions,omitempty"` + Updated time.Time `json:"updated_at"` + Permissions *Permission `json:"permissions,omitempty"` } // ListMyRepos lists all repositories for the authenticated user that has access to. @@ -122,15 +122,15 @@ func (c *Client) DeleteRepo(owner, repo string) error { // MigrateRepoOption options for migrating a repository from an external service type MigrateRepoOption struct { // required: true - CloneAddr string `json:"clone_addr" binding:"Required"` + CloneAddr string `json:"clone_addr" binding:"Required"` AuthUsername string `json:"auth_username"` AuthPassword string `json:"auth_password"` // required: true UID int `json:"uid" binding:"Required"` // required: true - RepoName string `json:"repo_name" binding:"Required"` - Mirror bool `json:"mirror"` - Private bool `json:"private"` + RepoName string `json:"repo_name" binding:"Required"` + Mirror bool `json:"mirror"` + Private bool `json:"private"` Description string `json:"description"` } diff --git a/vendor/code.gitea.io/sdk/gitea/repo_key.go b/vendor/code.gitea.io/sdk/gitea/repo_key.go index f2f1038aa3689..ec53311bdaa55 100644 --- a/vendor/code.gitea.io/sdk/gitea/repo_key.go +++ b/vendor/code.gitea.io/sdk/gitea/repo_key.go @@ -13,10 +13,10 @@ import ( // DeployKey a deploy key type DeployKey struct { - ID int64 `json:"id"` - Key string `json:"key"` - URL string `json:"url"` - Title string `json:"title"` + ID int64 `json:"id"` + Key string `json:"key"` + URL string `json:"url"` + Title string `json:"title"` // swagger:strfmt date-time Created time.Time `json:"created_at"` ReadOnly bool `json:"read_only"` diff --git a/vendor/code.gitea.io/sdk/gitea/status.go b/vendor/code.gitea.io/sdk/gitea/status.go index 5ce25321afc96..3060ab1b2b23b 100644 --- a/vendor/code.gitea.io/sdk/gitea/status.go +++ b/vendor/code.gitea.io/sdk/gitea/status.go @@ -38,9 +38,9 @@ type Status struct { Context string `json:"context"` Creator *User `json:"creator"` // swagger:strfmt date-time - Created time.Time `json:"created_at"` + Created time.Time `json:"created_at"` // swagger:strfmt date-time - Updated time.Time `json:"updated_at"` + Updated time.Time `json:"updated_at"` } // CombinedStatus holds the combined state of several statuses for a single commit diff --git a/vendor/code.gitea.io/sdk/gitea/user.go b/vendor/code.gitea.io/sdk/gitea/user.go index d104cc9933fe5..f6b687e979ee6 100644 --- a/vendor/code.gitea.io/sdk/gitea/user.go +++ b/vendor/code.gitea.io/sdk/gitea/user.go @@ -13,13 +13,13 @@ import ( // swagger:model type User struct { // the user's id - ID int64 `json:"id"` + ID int64 `json:"id"` // the user's username - UserName string `json:"login"` + UserName string `json:"login"` // the user's full name - FullName string `json:"full_name"` + FullName string `json:"full_name"` // swagger:strfmt email - Email string `json:"email"` + Email string `json:"email"` // URL to the user's avatar AvatarURL string `json:"avatar_url"` } diff --git a/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go b/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go index ae5dcdcb105cb..0817d89461a1c 100644 --- a/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go +++ b/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go @@ -24,9 +24,9 @@ type GPGKey struct { CanEncryptStorage bool `json:"can_encrypt_storage"` CanCertify bool `json:"can_certify"` // swagger:strfmt date-time - Created time.Time `json:"created_at,omitempty"` + Created time.Time `json:"created_at,omitempty"` // swagger:strfmt date-time - Expires time.Time `json:"expires_at,omitempty"` + Expires time.Time `json:"expires_at,omitempty"` } // GPGKeyEmail an email attached to a GPGKey diff --git a/vendor/vendor.json b/vendor/vendor.json index 520cf8e22b7ed..8e53472534f77 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,10 +9,13 @@ "revisionTime": "2018-01-14T14:37:32Z" }, { - "checksumSHA1": "Qtq0kW+BnpYMOriaoCjMa86WGG8=", + "checksumSHA1": "g1n6fJkgAsi/3VYGP2h0jN2k1zc=", + "origin": "github.com/JonasFranzDEV/go-sdk/gitea", "path": "code.gitea.io/sdk/gitea", - "revision": "79eee8f12c7fc1cc5b802c5cdc5b494ef3733866", - "revisionTime": "2017-12-20T06:57:50Z" + "revision": "05408a9188b961646914e6873b97de1b43a86b6a", + "revisionTime": "2018-02-08T21:06:42Z", + "version": "=711-release-api", + "versionExact": "711-release-api" }, { "checksumSHA1": "bOODD4Gbw3GfcuQPU2dI40crxxk=", From b2a780dec5fc723a02d7c9fbc040971a0ff524ba Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Thu, 8 Feb 2018 22:49:38 +0100 Subject: [PATCH 02/18] Add unit tests for new attachment functions Fix comments Signed-off-by: Jonas Franz --- models/attachment.go | 18 +++++++++--------- models/attachment_test.go | 16 ++++++++++++++++ routers/api/v1/repo/release_attachment.go | 16 +++++++--------- routers/api/v1/swagger/repo.go | 2 +- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index ffa747256cae2..bf8a6a00e9778 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -13,8 +13,8 @@ import ( gouuid "github.com/satori/go.uuid" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" api "code.gitea.io/sdk/gitea" ) @@ -40,16 +40,17 @@ func (a *Attachment) IncreaseDownloadCount() error { return nil } +// APIFormat converts models.Attachment to api.Attachment func (a *Attachment) APIFormat() *api.Attachment { size, _ := a.Size() return &api.Attachment{ - ID: a.ID, - Name: a.Name, - Created: a.CreatedUnix.AsTime(), + ID: a.ID, + Name: a.Name, + Created: a.CreatedUnix.AsTime(), DownloadCount: a.DownloadCount, - Size: size, - UUID: a.UUID, - DownloadURL: a.DownloadURL(), + Size: size, + UUID: a.UUID, + DownloadURL: a.DownloadURL(), } } @@ -74,7 +75,7 @@ func (a *Attachment) Size() (int64, error) { } // DownloadURL returns the download url of the attached file -func (a *Attachment) DownloadURL() string { +func (a *Attachment) DownloadURL() string { return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID) } @@ -125,7 +126,6 @@ func getAttachmentByID(e Engine, id int64) (*Attachment, error) { return attach, nil } - func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) { attach := &Attachment{UUID: uuid} has, err := e.Get(attach) diff --git a/models/attachment_test.go b/models/attachment_test.go index d568e39431b4a..df5bde518d02d 100644 --- a/models/attachment_test.go +++ b/models/attachment_test.go @@ -58,3 +58,19 @@ func TestDeleteAttachments(t *testing.T) { assert.True(t, IsErrAttachmentNotExist(err)) assert.Nil(t, attachment) } + +func TestGetAttachmentByID(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + attach, err := GetAttachmentByID(1) + assert.NoError(t, err) + assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.UUID) +} + +func TestAttachment_DownloadURL(t *testing.T) { + attach := &Attachment{ + UUID: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", + ID: 1, + } + assert.Equal(t, "https://try.gitea.io/attachments/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach) +} diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index 98b61c518d0f7..2cb3e661de655 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -1,8 +1,8 @@ package repo import ( - "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/context" ) // GetReleaseAttachment gets a single attachment of the release @@ -36,14 +36,14 @@ func GetReleaseAttachment(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/Attachment" - releaseId := ctx.ParamsInt64(":id") - attachId := ctx.ParamsInt64(":attachment") - attach, err := models.GetAttachmentByID(attachId) + releaseID := ctx.ParamsInt64(":id") + attachID := ctx.ParamsInt64(":attachment") + attach, err := models.GetAttachmentByID(attachID) if err != nil { ctx.Error(500, "GetAttachmentByID", err) return } - if attach.ReleaseID != releaseId { + if attach.ReleaseID != releaseID { ctx.Status(404) return } @@ -51,7 +51,6 @@ func GetReleaseAttachment(ctx *context.APIContext) { ctx.JSON(200, attach.APIFormat()) } - // ListReleaseAttachments lists all attachments of the release func ListReleaseAttachments(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/releases/{id}/attachments repository repoListReleaseAttachments @@ -78,8 +77,8 @@ func ListReleaseAttachments(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/AttachmentList" - releaseId := ctx.ParamsInt64(":id") - release, err := models.GetReleaseByID(releaseId) + releaseID := ctx.ParamsInt64(":id") + release, err := models.GetReleaseByID(releaseID) if err != nil { ctx.Error(500, "GetReleaseByID", err) return @@ -94,4 +93,3 @@ func ListReleaseAttachments(ctx *context.APIContext) { } ctx.JSON(200, release.APIFormat().Attachments) } - diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index dbfb2edbd0635..1f256911050f1 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -94,7 +94,7 @@ type swaggerResponseSearchResults struct { // swagger:response AttachmentList type swaggerResponseAttachmentList struct { //in: body - Body []api.Attachment `json:"body` + Body []api.Attachment `json:"body"` } // swagger:response Attachment From 1407c1c467a8d9617b810b1cccdccee00a6a1a4c Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Feb 2018 09:08:24 +0100 Subject: [PATCH 03/18] fix lint --- models/release.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/models/release.go b/models/release.go index 455cfc38ca7e1..9b0128a1313dd 100644 --- a/models/release.go +++ b/models/release.go @@ -53,10 +53,7 @@ func (r *Release) loadAttributes(e Engine) error { return err } } - if err := GetReleaseAttachments(r); err != nil { - return err - } - return nil + return GetReleaseAttachments(r) } // LoadAttributes load repo and publisher attributes for a release From 80c655574d3a16b2410c9be772846fcd64fb91c5 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 9 Feb 2018 10:19:28 +0100 Subject: [PATCH 04/18] Update vendor.json Signed-off-by: Jonas Franz --- vendor/code.gitea.io/sdk/gitea/attachment.go | 23 +++++++++++++++++++- vendor/vendor.json | 6 ++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/vendor/code.gitea.io/sdk/gitea/attachment.go b/vendor/code.gitea.io/sdk/gitea/attachment.go index 4f2b4a1a9e2ea..78bb5d1a0b616 100644 --- a/vendor/code.gitea.io/sdk/gitea/attachment.go +++ b/vendor/code.gitea.io/sdk/gitea/attachment.go @@ -3,7 +3,10 @@ // license that can be found in the LICENSE file. package gitea // import "code.gitea.io/sdk/gitea" -import "time" +import ( + "fmt" + "time" +) // Attachment a generic attachment // swagger:model @@ -17,3 +20,21 @@ type Attachment struct { UUID string `json:"uuid"` DownloadURL string `json:"browser_download_url"` } + +// ListReleaseAttachments list release's attachments +func (c *Client) ListReleaseAttachments(user, repo string, release int64) ([]*Attachment, error) { + attachments := make([]*Attachment, 0, 10) + err := c.getParsedResponse("GET", + fmt.Sprintf("/repos/%s/%s/releases/%d/attachments", user, repo, release), + nil, nil, &attachments) + return attachments, err +} + +// ListReleaseAttachments list release's attachments +func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, error) { + a := new(Attachment) + err := c.getParsedResponse("GET", + fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, id), + nil, nil, &a) + return a, err +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 8e53472534f77..fe057483155cc 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,11 +9,11 @@ "revisionTime": "2018-01-14T14:37:32Z" }, { - "checksumSHA1": "g1n6fJkgAsi/3VYGP2h0jN2k1zc=", + "checksumSHA1": "97LRDvbujBg4j0wYP/WdBjxu8TA=", "origin": "github.com/JonasFranzDEV/go-sdk/gitea", "path": "code.gitea.io/sdk/gitea", - "revision": "05408a9188b961646914e6873b97de1b43a86b6a", - "revisionTime": "2018-02-08T21:06:42Z", + "revision": "719ad42a282dc680daa91c9b9ac3c12baba0dc03", + "revisionTime": "2018-02-08T21:56:41Z", "version": "=711-release-api", "versionExact": "711-release-api" }, From 95965d8da17616e1e266fe5d47d537b5e7bc1b90 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 9 Feb 2018 10:29:00 +0100 Subject: [PATCH 05/18] remove version of sdk Signed-off-by: Jonas Franz --- vendor/vendor.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vendor/vendor.json b/vendor/vendor.json index fe057483155cc..bbe56b180eae2 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -13,9 +13,7 @@ "origin": "github.com/JonasFranzDEV/go-sdk/gitea", "path": "code.gitea.io/sdk/gitea", "revision": "719ad42a282dc680daa91c9b9ac3c12baba0dc03", - "revisionTime": "2018-02-08T21:56:41Z", - "version": "=711-release-api", - "versionExact": "711-release-api" + "revisionTime": "2018-02-08T21:56:41Z" }, { "checksumSHA1": "bOODD4Gbw3GfcuQPU2dI40crxxk=", From 640ef5a3c53f2fc61109e1c31a156259f5033aec Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 9 Feb 2018 10:35:31 +0100 Subject: [PATCH 06/18] Fix unit tests Add missing license header Signed-off-by: Jonas Franz --- models/attachment_test.go | 2 +- routers/api/v1/repo/release_attachment.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/models/attachment_test.go b/models/attachment_test.go index df5bde518d02d..8d3898e446817 100644 --- a/models/attachment_test.go +++ b/models/attachment_test.go @@ -72,5 +72,5 @@ func TestAttachment_DownloadURL(t *testing.T) { UUID: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", ID: 1, } - assert.Equal(t, "https://try.gitea.io/attachments/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach) + assert.Equal(t, "https://try.gitea.io/attachments/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.DownloadURL()) } diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index 2cb3e661de655..f0495ed6584a3 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -1,3 +1,7 @@ +// Copyright 2018 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 repo import ( From ad412582e8dfeae78977041448a3d02ba1f05c95 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 9 Feb 2018 12:35:44 +0100 Subject: [PATCH 07/18] Add CreateReleaseAttachment Add EditReleaseAttachment Add DeleteReleaseAttachment Signed-off-by: Jonas Franz --- models/attachment.go | 18 ++ models/attachment_test.go | 13 ++ package.json | 2 +- public/swagger.v1.json | 179 ++++++++++++++-- routers/api/v1/api.go | 7 +- routers/api/v1/repo/release_attachment.go | 213 +++++++++++++++++++ routers/api/v1/swagger/options.go | 2 + vendor/code.gitea.io/sdk/gitea/attachment.go | 62 ++++++ vendor/vendor.json | 6 +- 9 files changed, 483 insertions(+), 19 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index bf8a6a00e9778..36a362c8b74be 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" api "code.gitea.io/sdk/gitea" + "github.com/go-xorm/xorm" ) // Attachment represent a attachment of issue/comment/release. @@ -225,3 +226,20 @@ func DeleteAttachmentsByComment(commentID int64, remove bool) (int, error) { return DeleteAttachments(attachments, remove) } + +// UpdateAttachment updates the given attachment in database +func UpdateAttachment(atta *Attachment) error { + return updateAttachment(x, atta) +} + +func updateAttachment(e Engine, atta *Attachment) error { + var sess *xorm.Session + if atta.ID != 0 || atta.UUID == "" { + sess = e.ID(atta.ID) + } else { + // Use uuid only if id is not set and uuid is set + sess = e.Where("uuid = ?", atta.UUID) + } + _, err := sess.AllCols().Update(atta) + return err +} diff --git a/models/attachment_test.go b/models/attachment_test.go index 8d3898e446817..be4baf3055612 100644 --- a/models/attachment_test.go +++ b/models/attachment_test.go @@ -74,3 +74,16 @@ func TestAttachment_DownloadURL(t *testing.T) { } assert.Equal(t, "https://try.gitea.io/attachments/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.DownloadURL()) } + +func TestUpdateAttachment(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + attach, err := GetAttachmentByID(1) + assert.NoError(t, err) + assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.UUID) + + attach.Name = "new_name" + assert.NoError(t, UpdateAttachment(attach)) + + AssertExistsAndLoadBean(t, &Attachment{Name: "new_name"}) +} diff --git a/package.json b/package.json index 8251e5026446c..3410bb1f3589d 100644 --- a/package.json +++ b/package.json @@ -4,4 +4,4 @@ "less": "^2.7.2", "less-plugin-clean-css": "^1.5.1" } -} \ No newline at end of file +} diff --git a/public/swagger.v1.json b/public/swagger.v1.json index f204fdd1c80bd..0c21d9978dbd1 100644 --- a/public/swagger.v1.json +++ b/public/swagger.v1.json @@ -3458,6 +3458,54 @@ "$ref": "#/responses/AttachmentList" } } + }, + "post": { + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Create a release attachment", + "operationId": "repoCreateReleaseAttachment", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the release", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "file", + "description": "attachment to upload", + "name": "attachment", + "in": "formData", + "required": true + } + ], + "responses": { + "201": { + "$ref": "#/responses/Attachment" + } + } } }, "/repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id}": { @@ -3505,6 +3553,106 @@ "$ref": "#/responses/Attachment" } } + }, + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Delete a release attachment", + "operationId": "repoDeleteReleaseAttachment", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the release", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the attachment to delete", + "name": "attachment_id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + } + } + }, + "patch": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Edit a release attachment", + "operationId": "repoEditReleaseAttachment", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the release", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "id of the attachment to edit", + "name": "attachment_id", + "in": "path", + "required": true + }, + { + "name": "body", + "in": "body", + "schema": { + "$ref": "#/definitions/EditAttachmentOptions" + } + } + ], + "responses": { + "201": { + "$ref": "#/responses/Attachment" + } + } } }, "/repos/{owner}/{repo}/stargazers": { @@ -5421,8 +5569,7 @@ "properties": { "color": { "type": "string", - "x-go-name": "Color", - "example": "#00aabb" + "x-go-name": "Color" }, "name": { "type": "string", @@ -5740,6 +5887,17 @@ }, "x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea" }, + "EditAttachmentOptions": { + "description": "EditAttachmentOptions options for editing attachments", + "type": "object", + "properties": { + "name": { + "type": "string", + "x-go-name": "Name" + } + }, + "x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea" + }, "EditHookOption": { "description": "EditHookOption options when modify one hook", "type": "object", @@ -5831,8 +5989,6 @@ "x-go-name": "Description" }, "due_on": { - "type": "string", - "format": "date-time", "x-go-name": "Deadline" }, "state": { @@ -6210,9 +6366,9 @@ "type": "object", "properties": { "color": { + "description": "example: 00aabb", "type": "string", - "x-go-name": "Color", - "example": "00aabb" + "x-go-name": "Color" }, "id": { "type": "integer", @@ -6648,8 +6804,6 @@ "x-go-name": "HasMerged" }, "merged_at": { - "type": "string", - "format": "date-time", "x-go-name": "Merged" } }, @@ -6659,12 +6813,12 @@ "description": "Release represents a repository release", "type": "object", "properties": { - "assets": { + "attachments": { "type": "array", "items": { "$ref": "#/definitions/Attachment" }, - "x-go-name": "Assets" + "x-go-name": "Attachments" }, "author": { "$ref": "#/definitions/User" @@ -7012,8 +7166,6 @@ "type": "object", "properties": { "created_at": { - "type": "string", - "format": "date-time", "x-go-name": "CreatedAt" }, "ignored": { @@ -7351,7 +7503,7 @@ }, "parameterBodies": { "schema": { - "$ref": "#/definitions/MigrateRepoForm" + "$ref": "#/definitions/EditAttachmentOptions" }, "headers": { "AddCollaboratorOption": {}, @@ -7372,6 +7524,7 @@ "CreateTeamOption": {}, "CreateUserOption": {}, "DeleteEmailOption": {}, + "EditAttachmentOptions": {}, "EditHookOption": {}, "EditIssueCommentOption": {}, "EditIssueOption": {}, diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 913ccb025e49e..d6676ed1f7acd 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -469,8 +469,11 @@ func RegisterRoutes(m *macaron.Macaron) { Patch(reqToken(), reqRepoWriter(), context.ReferencesGitRepo(), bind(api.EditReleaseOption{}), repo.EditRelease). Delete(reqToken(), reqRepoWriter(), repo.DeleteRelease) m.Group("/attachments", func() { - m.Combo("").Get(repo.ListReleaseAttachments) - m.Combo("/:attachment").Get(repo.GetReleaseAttachment) + m.Combo("").Get(repo.ListReleaseAttachments). + Post(reqToken(), reqRepoWriter(), repo.CreateReleaseAttachment) + m.Combo("/:attachment").Get(repo.GetReleaseAttachment). + Patch(reqToken(), reqRepoWriter(), bind(api.EditAttachmentOptions{}), repo.EditReleaseAttachment). + Delete(reqToken(), reqRepoWriter(), repo.DeleteReleaseAttachment) }) }) }) diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index f0495ed6584a3..8ef8c1fa46ece 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -7,6 +7,11 @@ package repo import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" + api "code.gitea.io/sdk/gitea" + "errors" + "net/http" + "strings" ) // GetReleaseAttachment gets a single attachment of the release @@ -97,3 +102,211 @@ func ListReleaseAttachments(ctx *context.APIContext) { } ctx.JSON(200, release.APIFormat().Attachments) } + +// CreateReleaseAttachment creates an attachment and saves the given file +func CreateReleaseAttachment(ctx *context.APIContext) { + // swagger:operation POST /repos/{owner}/{repo}/releases/{id}/attachments repository repoCreateReleaseAttachment + // --- + // summary: Create a release attachment + // produces: + // - application/json + // consumes: + // - multipart/form-data + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: id + // in: path + // description: id of the release + // type: integer + // required: true + // - name: attachment + // in: formData + // description: attachment to upload + // type: file + // required: true + // responses: + // "201": + // "$ref": "#/responses/Attachment" + + // Check if attachments are enabled + if !setting.AttachmentEnabled { + ctx.Error(404, "AttachmentEnabled", errors.New("attachment is not enabled")) + return + } + + // Check if release exists an load release + releaseID := ctx.ParamsInt64(":id") + release, err := models.GetReleaseByID(releaseID) + if err != nil { + ctx.Error(500, "GetReleaseByID", err) + return + } + + // Get uploaded file from request + file, header, err := ctx.GetFile("attachment") + if err != nil { + ctx.Error(500, "GetFile", err) + return + } + defer file.Close() + + buf := make([]byte, 1024) + n, _ := file.Read(buf) + if n > 0 { + buf = buf[:n] + } + + // Check if the filetype is allowed by the settings + fileType := http.DetectContentType(buf) + + allowedTypes := strings.Split(setting.AttachmentAllowedTypes, ",") + allowed := false + for _, t := range allowedTypes { + t := strings.Trim(t, " ") + if t == "*/*" || t == fileType { + allowed = true + break + } + } + + if !allowed { + ctx.Error(400, "DetectContentType", errors.New("File type is not allowed")) + return + } + + // Create a new attachment and save the file + attach, err := models.NewAttachment(header.Filename, buf, file) + if err != nil { + ctx.Error(500, "NewAttachment", err) + return + } + attach.ReleaseID = release.ID + if err := models.UpdateAttachment(attach); err != nil { + ctx.Error(500, "UpdateAttachment", err) + return + } + ctx.JSON(201, attach.APIFormat()) +} + +// EditReleaseAttachment updates the given attachment +func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptions) { + // swagger:operation PATCH /repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id} repository repoEditReleaseAttachment + // --- + // summary: Edit a release attachment + // produces: + // - application/json + // consumes: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: id + // in: path + // description: id of the release + // type: integer + // required: true + // - name: attachment_id + // in: path + // description: id of the attachment to edit + // type: integer + // required: true + // - name: body + // in: body + // schema: + // "$ref": "#/definitions/EditAttachmentOptions" + // responses: + // "201": + // "$ref": "#/responses/Attachment" + + // Check if release exists an load release + releaseID := ctx.ParamsInt64(":id") + attachID := ctx.ParamsInt64(":attachment") + attach, err := models.GetAttachmentByID(attachID) + if err != nil { + ctx.Error(500, "GetAttachmentByID", err) + return + } + if attach.ReleaseID != releaseID { + ctx.Status(404) + return + } + // FIXME Should prove the existence of the given repo, but results in unnecessary database requests + if form.Name != "" { + attach.Name = form.Name + } + + if err := models.UpdateAttachment(attach); err != nil { + ctx.Error(500, "UpdateAttachment", attach) + } + ctx.JSON(201, attach.APIFormat()) +} + +// DeleteReleaseAttachment delete a given attachment +func DeleteReleaseAttachment(ctx *context.APIContext) { + // swagger:operation DELETE /repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id} repository repoDeleteReleaseAttachment + // --- + // summary: Delete a release attachment + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: id + // in: path + // description: id of the release + // type: integer + // required: true + // - name: attachment_id + // in: path + // description: id of the attachment to delete + // type: integer + // required: true + // responses: + // "204": + // "$ref": "#/responses/empty" + + // Check if release exists an load release + releaseID := ctx.ParamsInt64(":id") + attachID := ctx.ParamsInt64(":attachment") + attach, err := models.GetAttachmentByID(attachID) + if err != nil { + ctx.Error(500, "GetAttachmentByID", err) + return + } + if attach.ReleaseID != releaseID { + ctx.Status(404) + return + } + // FIXME Should prove the existence of the given repo, but results in unnecessary database requests + + if err := models.DeleteAttachment(attach, true); err != nil { + ctx.Error(500, "DeleteAttachment", err) + return + } + ctx.Status(204) +} diff --git a/routers/api/v1/swagger/options.go b/routers/api/v1/swagger/options.go index 31251eb3e2e40..3ea324186d728 100644 --- a/routers/api/v1/swagger/options.go +++ b/routers/api/v1/swagger/options.go @@ -63,4 +63,6 @@ type swaggerParameterBodies struct { EditUserOption api.EditUserOption MigrateRepoForm auth.MigrateRepoForm + + EditAttachmentOptions api.EditAttachmentOptions } diff --git a/vendor/code.gitea.io/sdk/gitea/attachment.go b/vendor/code.gitea.io/sdk/gitea/attachment.go index 78bb5d1a0b616..f55c6691c26e3 100644 --- a/vendor/code.gitea.io/sdk/gitea/attachment.go +++ b/vendor/code.gitea.io/sdk/gitea/attachment.go @@ -4,7 +4,12 @@ package gitea // import "code.gitea.io/sdk/gitea" import ( + "bytes" + "encoding/json" "fmt" + "io/ioutil" + "mime/multipart" + "os" "time" ) @@ -38,3 +43,60 @@ func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64 nil, nil, &a) return a, err } + +// CreateReleaseAttachment creates an attachment for the given release +func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file *os.File) (*Attachment, error) { + // Read file to upload + fileContents, err := ioutil.ReadAll(file) + if err != nil { + return nil, err + } + + fi, err := file.Stat() + if err != nil { + return nil, err + } + file.Close() + + // Write file to body + body := new(bytes.Buffer) + writer := multipart.NewWriter(body) + part, err := writer.CreateFormFile("attachment", fi.Name()) + if err != nil { + return nil, err + } + part.Write(fileContents) + err = writer.Close() + if err != nil { + return nil, err + } + + // Send request + attachment := new(Attachment) + err = c.getParsedResponse("POST", + fmt.Sprintf("/repos/%s/%s/releases/%d/attachments", user, repo, release), + nil, body, &attachment) + return attachment, err +} + +// EditReleaseAttachment updates the given attachment with the given options +func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, error) { + body, err := json.Marshal(&form) + if err != nil { + return nil, err + } + attach := new(Attachment) + return attach, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach) +} + +// DeleteReleaseAttachment deletes the given attachment including the uploaded file +func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, id), nil, nil) + return err +} + +// EditAttachmentOptions options for editing attachments +// swagger:model +type EditAttachmentOptions struct { + Name string `json:"name"` +} diff --git a/vendor/vendor.json b/vendor/vendor.json index bbe56b180eae2..458893fe7ef5a 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,11 +9,11 @@ "revisionTime": "2018-01-14T14:37:32Z" }, { - "checksumSHA1": "97LRDvbujBg4j0wYP/WdBjxu8TA=", + "checksumSHA1": "cH90P/fAXmY0jNh71p0HNjY2JkA=", "origin": "github.com/JonasFranzDEV/go-sdk/gitea", "path": "code.gitea.io/sdk/gitea", - "revision": "719ad42a282dc680daa91c9b9ac3c12baba0dc03", - "revisionTime": "2018-02-08T21:56:41Z" + "revision": "1c6256217cf1adc88399753202784a7b35c04015", + "revisionTime": "2018-02-09T11:17:55Z" }, { "checksumSHA1": "bOODD4Gbw3GfcuQPU2dI40crxxk=", From ca954a7c168b7117227f1b458ae276b14ae8fab0 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 9 Feb 2018 13:38:42 +0100 Subject: [PATCH 08/18] Add filename query parameter for choosing another name for an attachment Signed-off-by: Jonas Franz --- public/swagger.v1.json | 6 ++++++ routers/api/v1/repo/release_attachment.go | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/public/swagger.v1.json b/public/swagger.v1.json index 0c21d9978dbd1..ae57ab29c65a9 100644 --- a/public/swagger.v1.json +++ b/public/swagger.v1.json @@ -3493,6 +3493,12 @@ "in": "path", "required": true }, + { + "type": "string", + "description": "name of the attachment", + "name": "name", + "in": "query" + }, { "type": "file", "description": "attachment to upload", diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index 8ef8c1fa46ece..d65778b680916 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -128,6 +128,11 @@ func CreateReleaseAttachment(ctx *context.APIContext) { // description: id of the release // type: integer // required: true + // - name: name + // in: query + // description: name of the attachment + // type: string + // required: false // - name: attachment // in: formData // description: attachment to upload @@ -183,8 +188,13 @@ func CreateReleaseAttachment(ctx *context.APIContext) { return } + var filename = header.Filename + if query := ctx.Query("name"); query != "" { + filename = query + } + // Create a new attachment and save the file - attach, err := models.NewAttachment(header.Filename, buf, file) + attach, err := models.NewAttachment(filename, buf, file) if err != nil { ctx.Error(500, "NewAttachment", err) return From 151f59481ada22ac06cf9ed44cb2122e59c68b6e Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sat, 10 Feb 2018 12:53:46 +0100 Subject: [PATCH 09/18] Fix order of imports Signed-off-by: Jonas Franz --- models/attachment.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index 36a362c8b74be..b8ccc5e567afb 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -11,11 +11,11 @@ import ( "os" "path" - gouuid "github.com/satori/go.uuid" - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" api "code.gitea.io/sdk/gitea" + + gouuid "github.com/satori/go.uuid" "github.com/go-xorm/xorm" ) From 030d4e8f1e6194ee1413eaab2335904064dd3aec Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sat, 10 Feb 2018 13:35:25 +0100 Subject: [PATCH 10/18] Restricting updatable attachment columns Signed-off-by: Jonas Franz --- models/attachment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/attachment.go b/models/attachment.go index b8ccc5e567afb..6664c740c958b 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -240,6 +240,6 @@ func updateAttachment(e Engine, atta *Attachment) error { // Use uuid only if id is not set and uuid is set sess = e.Where("uuid = ?", atta.UUID) } - _, err := sess.AllCols().Update(atta) + _, err := sess.Cols("name", "issue_id", "release_id", "comment_id", "download_count").Update(atta) return err } From da162ad446c66cfc6c15030fe761603e2f6b3847 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sat, 10 Feb 2018 14:48:55 +0100 Subject: [PATCH 11/18] gofmt Signed-off-by: Jonas Franz --- models/attachment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/attachment.go b/models/attachment.go index 6664c740c958b..dbe8ff2e8f4ca 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -15,8 +15,8 @@ import ( "code.gitea.io/gitea/modules/util" api "code.gitea.io/sdk/gitea" - gouuid "github.com/satori/go.uuid" "github.com/go-xorm/xorm" + gouuid "github.com/satori/go.uuid" ) // Attachment represent a attachment of issue/comment/release. From 322c7a67ee4f3b0b091118f5f60a041b071b7136 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Tue, 27 Feb 2018 19:13:03 +0100 Subject: [PATCH 12/18] Update go-sdk Replace Attachments with Assets Signed-off-by: Jonas Franz --- routers/api/v1/api.go | 4 ++-- routers/api/v1/repo/release_attachment.go | 12 ++++++------ vendor/vendor.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index def0dd5e69128..4c454cb6a0eca 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -473,10 +473,10 @@ func RegisterRoutes(m *macaron.Macaron) { m.Combo("").Get(repo.GetRelease). Patch(reqToken(), reqRepoWriter(), context.ReferencesGitRepo(), bind(api.EditReleaseOption{}), repo.EditRelease). Delete(reqToken(), reqRepoWriter(), repo.DeleteRelease) - m.Group("/attachments", func() { + m.Group("/assets", func() { m.Combo("").Get(repo.ListReleaseAttachments). Post(reqToken(), reqRepoWriter(), repo.CreateReleaseAttachment) - m.Combo("/:attachment").Get(repo.GetReleaseAttachment). + m.Combo("/:asset").Get(repo.GetReleaseAttachment). Patch(reqToken(), reqRepoWriter(), bind(api.EditAttachmentOptions{}), repo.EditReleaseAttachment). Delete(reqToken(), reqRepoWriter(), repo.DeleteReleaseAttachment) }) diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index d65778b680916..80b2064df0e90 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -16,7 +16,7 @@ import ( // GetReleaseAttachment gets a single attachment of the release func GetReleaseAttachment(ctx *context.APIContext) { - // swagger:operation GET /repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id} repository repoGetReleaseAttachment + // swagger:operation GET /repos/{owner}/{repo}/releases/{id}/assets/{attachment_id} repository repoGetReleaseAttachment // --- // summary: Get a release attachment // produces: @@ -46,7 +46,7 @@ func GetReleaseAttachment(ctx *context.APIContext) { // "200": // "$ref": "#/responses/Attachment" releaseID := ctx.ParamsInt64(":id") - attachID := ctx.ParamsInt64(":attachment") + attachID := ctx.ParamsInt64(":asset") attach, err := models.GetAttachmentByID(attachID) if err != nil { ctx.Error(500, "GetAttachmentByID", err) @@ -62,7 +62,7 @@ func GetReleaseAttachment(ctx *context.APIContext) { // ListReleaseAttachments lists all attachments of the release func ListReleaseAttachments(ctx *context.APIContext) { - // swagger:operation GET /repos/{owner}/{repo}/releases/{id}/attachments repository repoListReleaseAttachments + // swagger:operation GET /repos/{owner}/{repo}/releases/{id}/assets repository repoListReleaseAttachments // --- // summary: List release's attachments // produces: @@ -105,7 +105,7 @@ func ListReleaseAttachments(ctx *context.APIContext) { // CreateReleaseAttachment creates an attachment and saves the given file func CreateReleaseAttachment(ctx *context.APIContext) { - // swagger:operation POST /repos/{owner}/{repo}/releases/{id}/attachments repository repoCreateReleaseAttachment + // swagger:operation POST /repos/{owner}/{repo}/releases/{id}/assets repository repoCreateReleaseAttachment // --- // summary: Create a release attachment // produces: @@ -209,7 +209,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) { // EditReleaseAttachment updates the given attachment func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptions) { - // swagger:operation PATCH /repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id} repository repoEditReleaseAttachment + // swagger:operation PATCH /repos/{owner}/{repo}/releases/{id}/assets/{attachment_id} repository repoEditReleaseAttachment // --- // summary: Edit a release attachment // produces: @@ -270,7 +270,7 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio // DeleteReleaseAttachment delete a given attachment func DeleteReleaseAttachment(ctx *context.APIContext) { - // swagger:operation DELETE /repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id} repository repoDeleteReleaseAttachment + // swagger:operation DELETE /repos/{owner}/{repo}/releases/{id}/assets/{attachment_id} repository repoDeleteReleaseAttachment // --- // summary: Delete a release attachment // produces: diff --git a/vendor/vendor.json b/vendor/vendor.json index f55a4902bd505..3b8ea35fd5f0f 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,7 +9,7 @@ "revisionTime": "2018-02-10T03:05:43Z" }, { - "checksumSHA1": "cH90P/fAXmY0jNh71p0HNjY2JkA=", + "checksumSHA1": "PcMtfbiMdyJQ479ti+n47mXjTuA=", "origin": "github.com/JonasFranzDEV/go-sdk/gitea", "path": "code.gitea.io/sdk/gitea", "revision": "1c6256217cf1adc88399753202784a7b35c04015", From 96acb4ececce4fe18f21db9805ea8d096ef711e6 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Tue, 27 Feb 2018 19:17:40 +0100 Subject: [PATCH 13/18] Update go-sdk Signed-off-by: Jonas Franz --- vendor/code.gitea.io/sdk/gitea/attachment.go | 39 ++++++++------------ vendor/code.gitea.io/sdk/gitea/release.go | 2 +- vendor/vendor.json | 6 +-- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/vendor/code.gitea.io/sdk/gitea/attachment.go b/vendor/code.gitea.io/sdk/gitea/attachment.go index f55c6691c26e3..b48bcee47a93e 100644 --- a/vendor/code.gitea.io/sdk/gitea/attachment.go +++ b/vendor/code.gitea.io/sdk/gitea/attachment.go @@ -7,9 +7,10 @@ import ( "bytes" "encoding/json" "fmt" + "io" "io/ioutil" "mime/multipart" - "os" + "net/http" "time" ) @@ -30,7 +31,7 @@ type Attachment struct { func (c *Client) ListReleaseAttachments(user, repo string, release int64) ([]*Attachment, error) { attachments := make([]*Attachment, 0, 10) err := c.getParsedResponse("GET", - fmt.Sprintf("/repos/%s/%s/releases/%d/attachments", user, repo, release), + fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release), nil, nil, &attachments) return attachments, err } @@ -39,43 +40,33 @@ func (c *Client) ListReleaseAttachments(user, repo string, release int64) ([]*At func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, error) { a := new(Attachment) err := c.getParsedResponse("GET", - fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, id), + fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil, &a) return a, err } // CreateReleaseAttachment creates an attachment for the given release -func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file *os.File) (*Attachment, error) { - // Read file to upload - fileContents, err := ioutil.ReadAll(file) - if err != nil { - return nil, err - } - - fi, err := file.Stat() - if err != nil { - return nil, err - } - file.Close() - +func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file *io.Reader, filename string) (*Attachment, error) { // Write file to body body := new(bytes.Buffer) writer := multipart.NewWriter(body) - part, err := writer.CreateFormFile("attachment", fi.Name()) + part, err := writer.CreateFormFile("attachment", filename) if err != nil { return nil, err } - part.Write(fileContents) - err = writer.Close() - if err != nil { + + if _, err = io.Copy(part, file); err != nil { + return nil, err + } + if err = writer.Close(); err != nil { return nil, err } // Send request attachment := new(Attachment) err = c.getParsedResponse("POST", - fmt.Sprintf("/repos/%s/%s/releases/%d/attachments", user, repo, release), - nil, body, &attachment) + fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release), + http.Header{"Content-Type": {writer.FormDataContentType()}}, body, &attachment) return attachment, err } @@ -86,12 +77,12 @@ func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachm return nil, err } attach := new(Attachment) - return attach, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach) + return attach, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach) } // DeleteReleaseAttachment deletes the given attachment including the uploaded file func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, id), nil, nil) + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil) return err } diff --git a/vendor/code.gitea.io/sdk/gitea/release.go b/vendor/code.gitea.io/sdk/gitea/release.go index e2aea693c5a3c..396251dcac9d8 100644 --- a/vendor/code.gitea.io/sdk/gitea/release.go +++ b/vendor/code.gitea.io/sdk/gitea/release.go @@ -28,7 +28,7 @@ type Release struct { // swagger:strfmt date-time PublishedAt time.Time `json:"published_at"` Publisher *User `json:"author"` - Attachments []*Attachment `json:"attachments"` + Attachments []*Attachment `json:"assets"` } // ListReleases list releases of a repository diff --git a/vendor/vendor.json b/vendor/vendor.json index 3b8ea35fd5f0f..44bb44b92679a 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,11 +9,11 @@ "revisionTime": "2018-02-10T03:05:43Z" }, { - "checksumSHA1": "PcMtfbiMdyJQ479ti+n47mXjTuA=", + "checksumSHA1": "13TTOFBvqxx4vX4h5uwWOm+He0M=", "origin": "github.com/JonasFranzDEV/go-sdk/gitea", "path": "code.gitea.io/sdk/gitea", - "revision": "1c6256217cf1adc88399753202784a7b35c04015", - "revisionTime": "2018-02-09T11:17:55Z" + "revision": "eeb85eb01b2f661f9e4efe01165d17fc89d76f12", + "revisionTime": "2018-02-27T18:04:45Z" }, { "checksumSHA1": "bOODD4Gbw3GfcuQPU2dI40crxxk=", From e5c1b820d2c6c6791d47be2532b2899c3d5d654d Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 2 Mar 2018 11:29:43 +0100 Subject: [PATCH 14/18] Updating go-sdk and regenerating swagger Signed-off-by: Jonas Franz --- public/swagger.v1.json | 15 ++++-- vendor/code.gitea.io/sdk/gitea/attachment.go | 40 ++++++---------- vendor/code.gitea.io/sdk/gitea/release.go | 2 +- vendor/vendor.json | 50 ++++++++++++++++++-- 4 files changed, 74 insertions(+), 33 deletions(-) diff --git a/public/swagger.v1.json b/public/swagger.v1.json index ae57ab29c65a9..d4e27449178ee 100644 --- a/public/swagger.v1.json +++ b/public/swagger.v1.json @@ -5575,7 +5575,8 @@ "properties": { "color": { "type": "string", - "x-go-name": "Color" + "x-go-name": "Color", + "example": "#00aabb" }, "name": { "type": "string", @@ -5995,6 +5996,8 @@ "x-go-name": "Description" }, "due_on": { + "type": "string", + "format": "date-time", "x-go-name": "Deadline" }, "state": { @@ -6372,9 +6375,9 @@ "type": "object", "properties": { "color": { - "description": "example: 00aabb", "type": "string", - "x-go-name": "Color" + "x-go-name": "Color", + "example": "00aabb" }, "id": { "type": "integer", @@ -6810,6 +6813,8 @@ "x-go-name": "HasMerged" }, "merged_at": { + "type": "string", + "format": "date-time", "x-go-name": "Merged" } }, @@ -6819,7 +6824,7 @@ "description": "Release represents a repository release", "type": "object", "properties": { - "attachments": { + "assets": { "type": "array", "items": { "$ref": "#/definitions/Attachment" @@ -7172,6 +7177,8 @@ "type": "object", "properties": { "created_at": { + "type": "string", + "format": "date-time", "x-go-name": "CreatedAt" }, "ignored": { diff --git a/vendor/code.gitea.io/sdk/gitea/attachment.go b/vendor/code.gitea.io/sdk/gitea/attachment.go index f55c6691c26e3..ec40fadbfc6db 100644 --- a/vendor/code.gitea.io/sdk/gitea/attachment.go +++ b/vendor/code.gitea.io/sdk/gitea/attachment.go @@ -7,9 +7,9 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "mime/multipart" - "os" + "net/http" "time" ) @@ -30,7 +30,7 @@ type Attachment struct { func (c *Client) ListReleaseAttachments(user, repo string, release int64) ([]*Attachment, error) { attachments := make([]*Attachment, 0, 10) err := c.getParsedResponse("GET", - fmt.Sprintf("/repos/%s/%s/releases/%d/attachments", user, repo, release), + fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release), nil, nil, &attachments) return attachments, err } @@ -39,43 +39,33 @@ func (c *Client) ListReleaseAttachments(user, repo string, release int64) ([]*At func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, error) { a := new(Attachment) err := c.getParsedResponse("GET", - fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, id), + fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil, &a) return a, err } // CreateReleaseAttachment creates an attachment for the given release -func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file *os.File) (*Attachment, error) { - // Read file to upload - fileContents, err := ioutil.ReadAll(file) - if err != nil { - return nil, err - } - - fi, err := file.Stat() - if err != nil { - return nil, err - } - file.Close() - +func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file *io.Reader, filename string) (*Attachment, error) { // Write file to body body := new(bytes.Buffer) writer := multipart.NewWriter(body) - part, err := writer.CreateFormFile("attachment", fi.Name()) + part, err := writer.CreateFormFile("attachment", filename) if err != nil { return nil, err } - part.Write(fileContents) - err = writer.Close() - if err != nil { + + if _, err = io.Copy(part, *file); err != nil { + return nil, err + } + if err = writer.Close(); err != nil { return nil, err } // Send request attachment := new(Attachment) err = c.getParsedResponse("POST", - fmt.Sprintf("/repos/%s/%s/releases/%d/attachments", user, repo, release), - nil, body, &attachment) + fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release), + http.Header{"Content-Type": {writer.FormDataContentType()}}, body, &attachment) return attachment, err } @@ -86,12 +76,12 @@ func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachm return nil, err } attach := new(Attachment) - return attach, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach) + return attach, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach) } // DeleteReleaseAttachment deletes the given attachment including the uploaded file func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/attachments/%d", user, repo, release, id), nil, nil) + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil) return err } diff --git a/vendor/code.gitea.io/sdk/gitea/release.go b/vendor/code.gitea.io/sdk/gitea/release.go index e2aea693c5a3c..396251dcac9d8 100644 --- a/vendor/code.gitea.io/sdk/gitea/release.go +++ b/vendor/code.gitea.io/sdk/gitea/release.go @@ -28,7 +28,7 @@ type Release struct { // swagger:strfmt date-time PublishedAt time.Time `json:"published_at"` Publisher *User `json:"author"` - Attachments []*Attachment `json:"attachments"` + Attachments []*Attachment `json:"assets"` } // ListReleases list releases of a repository diff --git a/vendor/vendor.json b/vendor/vendor.json index 458893fe7ef5a..c18a3808a175e 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -2,6 +2,10 @@ "comment": "", "ignore": "test appengine", "package": [ + { + "path": "bytes", + "revision": "" + }, { "checksumSHA1": "Gz+a5Qo4PCiB/Gf2f02v8HEAxDM=", "path": "code.gitea.io/git", @@ -9,11 +13,27 @@ "revisionTime": "2018-01-14T14:37:32Z" }, { - "checksumSHA1": "cH90P/fAXmY0jNh71p0HNjY2JkA=", + "checksumSHA1": "41bFXnkZIiehow1sWC+sYy5qXIk=", "origin": "github.com/JonasFranzDEV/go-sdk/gitea", "path": "code.gitea.io/sdk/gitea", - "revision": "1c6256217cf1adc88399753202784a7b35c04015", - "revisionTime": "2018-02-09T11:17:55Z" + "revision": "cb7d4c0d9b9fe04555c1e99e0424dfed2c538c5b", + "revisionTime": "2018-03-02T10:25:38Z" + }, + { + "path": "encoding/base64", + "revision": "" + }, + { + "path": "encoding/json", + "revision": "" + }, + { + "path": "errors", + "revision": "" + }, + { + "path": "fmt", + "revision": "" }, { "checksumSHA1": "bOODD4Gbw3GfcuQPU2dI40crxxk=", @@ -1544,11 +1564,35 @@ "revision": "a5b47d31c556af34a302ce5d659e6fea44d90de0", "revisionTime": "2016-09-28T15:37:09Z" }, + { + "path": "io", + "revision": "" + }, + { + "path": "io/ioutil", + "revision": "" + }, + { + "path": "mime/multipart", + "revision": "" + }, + { + "path": "net/http", + "revision": "" + }, + { + "path": "strings", + "revision": "" + }, { "checksumSHA1": "JQBqnAXO83ic7bwer/MwurhQMtg=", "path": "strk.kbt.io/projects/go/libravatar", "revision": "5eed7bff870ae19ef51c5773dbc8f3e9fcbd0982", "revisionTime": "2016-06-28T05:56:50Z" + }, + { + "path": "time", + "revision": "" } ], "rootPath": "code.gitea.io/gitea" From 08c778d3f96f9303452abe0ad3995ad0e497f3f4 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 2 Mar 2018 11:40:14 +0100 Subject: [PATCH 15/18] Add missing file of go-sdk Signed-off-by: Jonas Franz --- vendor/code.gitea.io/sdk/gitea/user_search.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 vendor/code.gitea.io/sdk/gitea/user_search.go diff --git a/vendor/code.gitea.io/sdk/gitea/user_search.go b/vendor/code.gitea.io/sdk/gitea/user_search.go new file mode 100644 index 0000000000000..65ab980d66f86 --- /dev/null +++ b/vendor/code.gitea.io/sdk/gitea/user_search.go @@ -0,0 +1,14 @@ +package gitea + +import "fmt" + +type searchUsersResponse struct { + Users []*User `json:"data"` +} + +// SearchUsers finds users by query +func (c *Client) SearchUsers(query string, limit int) ([]*User, error) { + resp := new(searchUsersResponse) + err := c.getParsedResponse("GET", fmt.Sprintf("/users/search?q=%s&limit=%d", query, limit), nil, nil, &resp) + return resp.Users, err +} From 73b705e648d82f5a0084fedb5e70cd153e20b9c4 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 2 Mar 2018 20:39:19 +0100 Subject: [PATCH 16/18] Change origin of code.gitea.io/sdk to code.gitea.io/sdk Update code.gitea.io/sdk Signed-off-by: Jonas Franz --- vendor/code.gitea.io/sdk/gitea/attachment.go | 4 ++-- vendor/vendor.json | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/vendor/code.gitea.io/sdk/gitea/attachment.go b/vendor/code.gitea.io/sdk/gitea/attachment.go index ec40fadbfc6db..e90a7114d9a48 100644 --- a/vendor/code.gitea.io/sdk/gitea/attachment.go +++ b/vendor/code.gitea.io/sdk/gitea/attachment.go @@ -45,7 +45,7 @@ func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64 } // CreateReleaseAttachment creates an attachment for the given release -func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file *io.Reader, filename string) (*Attachment, error) { +func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file io.Reader, filename string) (*Attachment, error) { // Write file to body body := new(bytes.Buffer) writer := multipart.NewWriter(body) @@ -54,7 +54,7 @@ func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file return nil, err } - if _, err = io.Copy(part, *file); err != nil { + if _, err = io.Copy(part, file); err != nil { return nil, err } if err = writer.Close(); err != nil { diff --git a/vendor/vendor.json b/vendor/vendor.json index f9e583bf37968..967a297b27adc 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,11 +9,10 @@ "revisionTime": "2018-02-10T03:05:43Z" }, { - "checksumSHA1": "41bFXnkZIiehow1sWC+sYy5qXIk=", - "origin": "github.com/JonasFranzDEV/go-sdk/gitea", + "checksumSHA1": "PWaIU7g1YSkETxka2DIS1EYsPK0=", "path": "code.gitea.io/sdk/gitea", - "revision": "cb7d4c0d9b9fe04555c1e99e0424dfed2c538c5b", - "revisionTime": "2018-03-02T10:25:38Z" + "revision": "cdbef997666132599cc92dc22aa94de3db04adeb", + "revisionTime": "2018-03-02T14:48:43Z" }, { "checksumSHA1": "bOODD4Gbw3GfcuQPU2dI40crxxk=", From e3173508facdc40ffa07e95235eebeb0cc11267c Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sun, 4 Mar 2018 16:50:40 +0100 Subject: [PATCH 17/18] Update swagger Signed-off-by: Jonas Franz --- public/swagger.v1.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/swagger.v1.json b/public/swagger.v1.json index d4e27449178ee..ad1b91ad812fd 100644 --- a/public/swagger.v1.json +++ b/public/swagger.v1.json @@ -3420,7 +3420,7 @@ } } }, - "/repos/{owner}/{repo}/releases/{id}/attachments": { + "/repos/{owner}/{repo}/releases/{id}/assets": { "get": { "produces": [ "application/json" @@ -3514,7 +3514,7 @@ } } }, - "/repos/{owner}/{repo}/releases/{id}/attachments/{attachment_id}": { + "/repos/{owner}/{repo}/releases/{id}/assets/{attachment_id}": { "get": { "produces": [ "application/json" From 7a6c7dd5bab38acaa724bad11fc2f5dda0d2c81a Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Mon, 5 Mar 2018 09:19:34 +0100 Subject: [PATCH 18/18] Update updateAttachment --- models/attachment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/attachment.go b/models/attachment.go index dbe8ff2e8f4ca..ffe2eea80c85a 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -234,7 +234,7 @@ func UpdateAttachment(atta *Attachment) error { func updateAttachment(e Engine, atta *Attachment) error { var sess *xorm.Session - if atta.ID != 0 || atta.UUID == "" { + if atta.ID != 0 && atta.UUID == "" { sess = e.ID(atta.ID) } else { // Use uuid only if id is not set and uuid is set