Fix API status code for hook creation (#2814)

* Fix API status code for hook creation

* Named constants for response statuses
tokarchuk/v1.17
Ethan Koenig 7 years ago committed by Lunny Xiao
parent 061f65ff29
commit 876bafb7ef
  1. 2
      public/swagger.v1.json
  2. 2
      routers/api/v1/repo/hook.go
  3. 5
      routers/api/v1/utils/hook.go

@ -1527,7 +1527,7 @@
} }
], ],
"responses": { "responses": {
"200": { "201": {
"$ref": "#/responses/Hook" "$ref": "#/responses/Hook"
} }
} }

@ -107,7 +107,7 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
// schema: // schema:
// "$ref": "#/definitions/CreateHookOption" // "$ref": "#/definitions/CreateHookOption"
// responses: // responses:
// "200": // "201":
// "$ref": "#/responses/Hook" // "$ref": "#/responses/Hook"
if !utils.CheckCreateHookOption(ctx, &form) { if !utils.CheckCreateHookOption(ctx, &form) {
return return

@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/convert" "code.gitea.io/gitea/routers/api/v1/convert"
"encoding/json" "encoding/json"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"net/http"
) )
// GetOrgHook get an organization's webhook. If there is an error, write to // GetOrgHook get an organization's webhook. If there is an error, write to
@ -69,7 +70,7 @@ func AddOrgHook(ctx *context.APIContext, form *api.CreateHookOption) {
org := ctx.Org.Organization org := ctx.Org.Organization
hook, ok := addHook(ctx, form, org.ID, 0) hook, ok := addHook(ctx, form, org.ID, 0)
if ok { if ok {
ctx.JSON(200, convert.ToHook(org.HomeLink(), hook)) ctx.JSON(http.StatusCreated, convert.ToHook(org.HomeLink(), hook))
} }
} }
@ -78,7 +79,7 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) {
repo := ctx.Repo repo := ctx.Repo
hook, ok := addHook(ctx, form, 0, repo.Repository.ID) hook, ok := addHook(ctx, form, 0, repo.Repository.ID)
if ok { if ok {
ctx.JSON(200, convert.ToHook(repo.RepoLink, hook)) ctx.JSON(http.StatusCreated, convert.ToHook(repo.RepoLink, hook))
} }
} }

Loading…
Cancel
Save