From edb92025df7803b66107513ceb1928e64726db02 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 11 Jul 2023 18:51:03 +0200 Subject: [PATCH] Correct api docs of PostRepo & GetRepos (#1974) ... and report if needed forge_remote_id is not valid --- cmd/server/docs/docs.go | 76 +++++++++++++++++++++++------------------ server/api/repo.go | 11 ++++-- server/api/user.go | 1 + 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index d486837f9..39e52e0b1 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1192,6 +1192,42 @@ const docTemplate = `{ } } }, + "/repos": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "Repositories" + ], + "summary": "Activate a repository", + "parameters": [ + { + "type": "string", + "default": "Bearer \u003cpersonal access token\u003e", + "description": "Insert your personal access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "the id of a repository at the forge", + "name": "forge_remote_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Repo" + } + } + } + } + }, "/repos/lookup/{repo_full_name}": { "get": { "produces": [ @@ -1263,40 +1299,6 @@ const docTemplate = `{ } } }, - "post": { - "produces": [ - "application/json" - ], - "tags": [ - "Repositories" - ], - "summary": "Activate a repository", - "parameters": [ - { - "type": "string", - "default": "Bearer \u003cpersonal access token\u003e", - "description": "Insert your personal access token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "the repository id", - "name": "repo_id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/Repo" - } - } - } - }, "delete": { "produces": [ "application/json" @@ -3116,6 +3118,12 @@ const docTemplate = `{ "name": "Authorization", "in": "header", "required": true + }, + { + "type": "boolean", + "description": "query not activated repos from forge too", + "name": "all", + "in": "query" } ], "responses": { diff --git a/server/api/repo.go b/server/api/repo.go index b78bdb4b6..a65e1877c 100644 --- a/server/api/repo.go +++ b/server/api/repo.go @@ -39,18 +39,23 @@ import ( // PostRepo // // @Summary Activate a repository -// @Router /repos/{repo_id} [post] +// @Router /repos [post] // @Produce json // @Success 200 {object} Repo // @Tags Repositories -// @Param Authorization header string true "Insert your personal access token" default(Bearer ) -// @Param repo_id path int true "the repository id" +// @Param Authorization header string true "Insert your personal access token" default(Bearer ) +// @Param forge_remote_id query string true "the id of a repository at the forge" func PostRepo(c *gin.Context) { forge := server.Config.Services.Forge _store := store.FromContext(c) user := session.User(c) forgeRemoteID := model.ForgeRemoteID(c.Query("forge_remote_id")) + if !forgeRemoteID.IsValid() { + c.String(http.StatusBadRequest, "No forge_remote_id provided") + return + } + repo, err := _store.GetRepoForgeID(forgeRemoteID) enabledOnce := err == nil // if there's no error, the repo was found and enabled once already if enabledOnce && repo.IsActive { diff --git a/server/api/user.go b/server/api/user.go index 1c3e8c89c..fa6263c0e 100644 --- a/server/api/user.go +++ b/server/api/user.go @@ -82,6 +82,7 @@ func GetFeed(c *gin.Context) { // @Success 200 {array} Repo // @Tags User // @Param Authorization header string true "Insert your personal access token" default(Bearer ) +// @Param all query bool false "query not activated repos from forge too" func GetRepos(c *gin.Context) { _store := store.FromContext(c) _forge := server.Config.Services.Forge