From 96d41287e5f4b9932ca38b404779a08a23eae266 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 18 Dec 2020 13:38:47 +0000 Subject: [PATCH] [API] GetCombinedCommitStatusByRef always return json & swagger doc fixes (#14047) * Fix swagger docs * always return json --- routers/api/v1/repo/status.go | 6 +- routers/api/v1/swagger/repo.go | 7 ++ templates/swagger/v1_json.tmpl | 128 ++++++++++++++++++++++++++++++++- 3 files changed, 136 insertions(+), 5 deletions(-) diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index 69661dca917..22e78d060c8 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -244,7 +244,7 @@ type combinedCommitStatus struct { // GetCombinedCommitStatusByRef returns the combined status for any given commit hash func GetCombinedCommitStatusByRef(ctx *context.APIContext) { - // swagger:operation GET /repos/{owner}/{repo}/commits/{ref}/statuses repository repoGetCombinedStatusByRef + // swagger:operation GET /repos/{owner}/{repo}/commits/{ref}/status repository repoGetCombinedStatusByRef // --- // summary: Get a commit's combined status, by branch/tag/commit reference // produces: @@ -272,7 +272,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { // required: false // responses: // "200": - // "$ref": "#/responses/Status" + // "$ref": "#/responses/CombinedStatus" // "400": // "$ref": "#/responses/error" @@ -292,7 +292,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { } if len(statuses) == 0 { - ctx.Status(http.StatusOK) + ctx.JSON(http.StatusOK, &api.CombinedStatus{}) return } diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index bce9e45c379..76c9ac608b3 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -309,3 +309,10 @@ type swaggerLanguageStatistics struct { // in: body Body map[string]int64 `json:"body"` } + +// CombinedStatus +// swagger:response CombinedStatus +type swaggerCombinedStatus struct { + // in: body + Body api.CombinedStatus `json:"body"` +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 96871b48c7e..10c9c24f893 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -2829,7 +2829,7 @@ } } }, - "/repos/{owner}/{repo}/commits/{ref}/statuses": { + "/repos/{owner}/{repo}/commits/{ref}/status": { "get": { "produces": [ "application/json" @@ -2870,7 +2870,88 @@ ], "responses": { "200": { - "$ref": "#/responses/Status" + "$ref": "#/responses/CombinedStatus" + }, + "400": { + "$ref": "#/responses/error" + } + } + } + }, + "/repos/{owner}/{repo}/commits/{ref}/statuses": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Get a commit's statuses, by branch/tag/commit reference", + "operationId": "repoListStatusesByRef", + "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": "string", + "description": "name of branch/tag/commit", + "name": "ref", + "in": "path", + "required": true + }, + { + "enum": [ + "oldest", + "recentupdate", + "leastupdate", + "leastindex", + "highestindex" + ], + "type": "string", + "description": "type of sort", + "name": "sort", + "in": "query" + }, + { + "enum": [ + "pending", + "success", + "error", + "failure", + "warning" + ], + "type": "string", + "description": "type of state", + "name": "state", + "in": "query" + }, + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/StatusList" }, "400": { "$ref": "#/responses/error" @@ -11240,6 +11321,43 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "CombinedStatus": { + "description": "CombinedStatus holds the combined state of several statuses for a single commit", + "type": "object", + "properties": { + "commit_url": { + "type": "string", + "x-go-name": "CommitURL" + }, + "repository": { + "$ref": "#/definitions/Repository" + }, + "sha": { + "type": "string", + "x-go-name": "SHA" + }, + "state": { + "$ref": "#/definitions/StatusState" + }, + "statuses": { + "type": "array", + "items": { + "$ref": "#/definitions/Status" + }, + "x-go-name": "Statuses" + }, + "total_count": { + "type": "integer", + "format": "int64", + "x-go-name": "TotalCount" + }, + "url": { + "type": "string", + "x-go-name": "URL" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "Comment": { "description": "Comment represents a comment on a commit or issue", "type": "object", @@ -15532,6 +15650,12 @@ } } }, + "CombinedStatus": { + "description": "CombinedStatus", + "schema": { + "$ref": "#/definitions/CombinedStatus" + } + }, "Comment": { "description": "Comment", "schema": {