diff options
author | JakobDev <jakobdev@gmx.de> | 2023-05-30 17:26:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-30 15:26:51 +0000 |
commit | 1b115296d3f2f396eebcb40d79aea814d282edaf (patch) | |
tree | 6cb848392a0ddd785d12b1fa5dd569015fe9d221 /routers/api | |
parent | faae819f5d8a662ec2df88205ab6d9b1871f1dd1 (diff) | |
download | gitea-1b115296d3f2f396eebcb40d79aea814d282edaf.tar.gz gitea-1b115296d3f2f396eebcb40d79aea814d282edaf.zip |
Followup to pinned Issues (#24945)
This addressees some things from #24406 that came up after the PR was
merged. Mostly from @delvh.
---------
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/repo/issue_pin.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/routers/api/v1/repo/issue_pin.go b/routers/api/v1/repo/issue_pin.go index c96ede45f5..1e774d4afa 100644 --- a/routers/api/v1/repo/issue_pin.go +++ b/routers/api/v1/repo/issue_pin.go @@ -45,6 +45,8 @@ func PinIssue(ctx *context.APIContext) { if err != nil { if issues_model.IsErrIssueNotExist(err) { ctx.NotFound() + } else if issues_model.IsErrIssueMaxPinReached(err) { + ctx.Error(http.StatusBadRequest, "MaxPinReached", err) } else { ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err) } @@ -55,11 +57,13 @@ func PinIssue(ctx *context.APIContext) { err = issue.LoadRepo(ctx) if err != nil { ctx.Error(http.StatusInternalServerError, "LoadRepo", err) + return } err = issue.Pin(ctx, ctx.Doer) if err != nil { ctx.Error(http.StatusInternalServerError, "PinIssue", err) + return } ctx.Status(http.StatusNoContent) @@ -108,11 +112,13 @@ func UnpinIssue(ctx *context.APIContext) { err = issue.LoadRepo(ctx) if err != nil { ctx.Error(http.StatusInternalServerError, "LoadRepo", err) + return } err = issue.Unpin(ctx, ctx.Doer) if err != nil { ctx.Error(http.StatusInternalServerError, "UnpinIssue", err) + return } ctx.Status(http.StatusNoContent) @@ -166,6 +172,7 @@ func MoveIssuePin(ctx *context.APIContext) { err = issue.MovePin(ctx, int(ctx.ParamsInt64(":position"))) if err != nil { ctx.Error(http.StatusInternalServerError, "MovePin", err) + return } ctx.Status(http.StatusNoContent) @@ -193,12 +200,12 @@ func ListPinnedIssues(ctx *context.APIContext) { // "200": // "$ref": "#/responses/IssueList" issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, false) - - if err == nil { - ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues)) - } else { + if err != nil { ctx.Error(http.StatusInternalServerError, "LoadPinnedIssues", err) + return } + + ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues)) } // ListPinnedPullRequests returns a list of all pinned PRs @@ -225,6 +232,7 @@ func ListPinnedPullRequests(ctx *context.APIContext) { issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, true) if err != nil { ctx.Error(http.StatusInternalServerError, "LoadPinnedPullRequests", err) + return } apiPrs := make([]*api.PullRequest, len(issues)) |