Correct api docs of PostRepo & GetRepos (#1974)

... and report if needed forge_remote_id is not valid
This commit is contained in:
6543 2023-07-11 18:51:03 +02:00 committed by GitHub
parent e85eeb10fc
commit edb92025df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 37 deletions

View file

@ -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}": { "/repos/lookup/{repo_full_name}": {
"get": { "get": {
"produces": [ "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": { "delete": {
"produces": [ "produces": [
"application/json" "application/json"
@ -3116,6 +3118,12 @@ const docTemplate = `{
"name": "Authorization", "name": "Authorization",
"in": "header", "in": "header",
"required": true "required": true
},
{
"type": "boolean",
"description": "query not activated repos from forge too",
"name": "all",
"in": "query"
} }
], ],
"responses": { "responses": {

View file

@ -39,18 +39,23 @@ import (
// PostRepo // PostRepo
// //
// @Summary Activate a repository // @Summary Activate a repository
// @Router /repos/{repo_id} [post] // @Router /repos [post]
// @Produce json // @Produce json
// @Success 200 {object} Repo // @Success 200 {object} Repo
// @Tags Repositories // @Tags Repositories
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>) // @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param repo_id path int true "the repository id" // @Param forge_remote_id query string true "the id of a repository at the forge"
func PostRepo(c *gin.Context) { func PostRepo(c *gin.Context) {
forge := server.Config.Services.Forge forge := server.Config.Services.Forge
_store := store.FromContext(c) _store := store.FromContext(c)
user := session.User(c) user := session.User(c)
forgeRemoteID := model.ForgeRemoteID(c.Query("forge_remote_id")) 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) repo, err := _store.GetRepoForgeID(forgeRemoteID)
enabledOnce := err == nil // if there's no error, the repo was found and enabled once already enabledOnce := err == nil // if there's no error, the repo was found and enabled once already
if enabledOnce && repo.IsActive { if enabledOnce && repo.IsActive {

View file

@ -82,6 +82,7 @@ func GetFeed(c *gin.Context) {
// @Success 200 {array} Repo // @Success 200 {array} Repo
// @Tags User // @Tags User
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>) // @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param all query bool false "query not activated repos from forge too"
func GetRepos(c *gin.Context) { func GetRepos(c *gin.Context) {
_store := store.FromContext(c) _store := store.FromContext(c)
_forge := server.Config.Services.Forge _forge := server.Config.Services.Forge