Skip to content

Commit 876bafb

Browse files
ethantkoeniglunny
authored andcommitted
Fix API status code for hook creation (#2814)
* Fix API status code for hook creation * Named constants for response statuses
1 parent 061f65f commit 876bafb

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

public/swagger.v1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@
15271527
}
15281528
],
15291529
"responses": {
1530-
"200": {
1530+
"201": {
15311531
"$ref": "#/responses/Hook"
15321532
}
15331533
}

routers/api/v1/repo/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
107107
// schema:
108108
// "$ref": "#/definitions/CreateHookOption"
109109
// responses:
110-
// "200":
110+
// "201":
111111
// "$ref": "#/responses/Hook"
112112
if !utils.CheckCreateHookOption(ctx, &form) {
113113
return

routers/api/v1/utils/hook.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/routers/api/v1/convert"
1313
"encoding/json"
1414
"github.com/Unknwon/com"
15+
"net/http"
1516
)
1617

1718
// 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) {
6970
org := ctx.Org.Organization
7071
hook, ok := addHook(ctx, form, org.ID, 0)
7172
if ok {
72-
ctx.JSON(200, convert.ToHook(org.HomeLink(), hook))
73+
ctx.JSON(http.StatusCreated, convert.ToHook(org.HomeLink(), hook))
7374
}
7475
}
7576

@@ -78,7 +79,7 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) {
7879
repo := ctx.Repo
7980
hook, ok := addHook(ctx, form, 0, repo.Repository.ID)
8081
if ok {
81-
ctx.JSON(200, convert.ToHook(repo.RepoLink, hook))
82+
ctx.JSON(http.StatusCreated, convert.ToHook(repo.RepoLink, hook))
8283
}
8384
}
8485

0 commit comments

Comments
 (0)