From f5a81f96362a873a4337b395de36d3bb9d91879c Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 17 Feb 2025 18:39:12 +0100 Subject: [PATCH 01/16] Run spellcheck on tools directory (#33627) Add `tools` files to spellcheck and fixed one issue. --- Makefile | 2 +- tools/lint-go-gopls.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 67a4e27efc..0b0d2afad6 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,7 @@ WEB_DIRS := web_src/js web_src/css ESLINT_FILES := web_src/js tools *.js *.ts *.cjs tests/e2e STYLELINT_FILES := web_src/css web_src/js/components/*.vue -SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) templates options/locale/locale_en-US.ini .github $(filter-out CHANGELOG.md, $(wildcard *.go *.js *.md *.yml *.yaml *.toml)) +SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) templates options/locale/locale_en-US.ini .github $(filter-out CHANGELOG.md, $(wildcard *.go *.js *.md *.yml *.yaml *.toml)) $(filter-out tools/misspellings.csv, $(wildcard tools/*)) EDITORCONFIG_FILES := templates .github/workflows options/locale/locale_en-US.ini GO_SOURCES := $(wildcard *.go) diff --git a/tools/lint-go-gopls.sh b/tools/lint-go-gopls.sh index 4bb69f4c16..a222ea14d7 100755 --- a/tools/lint-go-gopls.sh +++ b/tools/lint-go-gopls.sh @@ -8,7 +8,7 @@ IGNORE_PATTERNS=( ) # lint all go files with 'gopls check' and look for lines starting with the -# current absolute path, indicating a error was found. This is neccessary +# current absolute path, indicating a error was found. This is necessary # because the tool does not set non-zero exit code when errors are found. # ref: https://github.com/golang/go/issues/67078 ERROR_LINES=$("$GO" run "$GOPLS_PACKAGE" check "$@" 2>/dev/null | grep -E "^$PWD" | grep -vFf <(printf '%s\n' "${IGNORE_PATTERNS[@]}")); From 7df09e31fa2700454beecbaf3c0721e13d6086f4 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 17 Feb 2025 11:28:37 -0800 Subject: [PATCH 02/16] Move issue pin to an standalone table for querying performance (#33452) Noticed a SQL in gitea.com has a bigger load. It seems both `is_pull` and `pin_order` are not indexed columns in the database. ```SQL SELECT `id`, `repo_id`, `index`, `poster_id`, `original_author`, `original_author_id`, `name`, `content`, `content_version`, `milestone_id`, `priority`, `is_closed`, `is_pull`, `num_comments`, `ref`, `pin_order`, `deadline_unix`, `created_unix`, `updated_unix`, `closed_unix`, `is_locked`, `time_estimate` FROM `issue` WHERE (repo_id =?) AND (is_pull = 0) AND (pin_order > 0) ORDER BY pin_order ``` I came across a comment https://github.com/go-gitea/gitea/pull/24406#issuecomment-1527747296 from @delvh , which presents a more reasonable approach. Based on this, this PR will migrate all issue and pull request pin data from the `issue` table to the `issue_pin` table. This change benefits larger Gitea instances by improving scalability and performance. --------- Co-authored-by: wxiaoguang --- models/fixtures/issue_pin.yml | 6 + models/issues/issue.go | 215 ++++----------------------- models/issues/issue_list.go | 33 +++++ models/issues/issue_pin.go | 246 +++++++++++++++++++++++++++++++ models/migrations/migrations.go | 1 + models/migrations/v1_24/v313.go | 31 ++++ routers/api/v1/repo/issue_pin.go | 6 +- routers/web/repo/issue_pin.go | 47 +++--- routers/web/repo/issue_view.go | 6 +- services/convert/issue.go | 7 +- services/convert/pull.go | 7 +- services/issue/issue.go | 8 +- services/repository/delete.go | 1 + 13 files changed, 396 insertions(+), 218 deletions(-) create mode 100644 models/fixtures/issue_pin.yml create mode 100644 models/issues/issue_pin.go create mode 100644 models/migrations/v1_24/v313.go diff --git a/models/fixtures/issue_pin.yml b/models/fixtures/issue_pin.yml new file mode 100644 index 0000000000..14b7a72d84 --- /dev/null +++ b/models/fixtures/issue_pin.yml @@ -0,0 +1,6 @@ +- + id: 1 + repo_id: 2 + issue_id: 4 + is_pull: false + pin_order: 1 diff --git a/models/issues/issue.go b/models/issues/issue.go index 5d52f0dd5d..7e72bb776c 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -97,7 +97,7 @@ type Issue struct { // TODO: RemoveIssueRef: see "repo/issue/branch_selector_field.tmpl" Ref string - PinOrder int `xorm:"DEFAULT 0"` + PinOrder int `xorm:"-"` // 0 means not loaded, -1 means loaded but not pinned DeadlineUnix timeutil.TimeStamp `xorm:"INDEX"` @@ -291,6 +291,23 @@ func (issue *Issue) LoadMilestone(ctx context.Context) (err error) { return nil } +func (issue *Issue) LoadPinOrder(ctx context.Context) error { + if issue.PinOrder != 0 { + return nil + } + issuePin, err := GetIssuePin(ctx, issue) + if err != nil && !db.IsErrNotExist(err) { + return err + } + + if issuePin != nil { + issue.PinOrder = issuePin.PinOrder + } else { + issue.PinOrder = -1 + } + return nil +} + // LoadAttributes loads the attribute of this issue. func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { if err = issue.LoadRepo(ctx); err != nil { @@ -330,6 +347,10 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { return err } + if err = issue.LoadPinOrder(ctx); err != nil { + return err + } + if err = issue.Comments.LoadAttributes(ctx); err != nil { return err } @@ -342,6 +363,14 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { return issue.loadReactions(ctx) } +// IsPinned returns if a Issue is pinned +func (issue *Issue) IsPinned() bool { + if issue.PinOrder == 0 { + setting.PanicInDevOrTesting("issue's pinorder has not been loaded") + } + return issue.PinOrder > 0 +} + func (issue *Issue) ResetAttributesLoaded() { issue.isLabelsLoaded = false issue.isMilestoneLoaded = false @@ -720,190 +749,6 @@ func (issue *Issue) HasOriginalAuthor() bool { return issue.OriginalAuthor != "" && issue.OriginalAuthorID != 0 } -var ErrIssueMaxPinReached = util.NewInvalidArgumentErrorf("the max number of pinned issues has been readched") - -// IsPinned returns if a Issue is pinned -func (issue *Issue) IsPinned() bool { - return issue.PinOrder != 0 -} - -// Pin pins a Issue -func (issue *Issue) Pin(ctx context.Context, user *user_model.User) error { - // If the Issue is already pinned, we don't need to pin it twice - if issue.IsPinned() { - return nil - } - - var maxPin int - _, err := db.GetEngine(ctx).SQL("SELECT MAX(pin_order) FROM issue WHERE repo_id = ? AND is_pull = ?", issue.RepoID, issue.IsPull).Get(&maxPin) - if err != nil { - return err - } - - // Check if the maximum allowed Pins reached - if maxPin >= setting.Repository.Issue.MaxPinned { - return ErrIssueMaxPinReached - } - - _, err = db.GetEngine(ctx).Table("issue"). - Where("id = ?", issue.ID). - Update(map[string]any{ - "pin_order": maxPin + 1, - }) - if err != nil { - return err - } - - // Add the pin event to the history - opts := &CreateCommentOptions{ - Type: CommentTypePin, - Doer: user, - Repo: issue.Repo, - Issue: issue, - } - if _, err = CreateComment(ctx, opts); err != nil { - return err - } - - return nil -} - -// UnpinIssue unpins a Issue -func (issue *Issue) Unpin(ctx context.Context, user *user_model.User) error { - // If the Issue is not pinned, we don't need to unpin it - if !issue.IsPinned() { - return nil - } - - // This sets the Pin for all Issues that come after the unpined Issue to the correct value - _, err := db.GetEngine(ctx).Exec("UPDATE issue SET pin_order = pin_order - 1 WHERE repo_id = ? AND is_pull = ? AND pin_order > ?", issue.RepoID, issue.IsPull, issue.PinOrder) - if err != nil { - return err - } - - _, err = db.GetEngine(ctx).Table("issue"). - Where("id = ?", issue.ID). - Update(map[string]any{ - "pin_order": 0, - }) - if err != nil { - return err - } - - // Add the unpin event to the history - opts := &CreateCommentOptions{ - Type: CommentTypeUnpin, - Doer: user, - Repo: issue.Repo, - Issue: issue, - } - if _, err = CreateComment(ctx, opts); err != nil { - return err - } - - return nil -} - -// PinOrUnpin pins or unpins a Issue -func (issue *Issue) PinOrUnpin(ctx context.Context, user *user_model.User) error { - if !issue.IsPinned() { - return issue.Pin(ctx, user) - } - - return issue.Unpin(ctx, user) -} - -// MovePin moves a Pinned Issue to a new Position -func (issue *Issue) MovePin(ctx context.Context, newPosition int) error { - // If the Issue is not pinned, we can't move them - if !issue.IsPinned() { - return nil - } - - if newPosition < 1 { - return fmt.Errorf("The Position can't be lower than 1") - } - - dbctx, committer, err := db.TxContext(ctx) - if err != nil { - return err - } - defer committer.Close() - - var maxPin int - _, err = db.GetEngine(dbctx).SQL("SELECT MAX(pin_order) FROM issue WHERE repo_id = ? AND is_pull = ?", issue.RepoID, issue.IsPull).Get(&maxPin) - if err != nil { - return err - } - - // If the new Position bigger than the current Maximum, set it to the Maximum - if newPosition > maxPin+1 { - newPosition = maxPin + 1 - } - - // Lower the Position of all Pinned Issue that came after the current Position - _, err = db.GetEngine(dbctx).Exec("UPDATE issue SET pin_order = pin_order - 1 WHERE repo_id = ? AND is_pull = ? AND pin_order > ?", issue.RepoID, issue.IsPull, issue.PinOrder) - if err != nil { - return err - } - - // Higher the Position of all Pinned Issues that comes after the new Position - _, err = db.GetEngine(dbctx).Exec("UPDATE issue SET pin_order = pin_order + 1 WHERE repo_id = ? AND is_pull = ? AND pin_order >= ?", issue.RepoID, issue.IsPull, newPosition) - if err != nil { - return err - } - - _, err = db.GetEngine(dbctx).Table("issue"). - Where("id = ?", issue.ID). - Update(map[string]any{ - "pin_order": newPosition, - }) - if err != nil { - return err - } - - return committer.Commit() -} - -// GetPinnedIssues returns the pinned Issues for the given Repo and type -func GetPinnedIssues(ctx context.Context, repoID int64, isPull bool) (IssueList, error) { - issues := make(IssueList, 0) - - err := db.GetEngine(ctx). - Table("issue"). - Where("repo_id = ?", repoID). - And("is_pull = ?", isPull). - And("pin_order > 0"). - OrderBy("pin_order"). - Find(&issues) - if err != nil { - return nil, err - } - - err = issues.LoadAttributes(ctx) - if err != nil { - return nil, err - } - - return issues, nil -} - -// IsNewPinAllowed returns if a new Issue or Pull request can be pinned -func IsNewPinAllowed(ctx context.Context, repoID int64, isPull bool) (bool, error) { - var maxPin int - _, err := db.GetEngine(ctx).SQL("SELECT COUNT(pin_order) FROM issue WHERE repo_id = ? AND is_pull = ? AND pin_order > 0", repoID, isPull).Get(&maxPin) - if err != nil { - return false, err - } - - return maxPin < setting.Repository.Issue.MaxPinned, nil -} - -// IsErrIssueMaxPinReached returns if the error is, that the User can't pin more Issues -func IsErrIssueMaxPinReached(err error) bool { - return err == ErrIssueMaxPinReached -} - // InsertIssues insert issues to database func InsertIssues(ctx context.Context, issues ...*Issue) error { ctx, committer, err := db.TxContext(ctx) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 02fd330f0a..6c74b533b3 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -506,6 +506,39 @@ func (issues IssueList) loadTotalTrackedTimes(ctx context.Context) (err error) { return nil } +func (issues IssueList) LoadPinOrder(ctx context.Context) error { + if len(issues) == 0 { + return nil + } + + issueIDs := container.FilterSlice(issues, func(issue *Issue) (int64, bool) { + return issue.ID, issue.PinOrder == 0 + }) + if len(issueIDs) == 0 { + return nil + } + issuePins, err := GetIssuePinsByIssueIDs(ctx, issueIDs) + if err != nil { + return err + } + + for _, issue := range issues { + if issue.PinOrder != 0 { + continue + } + for _, pin := range issuePins { + if pin.IssueID == issue.ID { + issue.PinOrder = pin.PinOrder + break + } + } + if issue.PinOrder == 0 { + issue.PinOrder = -1 + } + } + return nil +} + // loadAttributes loads all attributes, expect for attachments and comments func (issues IssueList) LoadAttributes(ctx context.Context) error { if _, err := issues.LoadRepositories(ctx); err != nil { diff --git a/models/issues/issue_pin.go b/models/issues/issue_pin.go new file mode 100644 index 0000000000..ae6195b05d --- /dev/null +++ b/models/issues/issue_pin.go @@ -0,0 +1,246 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package issues + +import ( + "context" + "errors" + "sort" + + "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" +) + +type IssuePin struct { + ID int64 `xorm:"pk autoincr"` + RepoID int64 `xorm:"UNIQUE(s) NOT NULL"` + IssueID int64 `xorm:"UNIQUE(s) NOT NULL"` + IsPull bool `xorm:"NOT NULL"` + PinOrder int `xorm:"DEFAULT 0"` +} + +var ErrIssueMaxPinReached = util.NewInvalidArgumentErrorf("the max number of pinned issues has been readched") + +// IsErrIssueMaxPinReached returns if the error is, that the User can't pin more Issues +func IsErrIssueMaxPinReached(err error) bool { + return err == ErrIssueMaxPinReached +} + +func init() { + db.RegisterModel(new(IssuePin)) +} + +func GetIssuePin(ctx context.Context, issue *Issue) (*IssuePin, error) { + pin := new(IssuePin) + has, err := db.GetEngine(ctx). + Where("repo_id = ?", issue.RepoID). + And("issue_id = ?", issue.ID).Get(pin) + if err != nil { + return nil, err + } else if !has { + return nil, db.ErrNotExist{ + Resource: "IssuePin", + ID: issue.ID, + } + } + return pin, nil +} + +func GetIssuePinsByIssueIDs(ctx context.Context, issueIDs []int64) ([]IssuePin, error) { + var pins []IssuePin + if err := db.GetEngine(ctx).In("issue_id", issueIDs).Find(&pins); err != nil { + return nil, err + } + return pins, nil +} + +// Pin pins a Issue +func PinIssue(ctx context.Context, issue *Issue, user *user_model.User) error { + return db.WithTx(ctx, func(ctx context.Context) error { + pinnedIssuesNum, err := getPinnedIssuesNum(ctx, issue.RepoID, issue.IsPull) + if err != nil { + return err + } + + // Check if the maximum allowed Pins reached + if pinnedIssuesNum >= setting.Repository.Issue.MaxPinned { + return ErrIssueMaxPinReached + } + + pinnedIssuesMaxPinOrder, err := getPinnedIssuesMaxPinOrder(ctx, issue.RepoID, issue.IsPull) + if err != nil { + return err + } + + if _, err = db.GetEngine(ctx).Insert(&IssuePin{ + RepoID: issue.RepoID, + IssueID: issue.ID, + IsPull: issue.IsPull, + PinOrder: pinnedIssuesMaxPinOrder + 1, + }); err != nil { + return err + } + + // Add the pin event to the history + _, err = CreateComment(ctx, &CreateCommentOptions{ + Type: CommentTypePin, + Doer: user, + Repo: issue.Repo, + Issue: issue, + }) + return err + }) +} + +// UnpinIssue unpins a Issue +func UnpinIssue(ctx context.Context, issue *Issue, user *user_model.User) error { + return db.WithTx(ctx, func(ctx context.Context) error { + // This sets the Pin for all Issues that come after the unpined Issue to the correct value + cnt, err := db.GetEngine(ctx).Where("issue_id=?", issue.ID).Delete(new(IssuePin)) + if err != nil { + return err + } + if cnt == 0 { + return nil + } + + // Add the unpin event to the history + _, err = CreateComment(ctx, &CreateCommentOptions{ + Type: CommentTypeUnpin, + Doer: user, + Repo: issue.Repo, + Issue: issue, + }) + return err + }) +} + +func getPinnedIssuesNum(ctx context.Context, repoID int64, isPull bool) (int, error) { + var pinnedIssuesNum int + _, err := db.GetEngine(ctx).SQL("SELECT count(pin_order) FROM issue_pin WHERE repo_id = ? AND is_pull = ?", repoID, isPull).Get(&pinnedIssuesNum) + return pinnedIssuesNum, err +} + +func getPinnedIssuesMaxPinOrder(ctx context.Context, repoID int64, isPull bool) (int, error) { + var maxPinnedIssuesMaxPinOrder int + _, err := db.GetEngine(ctx).SQL("SELECT max(pin_order) FROM issue_pin WHERE repo_id = ? AND is_pull = ?", repoID, isPull).Get(&maxPinnedIssuesMaxPinOrder) + return maxPinnedIssuesMaxPinOrder, err +} + +// MovePin moves a Pinned Issue to a new Position +func MovePin(ctx context.Context, issue *Issue, newPosition int) error { + if newPosition < 1 { + return errors.New("The Position can't be lower than 1") + } + + issuePin, err := GetIssuePin(ctx, issue) + if err != nil { + return err + } + if issuePin.PinOrder == newPosition { + return nil + } + + return db.WithTx(ctx, func(ctx context.Context) error { + if issuePin.PinOrder > newPosition { // move the issue to a lower position + _, err = db.GetEngine(ctx).Exec("UPDATE issue_pin SET pin_order = pin_order + 1 WHERE repo_id = ? AND is_pull = ? AND pin_order >= ? AND pin_order < ?", issue.RepoID, issue.IsPull, newPosition, issuePin.PinOrder) + } else { // move the issue to a higher position + // Lower the Position of all Pinned Issue that came after the current Position + _, err = db.GetEngine(ctx).Exec("UPDATE issue_pin SET pin_order = pin_order - 1 WHERE repo_id = ? AND is_pull = ? AND pin_order > ? AND pin_order <= ?", issue.RepoID, issue.IsPull, issuePin.PinOrder, newPosition) + } + if err != nil { + return err + } + + _, err = db.GetEngine(ctx). + Table("issue_pin"). + Where("id = ?", issuePin.ID). + Update(map[string]any{ + "pin_order": newPosition, + }) + return err + }) +} + +func GetPinnedIssueIDs(ctx context.Context, repoID int64, isPull bool) ([]int64, error) { + var issuePins []IssuePin + if err := db.GetEngine(ctx). + Table("issue_pin"). + Where("repo_id = ?", repoID). + And("is_pull = ?", isPull). + Find(&issuePins); err != nil { + return nil, err + } + + sort.Slice(issuePins, func(i, j int) bool { + return issuePins[i].PinOrder < issuePins[j].PinOrder + }) + + var ids []int64 + for _, pin := range issuePins { + ids = append(ids, pin.IssueID) + } + return ids, nil +} + +func GetIssuePinsByRepoID(ctx context.Context, repoID int64, isPull bool) ([]*IssuePin, error) { + var pins []*IssuePin + if err := db.GetEngine(ctx).Where("repo_id = ? AND is_pull = ?", repoID, isPull).Find(&pins); err != nil { + return nil, err + } + return pins, nil +} + +// GetPinnedIssues returns the pinned Issues for the given Repo and type +func GetPinnedIssues(ctx context.Context, repoID int64, isPull bool) (IssueList, error) { + issuePins, err := GetIssuePinsByRepoID(ctx, repoID, isPull) + if err != nil { + return nil, err + } + if len(issuePins) == 0 { + return IssueList{}, nil + } + ids := make([]int64, 0, len(issuePins)) + for _, pin := range issuePins { + ids = append(ids, pin.IssueID) + } + + issues := make(IssueList, 0, len(ids)) + if err := db.GetEngine(ctx).In("id", ids).Find(&issues); err != nil { + return nil, err + } + for _, issue := range issues { + for _, pin := range issuePins { + if pin.IssueID == issue.ID { + issue.PinOrder = pin.PinOrder + break + } + } + if (!setting.IsProd || setting.IsInTesting) && issue.PinOrder == 0 { + panic("It should not happen that a pinned Issue has no PinOrder") + } + } + sort.Slice(issues, func(i, j int) bool { + return issues[i].PinOrder < issues[j].PinOrder + }) + + if err = issues.LoadAttributes(ctx); err != nil { + return nil, err + } + + return issues, nil +} + +// IsNewPinAllowed returns if a new Issue or Pull request can be pinned +func IsNewPinAllowed(ctx context.Context, repoID int64, isPull bool) (bool, error) { + var maxPin int + _, err := db.GetEngine(ctx).SQL("SELECT COUNT(pin_order) FROM issue_pin WHERE repo_id = ? AND is_pull = ?", repoID, isPull).Get(&maxPin) + if err != nil { + return false, err + } + + return maxPin < setting.Repository.Issue.MaxPinned, nil +} diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 95364ab705..87d674a440 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -373,6 +373,7 @@ func prepareMigrationTasks() []*migration { // Gitea 1.23.0-rc0 ends at migration ID number 311 (database version 312) newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge), + newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin), } return preparedMigrations } diff --git a/models/migrations/v1_24/v313.go b/models/migrations/v1_24/v313.go new file mode 100644 index 0000000000..ee9d479340 --- /dev/null +++ b/models/migrations/v1_24/v313.go @@ -0,0 +1,31 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_24 //nolint + +import ( + "code.gitea.io/gitea/models/migrations/base" + + "xorm.io/xorm" +) + +func MovePinOrderToTableIssuePin(x *xorm.Engine) error { + type IssuePin struct { + ID int64 `xorm:"pk autoincr"` + RepoID int64 `xorm:"UNIQUE(s) NOT NULL"` + IssueID int64 `xorm:"UNIQUE(s) NOT NULL"` + IsPull bool `xorm:"NOT NULL"` + PinOrder int `xorm:"DEFAULT 0"` + } + + if err := x.Sync(new(IssuePin)); err != nil { + return err + } + + if _, err := x.Exec("INSERT INTO issue_pin (repo_id, issue_id, is_pull, pin_order) SELECT repo_id, id, is_pull, pin_order FROM issue WHERE pin_order > 0"); err != nil { + return err + } + sess := x.NewSession() + defer sess.Close() + return base.DropTableColumns(sess, "issue", "pin_order") +} diff --git a/routers/api/v1/repo/issue_pin.go b/routers/api/v1/repo/issue_pin.go index f4cbc8e762..5e55b7c2d6 100644 --- a/routers/api/v1/repo/issue_pin.go +++ b/routers/api/v1/repo/issue_pin.go @@ -60,7 +60,7 @@ func PinIssue(ctx *context.APIContext) { return } - err = issue.Pin(ctx, ctx.Doer) + err = issues_model.PinIssue(ctx, issue, ctx.Doer) if err != nil { ctx.APIError(http.StatusInternalServerError, err) return @@ -115,7 +115,7 @@ func UnpinIssue(ctx *context.APIContext) { return } - err = issue.Unpin(ctx, ctx.Doer) + err = issues_model.UnpinIssue(ctx, issue, ctx.Doer) if err != nil { ctx.APIError(http.StatusInternalServerError, err) return @@ -169,7 +169,7 @@ func MoveIssuePin(ctx *context.APIContext) { return } - err = issue.MovePin(ctx, int(ctx.PathParamInt64("position"))) + err = issues_model.MovePin(ctx, issue, int(ctx.PathParamInt64("position"))) if err != nil { ctx.APIError(http.StatusInternalServerError, err) return diff --git a/routers/web/repo/issue_pin.go b/routers/web/repo/issue_pin.go index d7d3205c37..8d3de90d25 100644 --- a/routers/web/repo/issue_pin.go +++ b/routers/web/repo/issue_pin.go @@ -6,6 +6,7 @@ package repo import ( "net/http" + "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" @@ -22,15 +23,29 @@ func IssuePinOrUnpin(ctx *context.Context) { // If we don't do this, it will crash when trying to add the pin event to the comment history err := issue.LoadRepo(ctx) if err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + ctx.ServerError("LoadRepo", err) return } - err = issue.PinOrUnpin(ctx, ctx.Doer) + // PinOrUnpin pins or unpins a Issue + _, err = issues_model.GetIssuePin(ctx, issue) + if err != nil && !db.IsErrNotExist(err) { + ctx.ServerError("GetIssuePin", err) + return + } + + if db.IsErrNotExist(err) { + err = issues_model.PinIssue(ctx, issue, ctx.Doer) + } else { + err = issues_model.UnpinIssue(ctx, issue, ctx.Doer) + } + if err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + if issues_model.IsErrIssueMaxPinReached(err) { + ctx.JSONError(ctx.Tr("repo.issues.max_pinned")) + } else { + ctx.ServerError("Pin/Unpin failed", err) + } return } @@ -41,23 +56,20 @@ func IssuePinOrUnpin(ctx *context.Context) { func IssueUnpin(ctx *context.Context) { issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) if err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + ctx.ServerError("GetIssueByIndex", err) return } // If we don't do this, it will crash when trying to add the pin event to the comment history err = issue.LoadRepo(ctx) if err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + ctx.ServerError("LoadRepo", err) return } - err = issue.Unpin(ctx, ctx.Doer) + err = issues_model.UnpinIssue(ctx, issue, ctx.Doer) if err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + ctx.ServerError("UnpinIssue", err) return } @@ -78,15 +90,13 @@ func IssuePinMove(ctx *context.Context) { form := &movePinIssueForm{} if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + ctx.ServerError("Decode", err) return } issue, err := issues_model.GetIssueByID(ctx, form.ID) if err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + ctx.ServerError("GetIssueByID", err) return } @@ -96,10 +106,9 @@ func IssuePinMove(ctx *context.Context) { return } - err = issue.MovePin(ctx, form.Position) + err = issues_model.MovePin(ctx, issue, form.Position) if err != nil { - ctx.Status(http.StatusInternalServerError) - log.Error(err.Error()) + ctx.ServerError("MovePin", err) return } diff --git a/routers/web/repo/issue_view.go b/routers/web/repo/issue_view.go index 06a906b494..37e1b27931 100644 --- a/routers/web/repo/issue_view.go +++ b/routers/web/repo/issue_view.go @@ -543,7 +543,11 @@ func preparePullViewDeleteBranch(ctx *context.Context, issue *issues_model.Issue func prepareIssueViewSidebarPin(ctx *context.Context, issue *issues_model.Issue) { var pinAllowed bool - if !issue.IsPinned() { + if err := issue.LoadPinOrder(ctx); err != nil { + ctx.ServerError("LoadPinOrder", err) + return + } + if issue.PinOrder == 0 { var err error pinAllowed, err = issues_model.IsNewPinAllowed(ctx, issue.RepoID, issue.IsPull) if err != nil { diff --git a/services/convert/issue.go b/services/convert/issue.go index 62d0a3b3e6..7f386e6293 100644 --- a/services/convert/issue.go +++ b/services/convert/issue.go @@ -41,6 +41,9 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss if err := issue.LoadAttachments(ctx); err != nil { return &api.Issue{} } + if err := issue.LoadPinOrder(ctx); err != nil { + return &api.Issue{} + } apiIssue := &api.Issue{ ID: issue.ID, @@ -55,7 +58,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss Comments: issue.NumComments, Created: issue.CreatedUnix.AsTime(), Updated: issue.UpdatedUnix.AsTime(), - PinOrder: issue.PinOrder, + PinOrder: util.Iif(issue.PinOrder == -1, 0, issue.PinOrder), // -1 means loaded with no pin order } if issue.Repo != nil { @@ -122,6 +125,7 @@ func toIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Iss // ToIssueList converts an IssueList to API format func ToIssueList(ctx context.Context, doer *user_model.User, il issues_model.IssueList) []*api.Issue { result := make([]*api.Issue, len(il)) + _ = il.LoadPinOrder(ctx) for i := range il { result[i] = ToIssue(ctx, doer, il[i]) } @@ -131,6 +135,7 @@ func ToIssueList(ctx context.Context, doer *user_model.User, il issues_model.Iss // ToAPIIssueList converts an IssueList to API format func ToAPIIssueList(ctx context.Context, doer *user_model.User, il issues_model.IssueList) []*api.Issue { result := make([]*api.Issue, len(il)) + _ = il.LoadPinOrder(ctx) for i := range il { result[i] = ToAPIIssue(ctx, doer, il[i]) } diff --git a/services/convert/pull.go b/services/convert/pull.go index 209d2bd79d..ad4f08fa91 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -93,7 +93,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u Deadline: apiIssue.Deadline, Created: pr.Issue.CreatedUnix.AsTimePtr(), Updated: pr.Issue.UpdatedUnix.AsTimePtr(), - PinOrder: apiIssue.PinOrder, + PinOrder: util.Iif(apiIssue.PinOrder == -1, 0, apiIssue.PinOrder), // output "[]" rather than null to align to github outputs RequestedReviewers: []*api.User{}, @@ -304,6 +304,9 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs if err := issueList.LoadAssignees(ctx); err != nil { return nil, err } + if err = issueList.LoadPinOrder(ctx); err != nil { + return nil, err + } reviews, err := prs.LoadReviews(ctx) if err != nil { @@ -368,7 +371,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs Deadline: apiIssue.Deadline, Created: pr.Issue.CreatedUnix.AsTimePtr(), Updated: pr.Issue.UpdatedUnix.AsTimePtr(), - PinOrder: apiIssue.PinOrder, + PinOrder: util.Iif(apiIssue.PinOrder == -1, 0, apiIssue.PinOrder), AllowMaintainerEdit: pr.AllowMaintainerEdit, diff --git a/services/issue/issue.go b/services/issue/issue.go index 091b7c02d7..586b6031c8 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -197,13 +197,6 @@ func DeleteIssue(ctx context.Context, doer *user_model.User, gitRepo *git.Reposi } } - // If the Issue is pinned, we should unpin it before deletion to avoid problems with other pinned Issues - if issue.IsPinned() { - if err := issue.Unpin(ctx, doer); err != nil { - return err - } - } - notify_service.DeleteIssue(ctx, doer, issue) return nil @@ -319,6 +312,7 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error { &issues_model.Comment{RefIssueID: issue.ID}, &issues_model.IssueDependency{DependencyID: issue.ID}, &issues_model.Comment{DependentIssueID: issue.ID}, + &issues_model.IssuePin{IssueID: issue.ID}, ); err != nil { return err } diff --git a/services/repository/delete.go b/services/repository/delete.go index 2166b4dd5c..fb3fffdca7 100644 --- a/services/repository/delete.go +++ b/services/repository/delete.go @@ -158,6 +158,7 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, repoID &actions_model.ActionSchedule{RepoID: repoID}, &actions_model.ActionArtifact{RepoID: repoID}, &actions_model.ActionRunnerToken{RepoID: repoID}, + &issues_model.IssuePin{RepoID: repoID}, ); err != nil { return fmt.Errorf("deleteBeans: %w", err) } From 15e020eec85d7ec2ef0f1e9ad10a1ffde2ca0f34 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 18 Feb 2025 04:41:03 +0800 Subject: [PATCH 03/16] Refactor error system (#33626) --- modules/util/error.go | 15 ++- routers/api/v1/admin/email.go | 2 +- routers/api/v1/admin/hooks.go | 10 +- routers/api/v1/admin/org.go | 4 +- routers/api/v1/admin/user.go | 16 +-- routers/api/v1/admin/user_badge.go | 6 +- routers/api/v1/api.go | 42 ++++--- routers/api/v1/misc/signing.go | 5 +- routers/api/v1/org/action.go | 18 +-- routers/api/v1/org/avatar.go | 4 +- routers/api/v1/org/label.go | 12 +- routers/api/v1/org/member.go | 14 +-- routers/api/v1/org/org.go | 20 +-- routers/api/v1/org/team.go | 44 +++---- routers/api/v1/packages/package.go | 10 +- routers/api/v1/repo/action.go | 34 ++--- routers/api/v1/repo/avatar.go | 4 +- routers/api/v1/repo/branch.go | 118 +++++++++--------- routers/api/v1/repo/collaborators.go | 24 ++-- routers/api/v1/repo/commits.go | 28 ++--- routers/api/v1/repo/compare.go | 2 +- routers/api/v1/repo/download.go | 2 +- routers/api/v1/repo/file.go | 18 +-- routers/api/v1/repo/fork.go | 14 +-- routers/api/v1/repo/git_hook.go | 12 +- routers/api/v1/repo/git_ref.go | 2 +- routers/api/v1/repo/hook.go | 4 +- routers/api/v1/repo/issue.go | 68 +++++----- routers/api/v1/repo/issue_attachment.go | 16 +-- routers/api/v1/repo/issue_comment.go | 44 +++---- .../api/v1/repo/issue_comment_attachment.go | 18 +-- routers/api/v1/repo/issue_dependency.go | 18 +-- routers/api/v1/repo/issue_label.go | 30 ++--- routers/api/v1/repo/issue_pin.go | 32 ++--- routers/api/v1/repo/issue_reaction.go | 28 ++--- routers/api/v1/repo/issue_stopwatch.go | 12 +- routers/api/v1/repo/issue_subscription.go | 18 +-- routers/api/v1/repo/issue_tracked_time.go | 42 +++---- routers/api/v1/repo/key.go | 10 +- routers/api/v1/repo/label.go | 12 +- routers/api/v1/repo/migrate.go | 12 +- routers/api/v1/repo/milestone.go | 12 +- routers/api/v1/repo/mirror.go | 6 +- routers/api/v1/repo/notes.go | 6 +- routers/api/v1/repo/patch.go | 4 +- routers/api/v1/repo/pull.go | 110 ++++++++-------- routers/api/v1/repo/pull_review.go | 62 ++++----- routers/api/v1/repo/release.go | 30 ++--- routers/api/v1/repo/release_attachment.go | 20 +-- routers/api/v1/repo/release_tags.go | 8 +- routers/api/v1/repo/repo.go | 42 +++---- routers/api/v1/repo/star.go | 2 +- routers/api/v1/repo/status.go | 6 +- routers/api/v1/repo/subscriber.go | 2 +- routers/api/v1/repo/tag.go | 38 +++--- routers/api/v1/repo/transfer.go | 4 +- routers/api/v1/repo/wiki.go | 20 +-- routers/api/v1/shared/block.go | 10 +- routers/api/v1/user/action.go | 18 +-- routers/api/v1/user/app.go | 16 +-- routers/api/v1/user/avatar.go | 4 +- routers/api/v1/user/email.go | 8 +- routers/api/v1/user/follower.go | 8 +- routers/api/v1/user/gpg_key.go | 16 +-- routers/api/v1/user/helper.go | 4 +- routers/api/v1/user/key.go | 8 +- routers/api/v1/user/repo.go | 12 +- routers/api/v1/user/star.go | 8 +- routers/api/v1/user/user.go | 4 +- routers/api/v1/user/watch.go | 8 +- routers/api/v1/utils/git.go | 2 +- routers/api/v1/utils/hook.go | 34 ++--- services/actions/workflow.go | 2 +- services/context/api.go | 16 ++- services/context/user.go | 2 +- 75 files changed, 703 insertions(+), 693 deletions(-) diff --git a/modules/util/error.go b/modules/util/error.go index 07fadf3cab..13b592a9f8 100644 --- a/modules/util/error.go +++ b/modules/util/error.go @@ -10,13 +10,16 @@ import ( // Common Errors forming the base of our error system // -// Many Errors returned by Gitea can be tested against these errors -// using errors.Is. +// Many Errors returned by Gitea can be tested against these errors using "errors.Is". var ( - ErrInvalidArgument = errors.New("invalid argument") - ErrPermissionDenied = errors.New("permission denied") - ErrAlreadyExist = errors.New("resource already exists") - ErrNotExist = errors.New("resource does not exist") + ErrInvalidArgument = errors.New("invalid argument") // also implies HTTP 400 + ErrPermissionDenied = errors.New("permission denied") // also implies HTTP 403 + ErrNotExist = errors.New("resource does not exist") // also implies HTTP 404 + ErrAlreadyExist = errors.New("resource already exists") // also implies HTTP 409 + + // ErrUnprocessableContent implies HTTP 422, syntax of the request content was correct, + // but server was unable to process the contained instructions + ErrUnprocessableContent = errors.New("unprocessable content") ) // SilentWrap provides a simple wrapper for a wrapped error where the wrapped error message plays no part in the error message diff --git a/routers/api/v1/admin/email.go b/routers/api/v1/admin/email.go index dc8d27be0f..ad078347a4 100644 --- a/routers/api/v1/admin/email.go +++ b/routers/api/v1/admin/email.go @@ -42,7 +42,7 @@ func GetAllEmails(ctx *context.APIContext) { ListOptions: listOptions, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/admin/hooks.go b/routers/api/v1/admin/hooks.go index e914baf278..fb1ea4eab6 100644 --- a/routers/api/v1/admin/hooks.go +++ b/routers/api/v1/admin/hooks.go @@ -59,14 +59,14 @@ func ListHooks(ctx *context.APIContext) { sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } hooks := make([]*api.Hook, len(sysHooks)) for i, hook := range sysHooks { h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } hooks[i] = h @@ -98,13 +98,13 @@ func GetHook(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } h, err := webhook_service.ToHook("/-/admin/", hook) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, h) @@ -188,7 +188,7 @@ func DeleteHook(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go index c5962afbc1..8808a1587d 100644 --- a/routers/api/v1/admin/org.go +++ b/routers/api/v1/admin/org.go @@ -69,7 +69,7 @@ func CreateOrg(ctx *context.APIContext) { db.IsErrNamePatternNotAllowed(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -109,7 +109,7 @@ func GetAllOrgs(ctx *context.APIContext) { Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate}, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } orgs := make([]*api.Organization, len(users)) diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index c653794ffc..c4bb85de55 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -42,7 +42,7 @@ func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64 if auth.IsErrSourceNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -145,7 +145,7 @@ func CreateUser(ctx *context.APIContext) { db.IsErrNamePatternNotAllowed(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -210,7 +210,7 @@ func EditUser(ctx *context.APIContext) { case errors.Is(err, password.ErrIsPwned), password.IsErrIsPwnedRequest(err): ctx.APIError(http.StatusBadRequest, err) default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -223,7 +223,7 @@ func EditUser(ctx *context.APIContext) { case user_model.IsErrEmailAlreadyUsed(err): ctx.APIError(http.StatusBadRequest, err) default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -252,7 +252,7 @@ func EditUser(ctx *context.APIContext) { if user_model.IsErrDeleteLastAdminUser(err) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -307,7 +307,7 @@ func DeleteUser(ctx *context.APIContext) { user_model.IsErrDeleteLastAdminUser(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -381,7 +381,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) { } else if asymkey_model.IsErrKeyAccessDenied(err) { ctx.APIError(http.StatusForbidden, "You do not have access to this key") } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -432,7 +432,7 @@ func SearchUsers(ctx *context.APIContext) { ListOptions: listOptions, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/admin/user_badge.go b/routers/api/v1/admin/user_badge.go index 80c246b43d..6d9665a72b 100644 --- a/routers/api/v1/admin/user_badge.go +++ b/routers/api/v1/admin/user_badge.go @@ -33,7 +33,7 @@ func ListUserBadges(ctx *context.APIContext) { badges, maxResults, err := user_model.GetUserBadges(ctx, ctx.ContextUser) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -70,7 +70,7 @@ func AddUserBadges(ctx *context.APIContext) { badges := prepareBadgesForReplaceOrAdd(*form) if err := user_model.AddUserBadges(ctx, ctx.ContextUser, badges); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -106,7 +106,7 @@ func DeleteUserBadges(ctx *context.APIContext) { badges := prepareBadgesForReplaceOrAdd(*form) if err := user_model.RemoveUserBadges(ctx, ctx.ContextUser, badges); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index ad9c71dfbe..907a2f08fe 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -66,6 +66,7 @@ package v1 import ( + "errors" "fmt" "net/http" "strings" @@ -118,7 +119,7 @@ func sudo() func(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -156,10 +157,10 @@ func repoAssignment() func(ctx *context.APIContext) { } else if user_model.IsErrUserRedirectNotExist(err) { ctx.APIErrorNotFound("GetUserByName", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -177,10 +178,10 @@ func repoAssignment() func(ctx *context.APIContext) { } else if repo_model.IsErrRedirectNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -192,7 +193,7 @@ func repoAssignment() func(ctx *context.APIContext) { taskID := ctx.Data["ActionsTaskID"].(int64) task, err := actions_model.GetTaskByID(ctx, taskID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if task.RepoID != repo.ID { @@ -207,14 +208,14 @@ func repoAssignment() func(ctx *context.APIContext) { } if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Repo.Permission.SetUnitsWithDefaultAccessMode(ctx.Repo.Repository.Units, ctx.Repo.Permission.AccessMode) } else { ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -474,13 +475,14 @@ func reqOrgOwnership() func(ctx *context.APIContext) { } else if ctx.Org.Team != nil { orgID = ctx.Org.Team.OrgID } else { - ctx.APIError(http.StatusInternalServerError, "reqOrgOwnership: unprepared context") + setting.PanicInDevOrTesting("reqOrgOwnership: unprepared context") + ctx.APIErrorInternal(errors.New("reqOrgOwnership: unprepared context")) return } isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !isOwner { if ctx.Org.Organization != nil { @@ -500,26 +502,27 @@ func reqTeamMembership() func(ctx *context.APIContext) { return } if ctx.Org.Team == nil { - ctx.APIError(http.StatusInternalServerError, "reqTeamMembership: unprepared context") + setting.PanicInDevOrTesting("reqTeamMembership: unprepared context") + ctx.APIErrorInternal(errors.New("reqTeamMembership: unprepared context")) return } orgID := ctx.Org.Team.OrgID isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if isOwner { return } if isTeamMember, err := organization.IsTeamMember(ctx, orgID, ctx.Org.Team.ID, ctx.Doer.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !isTeamMember { isOrgMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } else if isOrgMember { ctx.APIError(http.StatusForbidden, "Must be a team member") } else { @@ -543,12 +546,13 @@ func reqOrgMembership() func(ctx *context.APIContext) { } else if ctx.Org.Team != nil { orgID = ctx.Org.Team.OrgID } else { - ctx.APIError(http.StatusInternalServerError, "reqOrgMembership: unprepared context") + setting.PanicInDevOrTesting("reqOrgMembership: unprepared context") + ctx.APIErrorInternal(errors.New("reqOrgMembership: unprepared context")) return } if isMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !isMember { if ctx.Org.Organization != nil { @@ -615,10 +619,10 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) { } else if user_model.IsErrUserRedirectNotExist(err) { ctx.APIErrorNotFound("GetOrgByName", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -631,7 +635,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) { if organization.IsErrTeamNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/misc/signing.go b/routers/api/v1/misc/signing.go index 7a9c0af7e9..667396e39c 100644 --- a/routers/api/v1/misc/signing.go +++ b/routers/api/v1/misc/signing.go @@ -5,7 +5,6 @@ package misc import ( "fmt" - "net/http" asymkey_service "code.gitea.io/gitea/services/asymkey" "code.gitea.io/gitea/services/context" @@ -53,11 +52,11 @@ func SigningKey(ctx *context.APIContext) { content, err := asymkey_service.PublicSigningKey(ctx, path) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } _, err = ctx.Write([]byte(content)) if err != nil { - ctx.APIError(http.StatusInternalServerError, fmt.Errorf("Error writing key content %w", err)) + ctx.APIErrorInternal(fmt.Errorf("Error writing key content %w", err)) } } diff --git a/routers/api/v1/org/action.go b/routers/api/v1/org/action.go index 425e514f2b..d9bdb3ab48 100644 --- a/routers/api/v1/org/action.go +++ b/routers/api/v1/org/action.go @@ -113,7 +113,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -160,7 +160,7 @@ func (Action) DeleteSecret(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -223,7 +223,7 @@ func (Action) ListVariables(ctx *context.APIContext) { ListOptions: utils.GetListOptions(ctx), }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -275,7 +275,7 @@ func (Action) GetVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -326,7 +326,7 @@ func (Action) DeleteVariable(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -378,7 +378,7 @@ func (Action) CreateVariable(ctx *context.APIContext) { Name: variableName, }) if err != nil && !errors.Is(err, util.ErrNotExist) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if v != nil && v.ID > 0 { @@ -390,7 +390,7 @@ func (Action) CreateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrInvalidArgument) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -442,7 +442,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -458,7 +458,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrInvalidArgument) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/org/avatar.go b/routers/api/v1/org/avatar.go index 7dadd0dd9e..0eb771b2cd 100644 --- a/routers/api/v1/org/avatar.go +++ b/routers/api/v1/org/avatar.go @@ -45,7 +45,7 @@ func UpdateAvatar(ctx *context.APIContext) { err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -72,7 +72,7 @@ func DeleteAvatar(ctx *context.APIContext) { // "$ref": "#/responses/notFound" err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index e5407ec82f..b5b70bdc7d 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -46,7 +46,7 @@ func ListLabels(ctx *context.APIContext) { labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -103,7 +103,7 @@ func CreateLabel(ctx *context.APIContext) { Description: form.Description, } if err := issues_model.NewLabel(ctx, label); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -149,7 +149,7 @@ func GetLabel(ctx *context.APIContext) { if issues_model.IsErrOrgLabelNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -195,7 +195,7 @@ func EditLabel(ctx *context.APIContext) { if issues_model.IsErrOrgLabelNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -219,7 +219,7 @@ func EditLabel(ctx *context.APIContext) { } l.SetArchived(form.IsArchived != nil && *form.IsArchived) if err := issues_model.UpdateLabel(ctx, l); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -250,7 +250,7 @@ func DeleteLabel(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id")); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index 8ed029895a..2663d78b73 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -82,7 +82,7 @@ func ListMembers(ctx *context.APIContext) { if ctx.Doer != nil { isMember, err = ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -150,12 +150,12 @@ func IsMember(ctx *context.APIContext) { if ctx.Doer != nil { userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if userIsMember || ctx.Doer.IsAdmin { userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } else if userToCheckIsMember { ctx.Status(http.StatusNoContent) } else { @@ -200,7 +200,7 @@ func IsPublicMember(ctx *context.APIContext) { } is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if is { @@ -246,7 +246,7 @@ func PublicizeMember(ctx *context.APIContext) { } err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -288,7 +288,7 @@ func ConcealMember(ctx *context.APIContext) { } err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -323,7 +323,7 @@ func DeleteMember(ctx *context.APIContext) { return } if err := org_service.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } ctx.Status(http.StatusNoContent) } diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index 57d6aabdad..c9208f4757 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -35,7 +35,7 @@ func listUserOrgs(ctx *context.APIContext, u *user_model.User) { } orgs, maxResults, err := db.FindAndCount[organization.Organization](ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -145,7 +145,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) { org := organization.OrgFromUser(o) authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx, ctx.ContextUser.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -164,7 +164,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) { op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx, ctx.ContextUser.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -209,7 +209,7 @@ func GetAll(ctx *context.APIContext) { Visible: vMode, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } orgs := make([]*api.Organization, len(publicOrgs)) @@ -273,7 +273,7 @@ func Create(ctx *context.APIContext) { db.IsErrNamePatternNotAllowed(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -383,7 +383,7 @@ func Edit(ctx *context.APIContext) { if form.Email != "" { if err := user_service.ReplacePrimaryEmailAddress(ctx, ctx.Org.Organization.AsUser(), form.Email); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -397,7 +397,7 @@ func Edit(ctx *context.APIContext) { RepoAdminChangeTeamAccess: optional.FromPtr(form.RepoAdminChangeTeamAccess), } if err := user_service.UpdateUser(ctx, ctx.Org.Organization.AsUser(), opts); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -424,7 +424,7 @@ func Delete(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if err := org.DeleteOrganization(ctx, ctx.Org.Organization, false); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -469,7 +469,7 @@ func ListOrgActivityFeeds(ctx *context.APIContext) { org := organization.OrgFromUser(ctx.ContextUser) isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } includePrivate = isMember @@ -488,7 +488,7 @@ func ListOrgActivityFeeds(ctx *context.APIContext) { feeds, count, err := feed_service.GetFeeds(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.SetTotalCountHeader(count) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 1518d1410c..f70e5dd235 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -59,13 +59,13 @@ func ListTeams(ctx *context.APIContext) { OrgID: ctx.Org.Organization.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiTeams, err := convert.ToTeams(ctx, teams, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -98,13 +98,13 @@ func ListUserTeams(ctx *context.APIContext) { UserID: ctx.Doer.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiTeams, err := convert.ToTeams(ctx, teams, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -233,7 +233,7 @@ func CreateTeam(ctx *context.APIContext) { } else if len(form.Units) > 0 { attachTeamUnits(team, form.Units) } else { - ctx.APIError(http.StatusInternalServerError, errors.New("units permission should not be empty")) + ctx.APIErrorInternal(errors.New("units permission should not be empty")) return } } else { @@ -244,7 +244,7 @@ func CreateTeam(ctx *context.APIContext) { if organization.IsErrTeamAlreadyExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -332,7 +332,7 @@ func EditTeam(ctx *context.APIContext) { } if err := org_service.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -363,7 +363,7 @@ func DeleteTeam(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if err := org_service.DeleteTeam(ctx, ctx.Org.Team); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -399,7 +399,7 @@ func GetTeamMembers(ctx *context.APIContext) { isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Team.OrgID, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !isMember && !ctx.Doer.IsAdmin { ctx.APIErrorNotFound() @@ -411,7 +411,7 @@ func GetTeamMembers(ctx *context.APIContext) { TeamID: ctx.Org.Team.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -456,7 +456,7 @@ func GetTeamMember(ctx *context.APIContext) { teamID := ctx.PathParamInt64("teamid") isTeamMember, err := organization.IsUserInTeams(ctx, u.ID, []int64{teamID}) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !isTeamMember { ctx.APIErrorNotFound() @@ -500,7 +500,7 @@ func AddTeamMember(ctx *context.APIContext) { if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -538,7 +538,7 @@ func RemoveTeamMember(ctx *context.APIContext) { } if err := org_service.RemoveTeamMember(ctx, ctx.Org.Team, u); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -578,14 +578,14 @@ func GetTeamRepos(ctx *context.APIContext) { TeamID: team.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } repos := make([]*api.Repository, len(teamRepos)) for i, repo := range teamRepos { permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } repos[i] = convert.ToRepo(ctx, repo, permission) @@ -636,7 +636,7 @@ func GetTeamRepo(ctx *context.APIContext) { permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -650,7 +650,7 @@ func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository { if repo_model.IsErrRepoNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil } @@ -694,14 +694,14 @@ func AddTeamRepository(ctx *context.APIContext) { return } if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if access < perm.AccessModeAdmin { ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository") return } if err := repo_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -746,14 +746,14 @@ func RemoveTeamRepository(ctx *context.APIContext) { return } if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if access < perm.AccessModeAdmin { ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository") return } if err := repo_service.RemoveRepositoryFromTeam(ctx, ctx.Org.Team, repo.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -885,7 +885,7 @@ func ListTeamActivityFeeds(ctx *context.APIContext) { feeds, count, err := feed_service.GetFeeds(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.SetTotalCountHeader(count) diff --git a/routers/api/v1/packages/package.go b/routers/api/v1/packages/package.go index 3da456c3fb..f869519344 100644 --- a/routers/api/v1/packages/package.go +++ b/routers/api/v1/packages/package.go @@ -67,13 +67,13 @@ func ListPackages(ctx *context.APIContext) { Paginator: &listOptions, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } pds, err := packages.GetPackageDescriptors(ctx, pvs) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -81,7 +81,7 @@ func ListPackages(ctx *context.APIContext) { for _, pd := range pds { apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiPackages = append(apiPackages, apiPackage) @@ -128,7 +128,7 @@ func GetPackage(ctx *context.APIContext) { apiPackage, err := convert.ToPackage(ctx, ctx.Package.Descriptor, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -169,7 +169,7 @@ func DeletePackage(ctx *context.APIContext) { err := packages_service.RemovePackageVersion(ctx, ctx.Doer, ctx.Package.Descriptor.Version) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 676f3f505a..6b4ce37fcf 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -143,7 +143,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -197,7 +197,7 @@ func (Action) DeleteSecret(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -243,7 +243,7 @@ func (Action) GetVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -299,7 +299,7 @@ func (Action) DeleteVariable(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -354,7 +354,7 @@ func (Action) CreateVariable(ctx *context.APIContext) { Name: variableName, }) if err != nil && !errors.Is(err, util.ErrNotExist) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if v != nil && v.ID > 0 { @@ -366,7 +366,7 @@ func (Action) CreateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrInvalidArgument) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -421,7 +421,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -437,7 +437,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrInvalidArgument) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -484,7 +484,7 @@ func (Action) ListVariables(ctx *context.APIContext) { ListOptions: utils.GetListOptions(ctx), }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -581,7 +581,7 @@ func ListActionTasks(ctx *context.APIContext) { RepoID: ctx.Repo.Repository.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -592,7 +592,7 @@ func ListActionTasks(ctx *context.APIContext) { for i := range tasks { convertedTask, err := convert.ToActionTask(ctx, tasks[i]) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } res.Entries[i] = convertedTask @@ -634,7 +634,7 @@ func ActionsListRepositoryWorkflows(ctx *context.APIContext) { workflows, err := actions_service.ListActionWorkflows(ctx) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -683,7 +683,7 @@ func ActionsGetWorkflow(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -731,7 +731,7 @@ func ActionsDisableWorkflow(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -810,7 +810,7 @@ func ActionsDispatchWorkflow(ctx *context.APIContext) { } else if errors.Is(err, util.ErrPermissionDenied) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -860,7 +860,7 @@ func ActionsEnableWorkflow(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -1218,7 +1218,7 @@ func DownloadArtifactRaw(ctx *context.APIContext) { if actions.IsArtifactV4(art) { err := actions.DownloadArtifactV4(ctx.Base, art) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } return diff --git a/routers/api/v1/repo/avatar.go b/routers/api/v1/repo/avatar.go index abfaace300..593460586f 100644 --- a/routers/api/v1/repo/avatar.go +++ b/routers/api/v1/repo/avatar.go @@ -50,7 +50,7 @@ func UpdateAvatar(ctx *context.APIContext) { err = repo_service.UploadAvatar(ctx, ctx.Repo.Repository, content) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } ctx.Status(http.StatusNoContent) @@ -81,7 +81,7 @@ func DeleteAvatar(ctx *context.APIContext) { // "$ref": "#/responses/notFound" err := repo_service.DeleteAvatar(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index a76ffc578f..5430c1a266 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -65,26 +65,26 @@ func GetBranch(ctx *context.APIContext) { if git.IsErrBranchNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } c, err := branch.GetCommit() if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branchName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -141,7 +141,7 @@ func DeleteBranch(ctx *context.APIContext) { IsDeletedBranch: optional.Some(false), }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch @@ -161,7 +161,7 @@ func DeleteBranch(ctx *context.APIContext) { case errors.Is(err, git_model.ErrBranchIsProtected): ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected")) default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -223,14 +223,14 @@ func CreateBranch(ctx *context.APIContext) { if len(opt.OldRefName) > 0 { oldCommit, err = ctx.Repo.GitRepo.GetCommit(opt.OldRefName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else if len(opt.OldBranchName) > 0 { //nolint if ctx.Repo.GitRepo.IsBranchExist(opt.OldBranchName) { //nolint oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -240,7 +240,7 @@ func CreateBranch(ctx *context.APIContext) { } else { oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -256,32 +256,32 @@ func CreateBranch(ctx *context.APIContext) { } else if git_model.IsErrBranchNameConflict(err) { ctx.APIError(http.StatusConflict, "The branch with the same name already exists.") } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } branch, err := ctx.Repo.GitRepo.GetBranch(opt.BranchName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } commit, err := branch.GetCommit() if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branch.Name) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, commit, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -325,7 +325,7 @@ func ListBranches(ctx *context.APIContext) { if !ctx.Repo.Repository.IsEmpty { if ctx.Repo.GitRepo == nil { - ctx.APIError(http.StatusInternalServerError, nil) + ctx.APIErrorInternal(nil) return } @@ -337,7 +337,7 @@ func ListBranches(ctx *context.APIContext) { var err error totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch @@ -350,13 +350,13 @@ func ListBranches(ctx *context.APIContext) { rules, err := git_model.FindRepoProtectedBranchRules(ctx, ctx.Repo.Repository.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } branches, err := db.Find[git_model.Branch](ctx, branchOpts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -369,14 +369,14 @@ func ListBranches(ctx *context.APIContext) { totalNumOfBranches-- continue } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } branchProtection := rules.GetFirstMatched(branches[i].Name) apiBranch, err := convert.ToBranch(ctx, ctx.Repo.Repository, branches[i].Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiBranches = append(apiBranches, apiBranch) @@ -450,7 +450,7 @@ func UpdateBranch(ctx *context.APIContext) { case errors.Is(err, git_model.ErrBranchIsProtected): ctx.APIError(http.StatusForbidden, "Branch is protected by glob-based protection rules.") default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -499,7 +499,7 @@ func GetBranchProtection(ctx *context.APIContext) { bpName := ctx.PathParam("name") bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if bp == nil || bp.RepoID != repo.ID { @@ -535,7 +535,7 @@ func ListBranchProtections(ctx *context.APIContext) { repo := ctx.Repo.Repository bps, err := git_model.FindRepoProtectedBranchRules(ctx, repo.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiBps := make([]*api.BranchProtection, len(bps)) @@ -602,7 +602,7 @@ func CreateBranchProtection(ctx *context.APIContext) { protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, ruleName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if protectBranch != nil { ctx.APIError(http.StatusForbidden, "Branch protection already exist") @@ -620,7 +620,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } forcePushAllowlistUsers, err := user_model.GetUserIDsByNames(ctx, form.ForcePushAllowlistUsernames, false) @@ -629,7 +629,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } mergeWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false) @@ -638,7 +638,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false) @@ -647,7 +647,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } var whitelistTeams, forcePushAllowlistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64 @@ -658,7 +658,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } forcePushAllowlistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ForcePushAllowlistTeams, false) @@ -667,7 +667,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false) @@ -676,7 +676,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false) @@ -685,7 +685,7 @@ func CreateBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -726,13 +726,13 @@ func CreateBranchProtection(ctx *context.APIContext) { ApprovalsUserIDs: approvalsWhitelistUsers, ApprovalsTeamIDs: approvalsWhitelistTeams, }); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if isBranchExist { if err := pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, ruleName); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -740,20 +740,20 @@ func CreateBranchProtection(ctx *context.APIContext) { if ctx.Repo.GitRepo == nil { ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } // FIXME: since we only need to recheck files protected rules, we could improve this matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, ruleName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } for _, branchName := range matchedBranches { if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -763,11 +763,11 @@ func CreateBranchProtection(ctx *context.APIContext) { // Reload from db to get all whitelists bp, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, ruleName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if bp == nil || bp.RepoID != ctx.Repo.Repository.ID { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -817,7 +817,7 @@ func EditBranchProtection(ctx *context.APIContext) { bpName := ctx.PathParam("name") protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if protectBranch == nil || protectBranch.RepoID != repo.ID { @@ -935,7 +935,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -948,7 +948,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -961,7 +961,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -974,7 +974,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -990,7 +990,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -1003,7 +1003,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -1016,7 +1016,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -1029,7 +1029,7 @@ func EditBranchProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -1048,7 +1048,7 @@ func EditBranchProtection(ctx *context.APIContext) { ApprovalsTeamIDs: approvalsWhitelistTeams, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1060,7 +1060,7 @@ func EditBranchProtection(ctx *context.APIContext) { if isBranchExist { if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, bpName); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -1068,7 +1068,7 @@ func EditBranchProtection(ctx *context.APIContext) { if ctx.Repo.GitRepo == nil { ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -1076,13 +1076,13 @@ func EditBranchProtection(ctx *context.APIContext) { // FIXME: since we only need to recheck files protected rules, we could improve this matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, protectBranch.RuleName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } for _, branchName := range matchedBranches { if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -1092,11 +1092,11 @@ func EditBranchProtection(ctx *context.APIContext) { // Reload from db to ensure get all whitelists bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if bp == nil || bp.RepoID != ctx.Repo.Repository.ID { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1136,7 +1136,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { bpName := ctx.PathParam("name") bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if bp == nil || bp.RepoID != repo.ID { @@ -1145,7 +1145,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { } if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository, bp.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1189,7 +1189,7 @@ func UpdateBranchProtectionPriories(ctx *context.APIContext) { repo := ctx.Repo.Repository if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1234,7 +1234,7 @@ func MergeUpstream(ctx *context.APIContext) { ctx.APIError(http.StatusNotFound, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, &api.MergeUpstreamResponse{MergeStyle: mergeStyle}) diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index 2e18987888..c397d7972b 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -59,7 +59,7 @@ func ListCollaborators(ctx *context.APIContext) { RepoID: ctx.Repo.Repository.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -108,13 +108,13 @@ func IsCollaborator(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } isColab, err := repo_model.IsCollaborator(ctx, ctx.Repo.Repository.ID, user.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if isColab { @@ -168,13 +168,13 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if !collaborator.IsActive { - ctx.APIError(http.StatusInternalServerError, errors.New("collaborator's account is inactive")) + ctx.APIErrorInternal(errors.New("collaborator's account is inactive")) return } @@ -187,7 +187,7 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) { if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -231,13 +231,13 @@ func DeleteCollaborator(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := repo_service.DeleteCollaboration(ctx, ctx.Repo.Repository, collaborator); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -284,14 +284,14 @@ func GetRepoPermissions(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } permission, err := access_model.GetUserRepoPermission(ctx, ctx.Repo.Repository, collaborator) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -330,7 +330,7 @@ func GetReviewers(ctx *context.APIContext) { reviewers, err := pull_service.GetReviewers(ctx, ctx.Repo.Repository, ctx.Doer.ID, 0) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, reviewers)) @@ -362,7 +362,7 @@ func GetAssignees(ctx *context.APIContext) { assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, assignees)) diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index be21cca159..03489d777b 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -79,13 +79,13 @@ func getCommit(ctx *context.APIContext, identifier string, toCommitOpts convert. ctx.APIErrorNotFound(identifier) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, toCommitOpts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, json) @@ -182,20 +182,20 @@ func GetAllCommits(ctx *context.APIContext) { // no sha supplied - use default branch head, err := ctx.Repo.GitRepo.GetHEADBranch() if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(head.Name) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { // get commit specified by sha baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha) if err != nil { - ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err) + ctx.NotFoundOrServerError(err) return } } @@ -207,14 +207,14 @@ func GetAllCommits(ctx *context.APIContext) { Revision: []string{baseCommit.ID.String()}, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } // Query commits commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -231,7 +231,7 @@ func GetAllCommits(ctx *context.APIContext) { }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if commitsCountTotal == 0 { ctx.APIErrorNotFound("FileCommitsCount", nil) @@ -246,7 +246,7 @@ func GetAllCommits(ctx *context.APIContext) { Page: listOptions.Page, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -259,7 +259,7 @@ func GetAllCommits(ctx *context.APIContext) { // Create json struct apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, convert.ParseCommitOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -320,7 +320,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) { ctx.APIErrorNotFound(sha) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -359,17 +359,17 @@ func GetCommitPullRequest(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err = pr.LoadBaseRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = pr.LoadHeadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer)) diff --git a/routers/api/v1/repo/compare.go b/routers/api/v1/repo/compare.go index 588f5f7919..6d427c8073 100644 --- a/routers/api/v1/repo/compare.go +++ b/routers/api/v1/repo/compare.go @@ -47,7 +47,7 @@ func CompareDiff(ctx *context.APIContext) { var err error ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } diff --git a/routers/api/v1/repo/download.go b/routers/api/v1/repo/download.go index d5d78ea52f..20901badfb 100644 --- a/routers/api/v1/repo/download.go +++ b/routers/api/v1/repo/download.go @@ -31,7 +31,7 @@ func DownloadArchive(ctx *context.APIContext) { var err error ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index 5fd4c27d67..7e6a7ef087 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -84,7 +84,7 @@ func GetRawFile(ctx *context.APIContext) { ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry))) if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } @@ -231,7 +231,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn if git.IsErrNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, nil, nil } @@ -243,7 +243,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil, nil } when := &latestCommit.Committer.When @@ -284,7 +284,7 @@ func GetArchive(ctx *context.APIContext) { var err error ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -389,7 +389,7 @@ func GetEditorconfig(ctx *context.APIContext) { if git.IsErrNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -736,7 +736,7 @@ func handleCreateOrUpdateFileError(ctx *context.APIContext, err error) { return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } // Called from both CreateFile or UpdateFile to handle both @@ -887,7 +887,7 @@ func DeleteFile(ctx *context.APIContext) { ctx.APIError(http.StatusForbidden, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } else { fileResponse := files_service.GetFileResponseFromFilesResponse(filesResponse, 0) ctx.JSON(http.StatusOK, fileResponse) // FIXME on APIv2: return http.StatusNoContent @@ -929,7 +929,7 @@ func GetContents(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if !canReadFiles(ctx.Repo) { - ctx.APIError(http.StatusInternalServerError, repo_model.ErrUserDoesNotHaveAccessToRepo{ + ctx.APIErrorInternal(repo_model.ErrUserDoesNotHaveAccessToRepo{ UserID: ctx.Doer.ID, RepoName: ctx.Repo.Repository.LowerName, }) @@ -944,7 +944,7 @@ func GetContents(ctx *context.APIContext) { ctx.APIErrorNotFound("GetContentsOrList", err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } else { ctx.JSON(http.StatusOK, fileList) } diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index ce236d2a04..58f66954e1 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -57,15 +57,15 @@ func ListForks(ctx *context.APIContext) { forks, total, err := repo_service.FindForks(ctx, ctx.Repo.Repository, ctx.Doer, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := repo_model.RepositoryList(forks).LoadOwners(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := repo_model.RepositoryList(forks).LoadUnits(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -73,7 +73,7 @@ func ListForks(ctx *context.APIContext) { for i, fork := range forks { permission, err := access_model.GetUserRepoPermission(ctx, fork, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiForks[i] = convert.ToRepo(ctx, fork, permission) @@ -128,14 +128,14 @@ func CreateFork(ctx *context.APIContext) { if organization.IsErrOrgNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if !ctx.Doer.IsAdmin { isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !isMember { ctx.APIError(http.StatusForbidden, fmt.Sprintf("User is no Member of Organisation '%s'", org.Name)) @@ -163,7 +163,7 @@ func CreateFork(ctx *context.APIContext) { } else if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/repo/git_hook.go b/routers/api/v1/repo/git_hook.go index 10e8aa6474..487c74e183 100644 --- a/routers/api/v1/repo/git_hook.go +++ b/routers/api/v1/repo/git_hook.go @@ -40,7 +40,7 @@ func ListGitHooks(ctx *context.APIContext) { hooks, err := ctx.Repo.GitRepo.Hooks() if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -86,7 +86,7 @@ func GetGitHook(ctx *context.APIContext) { if errors.Is(err, git.ErrNotValidHook) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -133,14 +133,14 @@ func EditGitHook(ctx *context.APIContext) { if errors.Is(err, git.ErrNotValidHook) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } hook.Content = form.Content if err = hook.Update(); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -182,14 +182,14 @@ func DeleteGitHook(ctx *context.APIContext) { if errors.Is(err, git.ErrNotValidHook) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } hook.Content = "" if err = hook.Update(); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/git_ref.go b/routers/api/v1/repo/git_ref.go index e2030ac296..f042e9e344 100644 --- a/routers/api/v1/repo/git_ref.go +++ b/routers/api/v1/repo/git_ref.go @@ -78,7 +78,7 @@ func GetGitRefs(ctx *context.APIContext) { func getGitRefsInternal(ctx *context.APIContext, filter string) { refs, lastMethodName, err := utils.GetGitRefs(ctx, filter) if err != nil { - ctx.APIError(http.StatusInternalServerError, fmt.Errorf("%s: %w", lastMethodName, err)) + ctx.APIErrorInternal(fmt.Errorf("%s: %w", lastMethodName, err)) return } diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go index 241ca6a732..ac47e15d64 100644 --- a/routers/api/v1/repo/hook.go +++ b/routers/api/v1/repo/hook.go @@ -189,7 +189,7 @@ func TestHook(ctx *context.APIContext) { Pusher: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone), Sender: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone), }); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -300,7 +300,7 @@ func DeleteHook(ctx *context.APIContext) { if webhook.IsErrWebhookNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 04da46a1a3..c9575ff98a 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -172,7 +172,7 @@ func SearchIssues(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -191,7 +191,7 @@ func SearchIssues(ctx *context.APIContext) { if organization.IsErrTeamNotExist(err) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -204,7 +204,7 @@ func SearchIssues(ctx *context.APIContext) { } repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if len(repoIDs) == 0 { @@ -237,7 +237,7 @@ func SearchIssues(ctx *context.APIContext) { } includedAnyLabels, err = issues_model.GetLabelIDsByNames(ctx, includedLabelNames) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -251,7 +251,7 @@ func SearchIssues(ctx *context.APIContext) { } includedMilestones, err = issues_model.GetMilestoneIDsByNames(ctx, includedMilestoneNames) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -312,12 +312,12 @@ func SearchIssues(ctx *context.APIContext) { ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } issues, err := issues_model.GetIssuesByIDs(ctx, ids, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -428,7 +428,7 @@ func ListIssues(ctx *context.APIContext) { if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 { labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, splitted) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -444,7 +444,7 @@ func ListIssues(ctx *context.APIContext) { continue } if !issues_model.IsErrMilestoneNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } id, err := strconv.ParseInt(part[i], 10, 64) @@ -459,7 +459,7 @@ func ListIssues(ctx *context.APIContext) { if issues_model.IsErrMilestoneNotExist(err) { continue } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } @@ -549,12 +549,12 @@ func ListIssues(ctx *context.APIContext) { ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } issues, err := issues_model.GetIssuesByIDs(ctx, ids, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -618,7 +618,7 @@ func GetIssue(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -693,7 +693,7 @@ func CreateIssue(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err)) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -702,13 +702,13 @@ func CreateIssue(ctx *context.APIContext) { for _, aID := range assigneeIDs { assignee, err := user_model.GetUserByID(ctx, aID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } valid, err := access_model.CanBeAssigned(ctx, assignee, ctx.Repo.Repository, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if !valid { @@ -727,7 +727,7 @@ func CreateIssue(ctx *context.APIContext) { } else if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -738,7 +738,7 @@ func CreateIssue(ctx *context.APIContext) { ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue because it still has open dependencies") return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -746,7 +746,7 @@ func CreateIssue(ctx *context.APIContext) { // Refetch from database to assign some automatic values issue, err = issues_model.GetIssueByID(ctx, issue.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, ctx.Doer, issue)) @@ -798,7 +798,7 @@ func EditIssue(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -807,7 +807,7 @@ func EditIssue(ctx *context.APIContext) { err = issue.LoadAttributes(ctx) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -819,7 +819,7 @@ func EditIssue(ctx *context.APIContext) { if len(form.Title) > 0 { err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -831,14 +831,14 @@ func EditIssue(ctx *context.APIContext) { return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } if form.Ref != nil { err = issue_service.ChangeIssueRef(ctx, issue, ctx.Doer, *form.Ref) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -860,7 +860,7 @@ func EditIssue(ctx *context.APIContext) { } if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } issue.DeadlineUnix = deadlineUnix @@ -885,7 +885,7 @@ func EditIssue(ctx *context.APIContext) { if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -896,14 +896,14 @@ func EditIssue(ctx *context.APIContext) { oldMilestoneID := issue.MilestoneID issue.MilestoneID = *form.Milestone if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } if form.State != nil { if issue.IsPull { if err := issue.LoadPullRequest(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if issue.PullRequest.HasMerged { @@ -965,13 +965,13 @@ func DeleteIssue(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1021,7 +1021,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -1033,7 +1033,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) { deadlineUnix, _ := common.ParseAPIDeadlineToEndOfDay(form.Deadline) if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1052,12 +1052,12 @@ func closeOrReopenIssue(ctx *context.APIContext, issue *issues_model.Issue, stat ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue or pull request because it still has open dependencies") return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else if state == api.StateOpen && issue.IsClosed { if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } diff --git a/routers/api/v1/repo/issue_attachment.go b/routers/api/v1/repo/issue_attachment.go index b063054424..3f751a295c 100644 --- a/routers/api/v1/repo/issue_attachment.go +++ b/routers/api/v1/repo/issue_attachment.go @@ -104,7 +104,7 @@ func ListIssueAttachments(ctx *context.APIContext) { } if err := issue.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -171,7 +171,7 @@ func CreateIssueAttachment(ctx *context.APIContext) { // Get uploaded file from request file, header, err := ctx.Req.FormFile("attachment") if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } defer file.Close() @@ -191,7 +191,7 @@ func CreateIssueAttachment(ctx *context.APIContext) { if upload.IsErrFileTypeForbidden(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -199,7 +199,7 @@ func CreateIssueAttachment(ctx *context.APIContext) { issue.Attachments = append(issue.Attachments, attachment) if err := issue_service.ChangeContent(ctx, issue, ctx.Doer, issue.Content, issue.ContentVersion); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -268,7 +268,7 @@ func EditIssueAttachment(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -319,7 +319,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) { } if err := repo_model.DeleteAttachment(ctx, attachment, true); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -329,7 +329,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) { func getIssueFromContext(ctx *context.APIContext) *issues_model.Issue { issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) if err != nil { - ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err) + ctx.NotFoundOrServerError(err) return nil } @@ -354,7 +354,7 @@ func getIssueAttachmentSafeWrite(ctx *context.APIContext) *repo_model.Attachment func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *issues_model.Issue) *repo_model.Attachment { attachment, err := repo_model.GetAttachmentByID(ctx, ctx.PathParamInt64("attachment_id")) if err != nil { - ctx.NotFoundOrServerError("GetAttachmentByID", repo_model.IsErrAttachmentNotExist, err) + ctx.NotFoundOrServerError(err) return nil } if !attachmentBelongsToRepoOrIssue(ctx, attachment, issue) { diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 6efa4ee6b5..0c572a06a8 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -70,7 +70,7 @@ func ListIssueComments(ctx *context.APIContext) { } issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) { @@ -89,7 +89,7 @@ func ListIssueComments(ctx *context.APIContext) { comments, err := issues_model.FindComments(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -100,12 +100,12 @@ func ListIssueComments(ctx *context.APIContext) { } if err := comments.LoadPosters(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := comments.LoadAttachments(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -174,7 +174,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) { } issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } issue.Repo = ctx.Repo.Repository @@ -189,12 +189,12 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) { comments, err := issues_model.FindComments(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := comments.LoadPosters(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -303,7 +303,7 @@ func ListRepoIssueComments(ctx *context.APIContext) { comments, err := issues_model.FindComments(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -314,21 +314,21 @@ func ListRepoIssueComments(ctx *context.APIContext) { } if err = comments.LoadPosters(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiComments := make([]*api.Comment, len(comments)) if err := comments.LoadIssues(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := comments.LoadAttachments(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if _, err := comments.Issues().LoadRepositories(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } for i := range comments { @@ -382,7 +382,7 @@ func CreateIssueComment(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.CreateIssueCommentOption) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -401,7 +401,7 @@ func CreateIssueComment(ctx *context.APIContext) { if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -450,7 +450,7 @@ func GetIssueComment(ctx *context.APIContext) { if issues_model.IsErrCommentNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -475,7 +475,7 @@ func GetIssueComment(ctx *context.APIContext) { } if err := comment.LoadPoster(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -584,13 +584,13 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) if issues_model.IsErrCommentNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := comment.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -615,7 +615,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -701,13 +701,13 @@ func deleteIssueComment(ctx *context.APIContext) { if issues_model.IsErrCommentNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := comment.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -725,7 +725,7 @@ func deleteIssueComment(ctx *context.APIContext) { } if err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/issue_comment_attachment.go b/routers/api/v1/repo/issue_comment_attachment.go index 3dbfa8177a..5f660c5750 100644 --- a/routers/api/v1/repo/issue_comment_attachment.go +++ b/routers/api/v1/repo/issue_comment_attachment.go @@ -109,7 +109,7 @@ func ListIssueCommentAttachments(ctx *context.APIContext) { } if err := comment.LoadAttachments(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -179,7 +179,7 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) { // Get uploaded file from request file, header, err := ctx.Req.FormFile("attachment") if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } defer file.Close() @@ -200,13 +200,13 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) { if upload.IsErrFileTypeForbidden(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := comment.LoadAttachments(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -282,7 +282,7 @@ func EditIssueCommentAttachment(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, attach) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach)) @@ -331,7 +331,7 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) { } if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -340,11 +340,11 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) { func getIssueCommentSafe(ctx *context.APIContext) *issues_model.Comment { comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id")) if err != nil { - ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err) + ctx.NotFoundOrServerError(err) return nil } if err := comment.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil } if comment.Issue == nil || comment.Issue.RepoID != ctx.Repo.Repository.ID { @@ -385,7 +385,7 @@ func canUserWriteIssueCommentAttachment(ctx *context.APIContext, comment *issues func getIssueCommentAttachmentSafeRead(ctx *context.APIContext, comment *issues_model.Comment) *repo_model.Attachment { attachment, err := repo_model.GetAttachmentByID(ctx, ctx.PathParamInt64("attachment_id")) if err != nil { - ctx.NotFoundOrServerError("GetAttachmentByID", repo_model.IsErrAttachmentNotExist, err) + ctx.NotFoundOrServerError(err) return nil } if !attachmentBelongsToRepoOrComment(ctx, attachment, comment) { diff --git a/routers/api/v1/repo/issue_dependency.go b/routers/api/v1/repo/issue_dependency.go index ac177100b9..2048c76ea0 100644 --- a/routers/api/v1/repo/issue_dependency.go +++ b/routers/api/v1/repo/issue_dependency.go @@ -66,7 +66,7 @@ func GetIssueDependencies(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound("IsErrIssueNotExist", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -98,7 +98,7 @@ func GetIssueDependencies(ctx *context.APIContext) { PageSize: limit, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -342,7 +342,7 @@ func GetIssueBlocks(ctx *context.APIContext) { deps, err := issue.BlockingDependencies(ctx) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -504,7 +504,7 @@ func getParamsIssue(ctx *context.APIContext) *issues_model.Issue { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound("IsErrIssueNotExist", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil } @@ -525,7 +525,7 @@ func getFormIssue(ctx *context.APIContext, form *api.IssueMeta) *issues_model.Is if repo_model.IsErrRepoNotExist(err) { ctx.APIErrorNotFound("IsErrRepoNotExist", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil } @@ -538,7 +538,7 @@ func getFormIssue(ctx *context.APIContext, form *api.IssueMeta) *issues_model.Is if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound("IsErrIssueNotExist", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil } @@ -553,7 +553,7 @@ func getPermissionForRepo(ctx *context.APIContext, repo *repo_model.Repository) perm, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil } @@ -581,7 +581,7 @@ func createIssueDependency(ctx *context.APIContext, target, dependency *issues_m err := issues_model.CreateIssueDependency(ctx, ctx.Doer, target, dependency) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -607,7 +607,7 @@ func removeIssueDependency(ctx *context.APIContext, target, dependency *issues_m err := issues_model.RemoveIssueDependency(ctx, ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go index 3715a8e952..f8e14e0490 100644 --- a/routers/api/v1/repo/issue_label.go +++ b/routers/api/v1/repo/issue_label.go @@ -52,13 +52,13 @@ func ListIssueLabels(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := issue.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -110,13 +110,13 @@ func AddIssueLabels(ctx *context.APIContext) { } if err = issue_service.AddLabels(ctx, issue, ctx.Doer, labels); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -168,7 +168,7 @@ func DeleteIssueLabel(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -183,13 +183,13 @@ func DeleteIssueLabel(ctx *context.APIContext) { if issues_model.IsErrLabelNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := issue_service.RemoveLabel(ctx, issue, ctx.Doer, label); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -240,13 +240,13 @@ func ReplaceIssueLabels(ctx *context.APIContext) { } if err := issue_service.ReplaceLabels(ctx, issue, ctx.Doer, labels); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -290,7 +290,7 @@ func ClearIssueLabels(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -301,7 +301,7 @@ func ClearIssueLabels(ctx *context.APIContext) { } if err := issue_service.ClearLabels(ctx, issue, ctx.Doer); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -314,7 +314,7 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, nil, err } @@ -347,14 +347,14 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) if len(labelNames) > 0 { repoLabelIDs, err := issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil, err } labelIDs = append(labelIDs, repoLabelIDs...) if ctx.Repo.Owner.IsOrganization() { orgLabelIDs, err := issues_model.GetLabelIDsInOrgByNames(ctx, ctx.Repo.Owner.ID, labelNames) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil, err } labelIDs = append(labelIDs, orgLabelIDs...) @@ -363,7 +363,7 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs, "id", "repo_id", "org_id", "name", "exclusive") if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil, err } diff --git a/routers/api/v1/repo/issue_pin.go b/routers/api/v1/repo/issue_pin.go index 5e55b7c2d6..71985ac765 100644 --- a/routers/api/v1/repo/issue_pin.go +++ b/routers/api/v1/repo/issue_pin.go @@ -48,7 +48,7 @@ func PinIssue(ctx *context.APIContext) { } else if issues_model.IsErrIssueMaxPinReached(err) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -56,13 +56,13 @@ func PinIssue(ctx *context.APIContext) { // If we don't do this, it will crash when trying to add the pin event to the comment history err = issue.LoadRepo(ctx) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } err = issues_model.PinIssue(ctx, issue, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -103,7 +103,7 @@ func UnpinIssue(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -111,13 +111,13 @@ func UnpinIssue(ctx *context.APIContext) { // If we don't do this, it will crash when trying to add the unpin event to the comment history err = issue.LoadRepo(ctx) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } err = issues_model.UnpinIssue(ctx, issue, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -164,14 +164,14 @@ func MoveIssuePin(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } err = issues_model.MovePin(ctx, issue, int(ctx.PathParamInt64("position"))) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -203,7 +203,7 @@ func ListPinnedIssues(ctx *context.APIContext) { // "$ref": "#/responses/notFound" issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -235,29 +235,29 @@ func ListPinnedPullRequests(ctx *context.APIContext) { // "$ref": "#/responses/notFound" issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiPrs := make([]*api.PullRequest, len(issues)) if err := issues.LoadPullRequests(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } for i, currentIssue := range issues { pr := currentIssue.PullRequest if err = pr.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = pr.LoadBaseRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = pr.LoadHeadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -295,13 +295,13 @@ func AreNewIssuePinsAllowed(ctx *context.APIContext) { pinsAllowed.Issues, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } pinsAllowed.PullRequests, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go index ce669e410a..e535b5e009 100644 --- a/routers/api/v1/repo/issue_reaction.go +++ b/routers/api/v1/repo/issue_reaction.go @@ -56,13 +56,13 @@ func GetIssueCommentReactions(ctx *context.APIContext) { if issues_model.IsErrCommentNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := comment.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -78,12 +78,12 @@ func GetIssueCommentReactions(ctx *context.APIContext) { reactions, _, err := issues_model.FindCommentReactions(ctx, comment.IssueID, comment.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } _, err = reactions.LoadUsers(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -193,13 +193,13 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp if issues_model.IsErrCommentNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err = comment.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -231,7 +231,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp Created: reaction.CreatedUnix.AsTime(), }) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -245,7 +245,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp // DeleteIssueCommentReaction part err = issues_model.DeleteCommentReaction(ctx, ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } // ToDo respond 204 @@ -300,7 +300,7 @@ func GetIssueReactions(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -312,12 +312,12 @@ func GetIssueReactions(ctx *context.APIContext) { reactions, count, err := issues_model.FindIssueReactions(ctx, issue.ID, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } _, err = reactions.LoadUsers(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -424,7 +424,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -447,7 +447,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i Created: reaction.CreatedUnix.AsTime(), }) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -461,7 +461,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i // DeleteIssueReaction part err = issues_model.DeleteIssueReaction(ctx, ctx.Doer.ID, issue.ID, form.Reaction) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } // ToDo respond 204 diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go index 0a29dd2aa1..b18e172b37 100644 --- a/routers/api/v1/repo/issue_stopwatch.go +++ b/routers/api/v1/repo/issue_stopwatch.go @@ -55,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) { } if err := issues_model.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -104,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) { } if err := issues_model.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -153,7 +153,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) { } if err := issues_model.CancelStopwatch(ctx, ctx.Doer, issue); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -166,7 +166,7 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_m if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, err @@ -220,7 +220,7 @@ func GetStopwatches(ctx *context.APIContext) { sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -232,7 +232,7 @@ func GetStopwatches(ctx *context.APIContext) { apiSWs, err := convert.ToStopWatches(ctx, sws) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go index acf72c64cd..21e549496d 100644 --- a/routers/api/v1/repo/issue_subscription.go +++ b/routers/api/v1/repo/issue_subscription.go @@ -109,7 +109,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return @@ -120,7 +120,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { if user_model.IsErrUserNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return @@ -134,7 +134,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { current, err := issues_model.CheckIssueWatch(ctx, user, issue) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -146,7 +146,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { // Update watch state if err := issues_model.CreateOrUpdateIssueWatch(ctx, user.ID, issue.ID, watch); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -190,7 +190,7 @@ func CheckIssueSubscription(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return @@ -256,7 +256,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return @@ -264,7 +264,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { iwl, err := issues_model.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -275,7 +275,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { users, err := user_model.GetUsersByIDs(ctx, userIDs) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiUsers := make([]*api.User, 0, len(users)) @@ -285,7 +285,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { count, err := issues_model.CountIssueWatchers(ctx, issue.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 8cead42267..dbb2afa920 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -80,7 +80,7 @@ func ListTrackedTimes(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -97,7 +97,7 @@ func ListTrackedTimes(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusNotFound, err) } else if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } opts.UserID = user.ID @@ -129,11 +129,11 @@ func ListTrackedTimes(ctx *context.APIContext) { trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = trackedTimes.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -186,7 +186,7 @@ func AddTime(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -206,7 +206,7 @@ func AddTime(ctx *context.APIContext) { // allow only RepoAdmin, Admin and User to add time user, err = user_model.GetUserByName(ctx, form.User) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } } @@ -218,11 +218,11 @@ func AddTime(ctx *context.APIContext) { trackedTime, err := issues_model.AddTime(ctx, user, issue, form.Time, created) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = trackedTime.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToTrackedTime(ctx, user, trackedTime)) @@ -269,7 +269,7 @@ func ResetIssueTime(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -288,7 +288,7 @@ func ResetIssueTime(ctx *context.APIContext) { if db.IsErrNotExist(err) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -342,7 +342,7 @@ func DeleteTime(ctx *context.APIContext) { if issues_model.IsErrIssueNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -362,7 +362,7 @@ func DeleteTime(ctx *context.APIContext) { ctx.APIErrorNotFound(err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if time.Deleted { @@ -378,7 +378,7 @@ func DeleteTime(ctx *context.APIContext) { err = issues_model.DeleteTime(ctx, time) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -427,7 +427,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -448,11 +448,11 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = trackedTimes.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, ctx.Doer, trackedTimes)) @@ -525,7 +525,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusNotFound, err) } else if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } opts.UserID = user.ID @@ -558,11 +558,11 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = trackedTimes.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -619,12 +619,12 @@ func ListMyTrackedTimes(ctx *context.APIContext) { trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = trackedTimes.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index f6f7b01585..8cb61e9e0c 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -100,7 +100,7 @@ func ListDeployKeys(ctx *context.APIContext) { apiKeys := make([]*api.DeployKey, len(keys)) for i := range keys { if err := keys[i].GetContent(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiKeys[i] = convert.ToDeployKey(apiLink, keys[i]) @@ -148,7 +148,7 @@ func GetDeployKey(ctx *context.APIContext) { if asymkey_model.IsErrDeployKeyNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -160,7 +160,7 @@ func GetDeployKey(ctx *context.APIContext) { } if err = key.GetContent(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -195,7 +195,7 @@ func HandleAddKeyError(ctx *context.APIContext, err error) { case asymkey_model.IsErrDeployKeyNameAlreadyUsed(err): ctx.APIError(http.StatusUnprocessableEntity, "A key with the same name already exists") default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } @@ -283,7 +283,7 @@ func DeleteDeploykey(ctx *context.APIContext) { if asymkey_model.IsErrKeyAccessDenied(err) { ctx.APIError(http.StatusForbidden, "You do not have access to this key") } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 357718628f..4f79d42595 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -51,7 +51,7 @@ func ListLabels(ctx *context.APIContext) { labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -109,7 +109,7 @@ func GetLabel(ctx *context.APIContext) { if issues_model.IsErrRepoLabelNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -166,7 +166,7 @@ func CreateLabel(ctx *context.APIContext) { } l.SetArchived(form.IsArchived) if err := issues_model.NewLabel(ctx, l); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -217,7 +217,7 @@ func EditLabel(ctx *context.APIContext) { if issues_model.IsErrRepoLabelNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -241,7 +241,7 @@ func EditLabel(ctx *context.APIContext) { } l.SetArchived(form.IsArchived != nil && *form.IsArchived) if err := issues_model.UpdateLabel(ctx, l); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -277,7 +277,7 @@ func DeleteLabel(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index 46563b8f22..d7508684a1 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -74,7 +74,7 @@ func Migrate(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -94,7 +94,7 @@ func Migrate(ctx *context.APIContext) { // Check ownership of organization. isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !isOwner { ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.") @@ -129,7 +129,7 @@ func Migrate(ctx *context.APIContext) { if form.LFS && len(form.LFSEndpoint) > 0 { ep := lfs.DetermineEndpoint("", form.LFSEndpoint) if ep == nil { - ctx.APIError(http.StatusInternalServerError, ctx.Tr("repo.migrate.invalid_lfs_endpoint")) + ctx.APIErrorInternal(errors.New("the LFS endpoint is not valid")) return } err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer) @@ -249,7 +249,7 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err } else if strings.Contains(err.Error(), "fatal:") { ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Migration failed: %v.", err)) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } } @@ -269,9 +269,9 @@ func handleRemoteAddrError(ctx *context.APIContext, err error) { case addrErr.IsInvalidPath: ctx.APIError(http.StatusUnprocessableEntity, "Invalid local path, it does not exist or not a directory.") default: - ctx.APIError(http.StatusInternalServerError, "Unknown error type (ErrInvalidCloneAddr): "+err.Error()) + ctx.APIErrorInternal(fmt.Errorf("unknown error type (ErrInvalidCloneAddr): %w", err)) } } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 727f7a1a1b..33fa7c4b16 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -74,7 +74,7 @@ func ListMilestones(ctx *context.APIContext) { Name: ctx.FormString("name"), }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -173,7 +173,7 @@ func CreateMilestone(ctx *context.APIContext) { } if err := issues_model.NewMilestone(ctx, milestone); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusCreated, convert.ToAPIMilestone(milestone)) @@ -233,7 +233,7 @@ func EditMilestone(ctx *context.APIContext) { } if err := issues_model.UpdateMilestone(ctx, milestone, oldIsClosed); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone)) @@ -272,7 +272,7 @@ func DeleteMilestone(ctx *context.APIContext) { } if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, m.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) @@ -288,7 +288,7 @@ func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone { if err == nil { return milestone } else if !issues_model.IsErrMilestoneNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil } } @@ -299,7 +299,7 @@ func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone { ctx.APIErrorNotFound() return nil } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil } diff --git a/routers/api/v1/repo/mirror.go b/routers/api/v1/repo/mirror.go index 59a4a3199a..b5f4c12c50 100644 --- a/routers/api/v1/repo/mirror.go +++ b/routers/api/v1/repo/mirror.go @@ -66,7 +66,7 @@ func MirrorSync(ctx *context.APIContext) { ctx.APIError(http.StatusBadRequest, "Repository is not a mirror") return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -116,7 +116,7 @@ func PushMirrorSync(ctx *context.APIContext) { for _, mirror := range pushMirrors { ok := mirror_service.SyncPushMirror(ctx, mirror.ID) if !ok { - ctx.APIError(http.StatusInternalServerError, "error occurred when syncing push mirror "+mirror.RemoteName) + ctx.APIErrorInternal(errors.New("error occurred when syncing push mirror " + mirror.RemoteName)) return } } @@ -230,7 +230,7 @@ func GetPushMirrorByName(ctx *context.APIContext) { RemoteName: mirrorName, }.ToConds()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !exist { ctx.APIError(http.StatusNotFound, nil) diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go index 084879ba00..dcb512256c 100644 --- a/routers/api/v1/repo/notes.go +++ b/routers/api/v1/repo/notes.go @@ -71,7 +71,7 @@ func getNote(ctx *context.APIContext, identifier string) { if git.IsErrNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -82,7 +82,7 @@ func getNote(ctx *context.APIContext, identifier string) { ctx.APIErrorNotFound(identifier) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -96,7 +96,7 @@ func getNote(ctx *context.APIContext, identifier string) { Files: files, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiNote := api.Note{Message: string(note.Message), Commit: cmt} diff --git a/routers/api/v1/repo/patch.go b/routers/api/v1/repo/patch.go index b03dd1219d..bcf498bf7e 100644 --- a/routers/api/v1/repo/patch.go +++ b/routers/api/v1/repo/patch.go @@ -83,7 +83,7 @@ func ApplyDiffPatch(ctx *context.APIContext) { } if !canWriteFiles(ctx, apiOpts.BranchName) { - ctx.APIError(http.StatusInternalServerError, repo_model.ErrUserDoesNotHaveAccessToRepo{ + ctx.APIErrorInternal(repo_model.ErrUserDoesNotHaveAccessToRepo{ UserID: ctx.Doer.ID, RepoName: ctx.Repo.Repository.LowerName, }) @@ -105,7 +105,7 @@ func ApplyDiffPatch(ctx *context.APIContext) { ctx.APIError(http.StatusNotFound, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } else { ctx.JSON(http.StatusCreated, fileResponse) } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 8809c7ed2d..1f61ac031a 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -108,7 +108,7 @@ func ListPullRequests(ctx *context.APIContext) { labelIDs, err := base.StringsToInt64s(ctx.FormStrings("labels")) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } var posterID int64 @@ -118,7 +118,7 @@ func ListPullRequests(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -134,13 +134,13 @@ func ListPullRequests(ctx *context.APIContext) { PosterID: posterID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiPrs, err := convert.ToAPIPullRequests(ctx, ctx.Repo.Repository, prs, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -184,17 +184,17 @@ func GetPullRequest(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err = pr.LoadBaseRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = pr.LoadHeadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer)) @@ -254,7 +254,7 @@ func GetPullRequestByBaseHead(ctx *context.APIContext) { if repo_model.IsErrRepoNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -269,17 +269,17 @@ func GetPullRequestByBaseHead(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err = pr.LoadBaseRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = pr.LoadHeadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer)) @@ -417,7 +417,7 @@ func CreatePullRequest(ctx *context.APIContext) { ) if err != nil { if !issues_model.IsErrPullRequestNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } else { @@ -436,7 +436,7 @@ func CreatePullRequest(ctx *context.APIContext) { if len(form.Labels) > 0 { labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -448,7 +448,7 @@ func CreatePullRequest(ctx *context.APIContext) { if ctx.Repo.Owner.IsOrganization() { orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -466,7 +466,7 @@ func CreatePullRequest(ctx *context.APIContext) { if issues_model.IsErrMilestoneNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetMilestoneByRepoID: %w", err)) + ctx.APIErrorInternal(fmt.Errorf("GetMilestoneByRepoID: %w", err)) } return } @@ -506,7 +506,7 @@ func CreatePullRequest(ctx *context.APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err)) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -514,13 +514,13 @@ func CreatePullRequest(ctx *context.APIContext) { for _, aID := range assigneeIDs { assignee, err := user_model.GetUserByID(ctx, aID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } valid, err := access_model.CanBeAssigned(ctx, assignee, repo, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if !valid { @@ -549,7 +549,7 @@ func CreatePullRequest(ctx *context.APIContext) { } else if errors.Is(err, issues_model.ErrMustCollaborator) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -608,21 +608,21 @@ func EditPullRequest(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } err = pr.LoadIssue(ctx) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } issue := pr.Issue issue.Repo = ctx.Repo.Repository if err := issue.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -634,7 +634,7 @@ func EditPullRequest(ctx *context.APIContext) { if len(form.Title) > 0 { err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -646,7 +646,7 @@ func EditPullRequest(ctx *context.APIContext) { return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -661,7 +661,7 @@ func EditPullRequest(ctx *context.APIContext) { } if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } issue.DeadlineUnix = deadlineUnix @@ -683,7 +683,7 @@ func EditPullRequest(ctx *context.APIContext) { } else if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -694,7 +694,7 @@ func EditPullRequest(ctx *context.APIContext) { oldMilestoneID := issue.MilestoneID issue.MilestoneID = form.Milestone if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -702,14 +702,14 @@ func EditPullRequest(ctx *context.APIContext) { if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil { labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if ctx.Repo.Owner.IsOrganization() { orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -717,7 +717,7 @@ func EditPullRequest(ctx *context.APIContext) { } if err = issues_model.ReplaceIssueLabels(ctx, issue, labels, ctx.Doer); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -776,7 +776,7 @@ func EditPullRequest(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -820,7 +820,7 @@ func IsPullRequestMerged(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -878,18 +878,18 @@ func MergePullRequest(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound("GetPullRequestByIndex", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := pr.LoadHeadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := pr.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } pr.Issue.Repo = ctx.Repo.Repository @@ -897,7 +897,7 @@ func MergePullRequest(ctx *context.APIContext) { if ctx.IsSigned { // Update issue-user. if err = activities_model.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -945,7 +945,7 @@ func MergePullRequest(ctx *context.APIContext) { ctx.JSON(http.StatusConflict, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusOK) @@ -960,7 +960,7 @@ func MergePullRequest(ctx *context.APIContext) { if len(message) == 0 { message, _, err = pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pr, repo_model.MergeStyle(form.Do)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -977,7 +977,7 @@ func MergePullRequest(ctx *context.APIContext) { ctx.APIError(http.StatusConflict, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if scheduled { // nothing more to do ... @@ -1010,7 +1010,7 @@ func MergePullRequest(ctx *context.APIContext) { ctx.APIError(http.StatusConflict, "PushRejected with remote message: "+errPushRej.Message) } } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -1053,7 +1053,7 @@ func MergePullRequest(ctx *context.APIContext) { case errors.Is(err, git_model.ErrBranchIsProtected): ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected")) default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -1094,7 +1094,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) if user_model.IsErrUserNotExist(err) { ctx.APIErrorNotFound("GetUserByName") } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, nil } @@ -1110,7 +1110,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) if headRepo == nil && !isSameRepo { err = baseRepo.GetBaseRepo(ctx) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil } @@ -1132,7 +1132,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } else { headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil } closer = func() { _ = headGitRepo.Close() } @@ -1146,7 +1146,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // user should have permission to read baseRepo's codes and pulls, NOT headRepo's permBase, err := access_model.GetUserRepoPermission(ctx, baseRepo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil } @@ -1160,7 +1160,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // TODO: could the logic be simplified if the headRepo is the same as the baseRepo? Need to think more about it. permHead, err := access_model.GetUserRepoPermission(ctx, headRepo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil } if !permHead.CanRead(unit.TypeCode) { @@ -1184,7 +1184,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseRef.ShortName(), headRef.ShortName(), false, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil } @@ -1238,7 +1238,7 @@ func UpdatePullRequest(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -1249,7 +1249,7 @@ func UpdatePullRequest(ctx *context.APIContext) { } if err = pr.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1259,11 +1259,11 @@ func UpdatePullRequest(ctx *context.APIContext) { } if err = pr.LoadBaseRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = pr.LoadHeadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1271,7 +1271,7 @@ func UpdatePullRequest(ctx *context.APIContext) { allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(ctx, pr, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1291,7 +1291,7 @@ func UpdatePullRequest(ctx *context.APIContext) { ctx.APIError(http.StatusConflict, "rebase failed because of conflict") return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1423,7 +1423,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -1546,7 +1546,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index a351343f10..fb35126a99 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -66,18 +66,18 @@ func ListPullReviews(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound("GetPullRequestByIndex", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err = pr.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err = pr.Issue.LoadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -100,7 +100,7 @@ func ListPullReviews(ctx *context.APIContext) { apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -151,7 +151,7 @@ func GetPullReview(ctx *context.APIContext) { apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -201,7 +201,7 @@ func GetPullReviewComments(ctx *context.APIContext) { apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -261,7 +261,7 @@ func DeletePullReview(ctx *context.APIContext) { } if err := issues_model.DeleteReview(ctx, review); err != nil { - ctx.APIError(http.StatusInternalServerError, fmt.Errorf("can not delete ReviewID: %d", review.ID)) + ctx.APIErrorInternal(fmt.Errorf("can not delete ReviewID: %d", review.ID)) return } @@ -311,7 +311,7 @@ func CreatePullReview(ctx *context.APIContext) { if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound("GetPullRequestByIndex", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -323,7 +323,7 @@ func CreatePullReview(ctx *context.APIContext) { } if err := pr.Issue.LoadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -331,14 +331,14 @@ func CreatePullReview(ctx *context.APIContext) { if opts.CommitID == "" { gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } defer closer.Close() headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -364,7 +364,7 @@ func CreatePullReview(ctx *context.APIContext) { opts.CommitID, nil, ); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -375,7 +375,7 @@ func CreatePullReview(ctx *context.APIContext) { if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -383,7 +383,7 @@ func CreatePullReview(ctx *context.APIContext) { // convert response apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, apiReview) @@ -457,7 +457,7 @@ func SubmitPullReview(ctx *context.APIContext) { headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitRefName()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -467,7 +467,7 @@ func SubmitPullReview(ctx *context.APIContext) { if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -475,7 +475,7 @@ func SubmitPullReview(ctx *context.APIContext) { // convert response apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, apiReview) @@ -484,7 +484,7 @@ func SubmitPullReview(ctx *context.APIContext) { // preparePullReviewType return ReviewType and false or nil and true if an error happen func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest, event api.ReviewStateType, body string, hasComments bool) (issues_model.ReviewType, bool) { if err := pr.LoadIssue(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return -1, true } @@ -538,7 +538,7 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound("GetPullRequestByIndex", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, nil, true } @@ -548,7 +548,7 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues if issues_model.IsErrReviewNotExist(err) { ctx.APIErrorNotFound("GetReviewByID", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, nil, true } @@ -566,7 +566,7 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues } if err := review.LoadAttributes(ctx); err != nil && !user_model.IsErrUserNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil, true } @@ -671,7 +671,7 @@ func parseReviewersByNames(ctx *context.APIContext, reviewerNames, teamReviewerN ctx.APIErrorNotFound("UserNotExist", fmt.Sprintf("User '%s' not exist", r)) return nil, nil } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil } @@ -687,7 +687,7 @@ func parseReviewersByNames(ctx *context.APIContext, reviewerNames, teamReviewerN ctx.APIErrorNotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t)) return nil, nil } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, nil } @@ -703,19 +703,19 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions if issues_model.IsErrPullRequestNotExist(err) { ctx.APIErrorNotFound("GetPullRequestByIndex", err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := pr.Issue.LoadRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } permDoer, err := access_model.GetUserRepoPermission(ctx, pr.Issue.Repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -740,7 +740,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -782,7 +782,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions if isAdd { apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusCreated, apiReviews) @@ -903,19 +903,19 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss, dismissPriors ctx.APIError(http.StatusForbidden, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if review, err = issues_model.GetReviewByID(ctx, review.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } // convert response apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, apiReview) diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index 3d5e51a2c9..36fff126e1 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -53,7 +53,7 @@ func GetRelease(ctx *context.APIContext) { id := ctx.PathParamInt64("id") release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) if err != nil && !repo_model.IsErrReleaseNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err != nil && repo_model.IsErrReleaseNotExist(err) || release.IsTag { @@ -62,7 +62,7 @@ func GetRelease(ctx *context.APIContext) { } if err := release.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)) @@ -93,7 +93,7 @@ func GetLatestRelease(ctx *context.APIContext) { // "$ref": "#/responses/notFound" release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID) if err != nil && !repo_model.IsErrReleaseNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err != nil && repo_model.IsErrReleaseNotExist(err) || @@ -103,7 +103,7 @@ func GetLatestRelease(ctx *context.APIContext) { } if err := release.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)) @@ -161,13 +161,13 @@ func ListReleases(ctx *context.APIContext) { releases, err := db.Find[repo_model.Release](ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } rels := make([]*api.Release, len(releases)) for i, release := range releases { if err := release.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release) @@ -226,7 +226,7 @@ func CreateRelease(ctx *context.APIContext) { rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName) if err != nil { if !repo_model.IsErrReleaseNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } // If target is not provided use default branch @@ -254,7 +254,7 @@ func CreateRelease(ctx *context.APIContext) { } else if git.IsErrNotExist(err) { ctx.APIError(http.StatusNotFound, fmt.Errorf("target \"%v\" not found: %w", rel.Target, err)) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -275,7 +275,7 @@ func CreateRelease(ctx *context.APIContext) { rel.Target = form.Target if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -322,7 +322,7 @@ func EditRelease(ctx *context.APIContext) { id := ctx.PathParamInt64("id") rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) if err != nil && !repo_model.IsErrReleaseNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag { @@ -349,18 +349,18 @@ func EditRelease(ctx *context.APIContext) { rel.IsPrerelease = *form.IsPrerelease } if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } // reload data from database rel, err = repo_model.GetReleaseByID(ctx, id) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := rel.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel)) @@ -399,7 +399,7 @@ func DeleteRelease(ctx *context.APIContext) { id := ctx.PathParamInt64("id") rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) if err != nil && !repo_model.IsErrReleaseNotExist(err) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag { @@ -411,7 +411,7 @@ func DeleteRelease(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag") return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index 7dba703cfa..defde81a1d 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -26,7 +26,7 @@ func checkReleaseMatchRepo(ctx *context.APIContext, releaseID int64) bool { ctx.APIErrorNotFound() return false } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return false } if release.RepoID != ctx.Repo.Repository.ID { @@ -84,7 +84,7 @@ func GetReleaseAttachment(ctx *context.APIContext) { ctx.APIErrorNotFound() return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if attach.ReleaseID != releaseID { @@ -133,7 +133,7 @@ func ListReleaseAttachments(ctx *context.APIContext) { ctx.APIErrorNotFound() return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if release.RepoID != ctx.Repo.Repository.ID { @@ -141,7 +141,7 @@ func ListReleaseAttachments(ctx *context.APIContext) { return } if err := release.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release).Attachments) @@ -212,7 +212,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) { if strings.HasPrefix(strings.ToLower(ctx.Req.Header.Get("Content-Type")), "multipart/form-data") { file, header, err := ctx.Req.FormFile("attachment") if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } defer file.Close() @@ -245,7 +245,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) { ctx.APIError(http.StatusBadRequest, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -311,7 +311,7 @@ func EditReleaseAttachment(ctx *context.APIContext) { ctx.APIErrorNotFound() return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if attach.ReleaseID != releaseID { @@ -329,7 +329,7 @@ func EditReleaseAttachment(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, attach) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach)) @@ -384,7 +384,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) { ctx.APIErrorNotFound() return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if attach.ReleaseID != releaseID { @@ -395,7 +395,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) { // FIXME Should prove the existence of the given repo, but results in unnecessary database requests if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/repo/release_tags.go b/routers/api/v1/repo/release_tags.go index 19f8bac9e8..b5e7d83b2a 100644 --- a/routers/api/v1/repo/release_tags.go +++ b/routers/api/v1/repo/release_tags.go @@ -49,7 +49,7 @@ func GetReleaseByTag(ctx *context.APIContext) { ctx.APIErrorNotFound() return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -59,7 +59,7 @@ func GetReleaseByTag(ctx *context.APIContext) { } if err = release.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)) @@ -102,7 +102,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) { ctx.APIErrorNotFound() return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -116,7 +116,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag") return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 72b841ff6b..d418b8e4b5 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -271,7 +271,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre label.IsErrTemplateLoad(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -279,7 +279,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre // reload repo from db to get a real state after creation repo, err = repo_model.GetRepositoryByID(ctx, repo.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner})) @@ -395,7 +395,7 @@ func Generate(ctx *context.APIContext) { return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -424,7 +424,7 @@ func Generate(ctx *context.APIContext) { db.IsErrNamePatternNotAllowed(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -500,7 +500,7 @@ func CreateOrgRepo(ctx *context.APIContext) { if organization.IsErrOrgNotExist(err) { ctx.APIError(http.StatusUnprocessableEntity, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -513,7 +513,7 @@ func CreateOrgRepo(ctx *context.APIContext) { if !ctx.Doer.IsAdmin { canCreate, err := org.CanCreateOrgRepo(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !canCreate { ctx.APIError(http.StatusForbidden, "Given user is not allowed to create repository in organization.") @@ -548,7 +548,7 @@ func Get(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if err := ctx.Repo.Repository.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -580,14 +580,14 @@ func GetByID(ctx *context.APIContext) { if repo_model.IsErrRepoNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !permission.HasAnyUnitAccess() { ctx.APIErrorNotFound() @@ -703,7 +703,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err // Visibility of forked repository is forced sync with base repository. if repo.IsFork { if err := repo.GetBaseRepo(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } *opts.Private = repo.BaseRepo.IsPrivate @@ -728,7 +728,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err var err error ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, repo) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } } @@ -738,7 +738,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) { if !repo.IsEmpty { if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, *opts.DefaultBranch); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } updateRepoLicense = true @@ -747,7 +747,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err } if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } @@ -755,7 +755,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err if err := repo_service.AddRepoToLicenseUpdaterQueue(&repo_service.LicenseUpdaterOptions{ RepoID: ctx.Repo.Repository.ID, }); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } } @@ -1024,7 +1024,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { if len(units)+len(deleteUnitTypes) > 0 { if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } } @@ -1046,7 +1046,7 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e if *opts.Archived { if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil { log.Error("Tried to archive a repo: %s", err) - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil { @@ -1056,7 +1056,7 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e } else { if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil { log.Error("Tried to un-archive a repo: %s", err) - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } if ctx.Repo.Repository.UnitEnabled(ctx, unit_model.TypeActions) { @@ -1084,7 +1084,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error { mirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID) if err != nil { log.Error("Failed to get mirror: %s", err) - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return err } @@ -1158,7 +1158,7 @@ func Delete(ctx *context.APIContext) { canDelete, err := repo_module.CanUserDelete(ctx, repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if !canDelete { ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.") @@ -1170,7 +1170,7 @@ func Delete(ctx *context.APIContext) { } if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -1315,7 +1315,7 @@ func ListRepoActivityFeeds(ctx *context.APIContext) { feeds, count, err := feed_service.GetFeeds(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.SetTotalCountHeader(count) diff --git a/routers/api/v1/repo/star.go b/routers/api/v1/repo/star.go index 1e1c416e42..46218e0e28 100644 --- a/routers/api/v1/repo/star.go +++ b/routers/api/v1/repo/star.go @@ -49,7 +49,7 @@ func ListStargazers(ctx *context.APIContext) { stargazers, err := repo_model.GetStargazers(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } users := make([]*api.User, len(stargazers)) diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index e6c7c71782..e1dbb25865 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -65,7 +65,7 @@ func NewCommitStatus(ctx *context.APIContext) { Context: form.Context, } if err := commitstatus_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -203,7 +203,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { State: ctx.FormTrim("state"), }) if err != nil { - ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err)) + ctx.APIErrorInternal(fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err)) return } @@ -266,7 +266,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err)) + ctx.APIErrorInternal(fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err)) return } diff --git a/routers/api/v1/repo/subscriber.go b/routers/api/v1/repo/subscriber.go index e02b0c2ab7..14f296a83d 100644 --- a/routers/api/v1/repo/subscriber.go +++ b/routers/api/v1/repo/subscriber.go @@ -47,7 +47,7 @@ func ListSubscribers(ctx *context.APIContext) { subscribers, err := repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } users := make([]*api.User, len(subscribers)) diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index c0b70b92b2..2e6c1c1023 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -57,7 +57,7 @@ func ListTags(ctx *context.APIContext) { tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -270,7 +270,7 @@ func DeleteTag(ctx *context.APIContext) { ctx.APIErrorNotFound() return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -284,7 +284,7 @@ func DeleteTag(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag") return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -316,7 +316,7 @@ func ListTagProtection(ctx *context.APIContext) { repo := ctx.Repo.Repository pts, err := git_model.GetProtectedTags(ctx, repo.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiPts := make([]*api.TagProtection, len(pts)) @@ -360,7 +360,7 @@ func GetTagProtection(ctx *context.APIContext) { id := ctx.PathParamInt64("id") pt, err := git_model.GetProtectedTagByID(ctx, id) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -424,7 +424,7 @@ func CreateTagProtection(ctx *context.APIContext) { pt, err := git_model.GetProtectedTagByNamePattern(ctx, repo.ID, namePattern) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } else if pt != nil { ctx.APIError(http.StatusForbidden, "Tag protection already exist") @@ -438,7 +438,7 @@ func CreateTagProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -449,7 +449,7 @@ func CreateTagProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -461,18 +461,18 @@ func CreateTagProtection(ctx *context.APIContext) { AllowlistTeamIDs: whitelistTeams, } if err := git_model.InsertProtectedTag(ctx, protectTag); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } pt, err = git_model.GetProtectedTagByID(ctx, protectTag.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if pt == nil || pt.RepoID != repo.ID { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -524,7 +524,7 @@ func EditTagProtection(ctx *context.APIContext) { id := ctx.PathParamInt64("id") pt, err := git_model.GetProtectedTagByID(ctx, id) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -546,7 +546,7 @@ func EditTagProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -560,7 +560,7 @@ func EditTagProtection(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } pt.AllowlistUserIDs = whitelistUsers @@ -568,18 +568,18 @@ func EditTagProtection(ctx *context.APIContext) { err = git_model.UpdateProtectedTag(ctx, pt) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } pt, err = git_model.GetProtectedTagByID(ctx, id) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if pt == nil || pt.RepoID != repo.ID { - ctx.APIError(http.StatusInternalServerError, "New tag protection not found") + ctx.APIErrorInternal(errors.New("new tag protection not found")) return } @@ -619,7 +619,7 @@ func DeleteTagProtection(ctx *context.APIContext) { id := ctx.PathParamInt64("id") pt, err := git_model.GetProtectedTagByID(ctx, id) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -630,7 +630,7 @@ func DeleteTagProtection(ctx *context.APIContext) { err = git_model.DeleteProtectedTag(ctx, pt) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index 0e50f29e15..7b890c9e5c 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -170,7 +170,7 @@ func AcceptTransfer(ctx *context.APIContext) { case errors.Is(err, util.ErrPermissionDenied): ctx.APIError(http.StatusForbidden, err) default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -212,7 +212,7 @@ func RejectTransfer(ctx *context.APIContext) { case errors.Is(err, util.ErrPermissionDenied): ctx.APIError(http.StatusForbidden, err) default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index a913225bb6..8d73383f76 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -82,7 +82,7 @@ func NewWikiPage(ctx *context.APIContext) { } else if repo_model.IsErrWikiAlreadyExist(err) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -155,7 +155,7 @@ func EditWikiPage(ctx *context.APIContext) { form.ContentBase64 = string(content) if err := wiki_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -198,7 +198,7 @@ func getWikiPage(ctx *context.APIContext, wikiName wiki_service.WebPath) *api.Wi // Get last change information. lastCommit, err := wikiRepo.GetCommitByPath(pageFilename) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil } @@ -249,7 +249,7 @@ func DeleteWikiPage(ctx *context.APIContext) { ctx.APIErrorNotFound(err) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -322,7 +322,7 @@ func ListWikiPages(ctx *context.APIContext) { } c, err := wikiRepo.GetCommitByPath(entry.Name()) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } wikiName, err := wiki_service.GitPathToWebPath(entry.Name()) @@ -330,7 +330,7 @@ func ListWikiPages(ctx *context.APIContext) { if repo_model.IsErrWikiInvalidFileName(err) { continue } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } pages = append(pages, wiki_service.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository)) @@ -447,7 +447,7 @@ func ListPageRevisions(ctx *context.APIContext) { Page: page, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -481,7 +481,7 @@ func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) if git.IsErrNotExist(err) || err.Error() == "no such file or directory" { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, nil } @@ -491,7 +491,7 @@ func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) if git.IsErrNotExist(err) { ctx.APIErrorNotFound(err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return wikiRepo, nil } @@ -507,7 +507,7 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) string { } content, err := blob.GetBlobContentBase64() if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return "" } return content diff --git a/routers/api/v1/shared/block.go b/routers/api/v1/shared/block.go index 17be2dde4a..b22f8a74fd 100644 --- a/routers/api/v1/shared/block.go +++ b/routers/api/v1/shared/block.go @@ -21,12 +21,12 @@ func ListBlocks(ctx *context.APIContext, blocker *user_model.User) { BlockerID: blocker.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := user_model.BlockingList(blocks).LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -49,7 +49,7 @@ func CheckUserBlock(ctx *context.APIContext, blocker *user_model.User) { status := http.StatusNotFound blocking, err := user_model.GetBlocking(ctx, blocker.ID, blockee.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if blocking != nil { @@ -70,7 +70,7 @@ func BlockUser(ctx *context.APIContext, blocker *user_model.User) { if errors.Is(err, user_model.ErrCanNotBlock) || errors.Is(err, user_model.ErrBlockOrganization) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -89,7 +89,7 @@ func UnblockUser(ctx *context.APIContext, doer, blocker *user_model.User) { if errors.Is(err, user_model.ErrCanNotUnblock) || errors.Is(err, user_model.ErrBlockOrganization) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/user/action.go b/routers/api/v1/user/action.go index cfc206cac7..1c8e3b6e71 100644 --- a/routers/api/v1/user/action.go +++ b/routers/api/v1/user/action.go @@ -56,7 +56,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -98,7 +98,7 @@ func DeleteSecret(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -145,7 +145,7 @@ func CreateVariable(ctx *context.APIContext) { Name: variableName, }) if err != nil && !errors.Is(err, util.ErrNotExist) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if v != nil && v.ID > 0 { @@ -157,7 +157,7 @@ func CreateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrInvalidArgument) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -204,7 +204,7 @@ func UpdateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -220,7 +220,7 @@ func UpdateVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrInvalidArgument) { ctx.APIError(http.StatusBadRequest, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -257,7 +257,7 @@ func DeleteVariable(ctx *context.APIContext) { } else if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -294,7 +294,7 @@ func GetVariable(ctx *context.APIContext) { if errors.Is(err, util.ErrNotExist) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -338,7 +338,7 @@ func ListVariables(ctx *context.APIContext) { ListOptions: utils.GetListOptions(ctx), }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go index cc1ed8b95f..4ca06ca923 100644 --- a/routers/api/v1/user/app.go +++ b/routers/api/v1/user/app.go @@ -125,7 +125,7 @@ func CreateAccessToken(ctx *context.APIContext) { t.Scope = scope if err := auth_model.NewAccessToken(ctx, t); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusCreated, &api.AccessToken{ @@ -174,7 +174,7 @@ func DeleteAccessToken(ctx *context.APIContext) { UserID: ctx.ContextUser.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -190,7 +190,7 @@ func DeleteAccessToken(ctx *context.APIContext) { } } if tokenID == 0 { - ctx.APIError(http.StatusInternalServerError, nil) + ctx.APIErrorInternal(nil) return } @@ -198,7 +198,7 @@ func DeleteAccessToken(ctx *context.APIContext) { if auth_model.IsErrAccessTokenNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -273,7 +273,7 @@ func ListOauth2Applications(ctx *context.APIContext) { OwnerID: ctx.Doer.ID, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -311,7 +311,7 @@ func DeleteOauth2Application(ctx *context.APIContext) { if auth_model.IsErrOAuthApplicationNotFound(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -344,7 +344,7 @@ func GetOauth2Application(ctx *context.APIContext) { if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -398,7 +398,7 @@ func UpdateOauth2Application(ctx *context.APIContext) { if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/user/avatar.go b/routers/api/v1/user/avatar.go index 028b5e8288..9c7bd57bc0 100644 --- a/routers/api/v1/user/avatar.go +++ b/routers/api/v1/user/avatar.go @@ -38,7 +38,7 @@ func UpdateAvatar(ctx *context.APIContext) { err = user_service.UploadAvatar(ctx, ctx.Doer, content) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -57,7 +57,7 @@ func DeleteAvatar(ctx *context.APIContext) { // "$ref": "#/responses/empty" err := user_service.DeleteAvatar(ctx, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go index b488e457a1..055e5ea419 100644 --- a/routers/api/v1/user/email.go +++ b/routers/api/v1/user/email.go @@ -29,7 +29,7 @@ func ListEmails(ctx *context.APIContext) { emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } apiEmails := make([]*api.Email, len(emails)) @@ -78,14 +78,14 @@ func AddEmail(ctx *context.APIContext) { errMsg := fmt.Sprintf("Email address %q invalid", email) ctx.APIError(http.StatusUnprocessableEntity, errMsg) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -124,7 +124,7 @@ func DeleteEmail(ctx *context.APIContext) { if user_model.IsErrEmailAddressNotExist(err) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go index 83a852062b..0d0c0be7e0 100644 --- a/routers/api/v1/user/follower.go +++ b/routers/api/v1/user/follower.go @@ -26,7 +26,7 @@ func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) { func listUserFollowers(ctx *context.APIContext, u *user_model.User) { users, count, err := user_model.GetUserFollowers(ctx, u, ctx.Doer, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -90,7 +90,7 @@ func ListFollowers(ctx *context.APIContext) { func listUserFollowing(ctx *context.APIContext, u *user_model.User) { users, count, err := user_model.GetUserFollowing(ctx, u, ctx.Doer, utils.GetListOptions(ctx)) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -231,7 +231,7 @@ func Follow(ctx *context.APIContext) { if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -256,7 +256,7 @@ func Unfollow(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if err := user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index f8b5cf08a3..504e74ae10 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -25,12 +25,12 @@ func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) OwnerID: uid, }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := asymkey_model.GPGKeyList(keys).LoadSubKeys(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -121,12 +121,12 @@ func GetGPGKey(ctx *context.APIContext) { if asymkey_model.IsErrGPGKeyNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } if err := key.LoadSubKeys(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, convert.ToGPGKey(key)) @@ -208,7 +208,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) { ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token)) return } - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{ @@ -219,7 +219,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) { if asymkey_model.IsErrGPGKeyNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -284,7 +284,7 @@ func DeleteGPGKey(ctx *context.APIContext) { if asymkey_model.IsErrGPGKeyAccessDenied(err) { ctx.APIError(http.StatusForbidden, "You do not have access to this key") } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -306,6 +306,6 @@ func HandleAddGPGKeyError(ctx *context.APIContext, err error, token string) { case asymkey_model.IsErrGPGInvalidTokenSignature(err): ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token)) default: - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } diff --git a/routers/api/v1/user/helper.go b/routers/api/v1/user/helper.go index 9ceb0c255b..f49bbbd6db 100644 --- a/routers/api/v1/user/helper.go +++ b/routers/api/v1/user/helper.go @@ -4,8 +4,6 @@ package user import ( - "net/http" - user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/services/context" ) @@ -23,7 +21,7 @@ func GetUserByPathParam(ctx *context.APIContext, name string) *user_model.User { ctx.APIErrorNotFound("GetUserByName", err) } } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil } diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index dafd696954..6295f4753b 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -81,7 +81,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) { } if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -184,7 +184,7 @@ func GetPublicKey(ctx *context.APIContext) { if asymkey_model.IsErrKeyNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -280,7 +280,7 @@ func DeletePublicKey(ctx *context.APIContext) { if asymkey_model.IsErrKeyNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -294,7 +294,7 @@ func DeletePublicKey(ctx *context.APIContext) { if asymkey_model.IsErrKeyAccessDenied(err) { ctx.APIError(http.StatusForbidden, "You do not have access to this key") } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index f57e23d679..6aabc4fb90 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -26,12 +26,12 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { OrderBy: "id ASC", }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if err := repos.LoadAttributes(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -39,7 +39,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { for i := range repos { permission, err := access_model.GetUserRepoPermission(ctx, repos[i], ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if ctx.IsSigned && ctx.Doer.IsAdmin || permission.HasAnyUnitAccess() { @@ -113,19 +113,19 @@ func ListMyRepos(ctx *context.APIContext) { repos, count, err := repo_model.SearchRepository(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } results := make([]*api.Repository, len(repos)) for i, repo := range repos { if err = repo.LoadOwner(ctx); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } results[i] = convert.ToRepo(ctx, repo, permission) } diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 1fab8a09bb..4b0cb45d67 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -72,7 +72,7 @@ func GetStarredRepos(ctx *context.APIContext) { private := ctx.ContextUser.ID == ctx.Doer.ID repos, err := getStarredRepos(ctx, ctx.ContextUser, private) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } @@ -104,7 +104,7 @@ func GetMyStarredRepos(ctx *context.APIContext) { repos, err := getStarredRepos(ctx, ctx.Doer, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars)) @@ -171,7 +171,7 @@ func Star(ctx *context.APIContext) { if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -204,7 +204,7 @@ func Unstar(ctx *context.APIContext) { err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 0542bf21cf..757a548518 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -162,7 +162,7 @@ func GetUserHeatmapData(ctx *context.APIContext) { heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, heatmap) @@ -217,7 +217,7 @@ func ListUserActivityFeeds(ctx *context.APIContext) { feeds, count, err := feed_service.GetFeeds(ctx, opts) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.SetTotalCountHeader(count) diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index d803efc387..76d7c81793 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -68,7 +68,7 @@ func GetWatchedRepos(ctx *context.APIContext) { private := ctx.ContextUser.ID == ctx.Doer.ID repos, total, err := getWatchedRepos(ctx, ctx.ContextUser, private) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } ctx.SetTotalCountHeader(total) @@ -97,7 +97,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) { repos, total, err := getWatchedRepos(ctx, ctx.Doer, true) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } ctx.SetTotalCountHeader(total) @@ -170,7 +170,7 @@ func Watch(ctx *context.APIContext) { if errors.Is(err, user_model.ErrBlockedUser) { ctx.APIError(http.StatusForbidden, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } @@ -208,7 +208,7 @@ func Unwatch(ctx *context.APIContext) { err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.Status(http.StatusNoContent) diff --git a/routers/api/v1/utils/git.go b/routers/api/v1/utils/git.go index 33aa3b81d6..af672ba147 100644 --- a/routers/api/v1/utils/git.go +++ b/routers/api/v1/utils/git.go @@ -26,7 +26,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string { for _, refType := range []string{"heads", "tags"} { refSHA, lastMethodName, err := searchRefCommitByType(ctx, refType, ref) if err != nil { - ctx.APIError(http.StatusInternalServerError, fmt.Errorf("%s: %w", lastMethodName, err)) + ctx.APIErrorInternal(fmt.Errorf("%s: %w", lastMethodName, err)) return "" } if refSHA != "" { diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index c6154dd133..9c49819970 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -54,7 +54,7 @@ func GetOwnerHook(ctx *context.APIContext, ownerID, hookID int64) (*webhook.Webh if webhook.IsErrWebhookNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, err } @@ -69,7 +69,7 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*webhook.Webhoo if webhook.IsErrWebhookNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return nil, err } @@ -102,7 +102,7 @@ func AddSystemHook(ctx *context.APIContext, form *api.CreateHookOption) { if ok { h, err := webhook_service.ToHook(setting.AppSubURL+"/-/admin", hook) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusCreated, h) @@ -141,7 +141,7 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) { func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook) (*api.Hook, bool) { apiHook, err := webhook_service.ToHook(repoLink, hook) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, false } return apiHook, true @@ -215,7 +215,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI } err := w.SetHeaderAuthorization(form.AuthorizationHeader) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, false } if w.Type == webhook_module.SLACK { @@ -238,17 +238,17 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI Color: form.Config["color"], }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, false } w.Meta = string(meta) } if err := w.UpdateEvent(); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, false } else if err := webhook.CreateWebhook(ctx, w); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return nil, false } return w, true @@ -258,21 +258,21 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI func EditSystemHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64) { hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } if !editHook(ctx, form, hook) { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } updated, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", updated) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } ctx.JSON(http.StatusOK, h) @@ -343,7 +343,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh Color: form.Config["color"], }) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return false } w.Meta = string(meta) @@ -369,7 +369,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh err := w.SetHeaderAuthorization(form.AuthorizationHeader) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return false } @@ -391,7 +391,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh w.HookEvents[webhook_module.HookEventPullRequestSync] = pullHook(form.Events, string(webhook_module.HookEventPullRequestSync)) if err := w.UpdateEvent(); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return false } @@ -400,7 +400,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh } if err := webhook.UpdateWebhook(ctx, w); err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return false } return true @@ -412,7 +412,7 @@ func DeleteOwnerHook(ctx *context.APIContext, owner *user_model.User, hookID int if webhook.IsErrWebhookNotExist(err) { ctx.APIErrorNotFound() } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } return } diff --git a/services/actions/workflow.go b/services/actions/workflow.go index ab320aa453..9aecad171b 100644 --- a/services/actions/workflow.go +++ b/services/actions/workflow.go @@ -104,7 +104,7 @@ func EnableOrDisableWorkflow(ctx *context.APIContext, workflowID string, isEnabl func ListActionWorkflows(ctx *context.APIContext) ([]*api.ActionWorkflow, error) { defaultBranchCommit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) if err != nil { - ctx.APIError(http.StatusInternalServerError, err.Error()) + ctx.APIErrorInternal(err) return nil, err } diff --git a/services/context/api.go b/services/context/api.go index 9c3ee2a4ac..230c3456d1 100644 --- a/services/context/api.go +++ b/services/context/api.go @@ -5,6 +5,7 @@ package context import ( + "errors" "fmt" "net/http" "net/url" @@ -17,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/httpcache" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" web_types "code.gitea.io/gitea/modules/web/types" ) @@ -108,7 +110,11 @@ type APIRepoArchivedError struct { // APIErrorInternal responds with error message, status is 500 func (ctx *APIContext) APIErrorInternal(err error) { - log.ErrorWithSkip(1, "InternalServerError: %v", err) + ctx.apiErrorInternal(1, err) +} + +func (ctx *APIContext) apiErrorInternal(skip int, err error) { + log.ErrorWithSkip(skip+1, "InternalServerError: %v", err) var message string if !setting.IsProd || (ctx.Doer != nil && ctx.Doer.IsAdmin) { @@ -273,7 +279,7 @@ func ReferencesGitRepo(allowEmpty ...bool) func(ctx *APIContext) { var err error ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository) if err != nil { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) return } } @@ -344,12 +350,12 @@ func (ctx *APIContext) GetErrMsg() string { // NotFoundOrServerError use error check function to determine if the error // is about not found. It responds with 404 status code for not found error, // or error context description for logging purpose of 500 server error. -func (ctx *APIContext) NotFoundOrServerError(logMsg string, errCheck func(error) bool, logErr error) { - if errCheck(logErr) { +func (ctx *APIContext) NotFoundOrServerError(err error) { + if errors.Is(err, util.ErrNotExist) { ctx.JSON(http.StatusNotFound, nil) return } - ctx.APIError(http.StatusInternalServerError, logMsg) + ctx.APIErrorInternal(err) } // IsUserSiteAdmin returns true if current user is a site admin diff --git a/services/context/user.go b/services/context/user.go index 4037354955..c09ded8339 100644 --- a/services/context/user.go +++ b/services/context/user.go @@ -44,7 +44,7 @@ func UserIDAssignmentAPI() func(ctx *APIContext) { if user_model.IsErrUserNotExist(err) { ctx.APIError(http.StatusNotFound, err) } else { - ctx.APIError(http.StatusInternalServerError, err) + ctx.APIErrorInternal(err) } } } From 9f560d47c9516e69ffdb077658439442f40c4629 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 17 Feb 2025 18:20:18 -0800 Subject: [PATCH 04/16] Make actions URL in commit status webhooks absolute (#33620) Gitea Actions generated target url doesn't contain host and port. So we need to include them for external webhook visiting. Fix #33603 --------- Co-authored-by: wxiaoguang --- services/webhook/notifier.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 6c691c21f4..76d6fd3472 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -15,6 +15,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" @@ -871,6 +872,11 @@ func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_mod return } + // as a webhook url, target should be an absolute url. But for internal actions target url + // the target url is a url path with no host and port to make it easy to be visited + // from multiple hosts. So we need to convert it to an absolute url here. + target := httplib.MakeAbsoluteURL(ctx, status.TargetURL) + payload := api.CommitStatusPayload{ Context: status.Context, CreatedAt: status.CreatedUnix.AsTime().UTC(), @@ -878,7 +884,7 @@ func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_mod ID: status.ID, SHA: commit.Sha1, State: status.State.String(), - TargetURL: status.TargetURL, + TargetURL: target, Commit: apiCommit, Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), From 241f799edfecda763c7571ea33e82356b6689423 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 18 Feb 2025 17:10:30 +0900 Subject: [PATCH 05/16] Update README screenshots (#33347) @lunny @techknowlogick Wait for the update of https://dl.gitea.com/screenshots Can you move all old screenshots into https://dl.gitea.com/screenshots/old ? Then run the action to upload new screenshots to https://dl.gitea.com/screenshots Follow #33149. As I mentioned here: https://github.com/go-gitea/gitea/pull/33149#issuecomment-2581787057, the prepare process is almost finished. The backend technical is using newly added `workflow_dispatch` feature for Gitea Action to take the screenshots automatically. Then we can easily sync the screenshots to the latest version without annoying manual work. Get more information from https://gitea.com/gitea/deployment --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---- README_ZH.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 118 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f747d993d7..5ae65cd2ac 100644 --- a/README.md +++ b/README.md @@ -150,10 +150,64 @@ for the full license text.
Looking for an overview of the interface? Check it out! -|![Dashboard](https://dl.gitea.com/screenshots/home_timeline.png)|![User Profile](https://dl.gitea.com/screenshots/user_profile.png)|![Global Issues](https://dl.gitea.com/screenshots/global_issues.png)| -|:---:|:---:|:---:| -|![Branches](https://dl.gitea.com/screenshots/branches.png)|![Web Editor](https://dl.gitea.com/screenshots/web_editor.png)|![Activity](https://dl.gitea.com/screenshots/activity.png)| -|![New Migration](https://dl.gitea.com/screenshots/migration.png)|![Migrating](https://dl.gitea.com/screenshots/migration.gif)|![Pull Request View](https://image.ibb.co/e02dSb/6.png)| -|![Pull Request Dark](https://dl.gitea.com/screenshots/pull_requests_dark.png)|![Diff Review Dark](https://dl.gitea.com/screenshots/review_dark.png)|![Diff Dark](https://dl.gitea.com/screenshots/diff_dark.png)| +### Login/Register Page + +![Login](https://dl.gitea.com/screenshots/login.png) +![Register](https://dl.gitea.com/screenshots/register.png) + +### User Dashboard + +![Home](https://dl.gitea.com/screenshots/home.png) +![Issues](https://dl.gitea.com/screenshots/issues.png) +![Pull Requests](https://dl.gitea.com/screenshots/pull_requests.png) +![Milestones](https://dl.gitea.com/screenshots/milestones.png) + +### User Profile + +![Profile](https://dl.gitea.com/screenshots/user_profile.png) + +### Explore + +![Repos](https://dl.gitea.com/screenshots/explore_repos.png) +![Users](https://dl.gitea.com/screenshots/explore_users.png) +![Orgs](https://dl.gitea.com/screenshots/explore_orgs.png) + +### Repository + +![Home](https://dl.gitea.com/screenshots/repo_home.png) +![Commits](https://dl.gitea.com/screenshots/repo_commits.png) +![Branches](https://dl.gitea.com/screenshots/repo_branches.png) +![Labels](https://dl.gitea.com/screenshots/repo_labels.png) +![Milestones](https://dl.gitea.com/screenshots/repo_milestones.png) +![Releases](https://dl.gitea.com/screenshots/repo_releases.png) +![Tags](https://dl.gitea.com/screenshots/repo_tags.png) + +#### Repository Issue + +![List](https://dl.gitea.com/screenshots/repo_issues.png) +![Issue](https://dl.gitea.com/screenshots/repo_issue.png) + +#### Repository Pull Requests + +![List](https://dl.gitea.com/screenshots/repo_pull_requests.png) +![Pull Request](https://dl.gitea.com/screenshots/repo_pull_request.png) +![File](https://dl.gitea.com/screenshots/repo_pull_request_file.png) +![Commits](https://dl.gitea.com/screenshots/repo_pull_request_commits.png) + +#### Repository Actions + +![List](https://dl.gitea.com/screenshots/repo_actions.png) +![Details](https://dl.gitea.com/screenshots/repo_actions_run.png) + +#### Repository Activity + +![Activity](https://dl.gitea.com/screenshots/repo_activity.png) +![Contributors](https://dl.gitea.com/screenshots/repo_contributors.png) +![Code Frequency](https://dl.gitea.com/screenshots/repo_code_frequency.png) +![Recent Commits](https://dl.gitea.com/screenshots/repo_recent_commits.png) + +### Organization + +![Home](https://dl.gitea.com/screenshots/org_home.png)
diff --git a/README_ZH.md b/README_ZH.md index 2dd60fd564..89c34f6b63 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -93,10 +93,64 @@ Gitea 提供官方的 [go-sdk](https://gitea.com/gitea/go-sdk),以及名为 [t
截图 -|![Dashboard](https://dl.gitea.com/screenshots/home_timeline.png)|![User Profile](https://dl.gitea.com/screenshots/user_profile.png)|![Global Issues](https://dl.gitea.com/screenshots/global_issues.png)| -|:---:|:---:|:---:| -|![Branches](https://dl.gitea.com/screenshots/branches.png)|![Web Editor](https://dl.gitea.com/screenshots/web_editor.png)|![Activity](https://dl.gitea.com/screenshots/activity.png)| -|![New Migration](https://dl.gitea.com/screenshots/migration.png)|![Migrating](https://dl.gitea.com/screenshots/migration.gif)|![Pull Request View](https://image.ibb.co/e02dSb/6.png)| -|![Pull Request Dark](https://dl.gitea.com/screenshots/pull_requests_dark.png)|![Diff Review Dark](https://dl.gitea.com/screenshots/review_dark.png)|![Diff Dark](https://dl.gitea.com/screenshots/diff_dark.png)| +### 登录界面 + +![登录](https://dl.gitea.com/screenshots/login.png) +![注册](https://dl.gitea.com/screenshots/register.png) + +### 用户首页 + +![首页](https://dl.gitea.com/screenshots/home.png) +![工单列表](https://dl.gitea.com/screenshots/issues.png) +![合并请求列表](https://dl.gitea.com/screenshots/pull_requests.png) +![里程碑列表](https://dl.gitea.com/screenshots/milestones.png) + +### 用户资料 + +![用户资料](https://dl.gitea.com/screenshots/user_profile.png) + +### 探索 + +![仓库列表](https://dl.gitea.com/screenshots/explore_repos.png) +![用户列表](https://dl.gitea.com/screenshots/explore_users.png) +![组织列表](https://dl.gitea.com/screenshots/explore_orgs.png) + +### 仓库 + +![首页](https://dl.gitea.com/screenshots/repo_home.png) +![提交列表](https://dl.gitea.com/screenshots/repo_commits.png) +![分支列表](https://dl.gitea.com/screenshots/repo_branches.png) +![标签列表](https://dl.gitea.com/screenshots/repo_labels.png) +![里程碑列表](https://dl.gitea.com/screenshots/repo_milestones.png) +![版本发布](https://dl.gitea.com/screenshots/repo_releases.png) +![标签列表](https://dl.gitea.com/screenshots/repo_tags.png) + +#### 仓库工单 + +![列表](https://dl.gitea.com/screenshots/repo_issues.png) +![工单](https://dl.gitea.com/screenshots/repo_issue.png) + +#### 仓库合并请求 + +![列表](https://dl.gitea.com/screenshots/repo_pull_requests.png) +![合并请求](https://dl.gitea.com/screenshots/repo_pull_request.png) +![文件](https://dl.gitea.com/screenshots/repo_pull_request_file.png) +![提交列表](https://dl.gitea.com/screenshots/repo_pull_request_commits.png) + +#### 仓库 Actions + +![列表](https://dl.gitea.com/screenshots/repo_actions.png) +![Run](https://dl.gitea.com/screenshots/repo_actions_run.png) + +#### 仓库动态 + +![动态](https://dl.gitea.com/screenshots/repo_activity.png) +![贡献者](https://dl.gitea.com/screenshots/repo_contributors.png) +![代码频率](https://dl.gitea.com/screenshots/repo_code_frequency.png) +![最近的提交](https://dl.gitea.com/screenshots/repo_recent_commits.png) + +### 组织 + +![首页](https://dl.gitea.com/screenshots/org_home.png)
From 748b731612191fdf597300fc1b8a1d423bae1e09 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Tue, 18 Feb 2025 06:02:40 -0500 Subject: [PATCH 06/16] Improve button layout on small screens (#33633) Fix #33160 Better "New Repository" & "New Migration" buttons on home page. --------- Co-authored-by: wxiaoguang --- templates/org/home.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index bae5db00be..826642db42 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -16,10 +16,10 @@ {{if .ShowMemberAndTeamTab}}
{{if .CanCreateOrgRepo}} -
- {{ctx.Locale.Tr "new_repo"}} +
From ce65613690e4564d9961f847ebd6eb2137f0c885 Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Tue, 18 Feb 2025 19:29:08 +0800 Subject: [PATCH 07/16] Fix Untranslated Text on Actions Page (#33635) Fix the problem of untranslated text on the actions page Co-authored-by: wxiaoguang --- models/actions/run_list.go | 5 +++-- routers/web/repo/actions/actions.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/models/actions/run_list.go b/models/actions/run_list.go index 4046c7d369..b9b9324e07 100644 --- a/models/actions/run_list.go +++ b/models/actions/run_list.go @@ -10,6 +10,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" + "code.gitea.io/gitea/modules/translation" webhook_module "code.gitea.io/gitea/modules/webhook" "xorm.io/builder" @@ -112,14 +113,14 @@ type StatusInfo struct { } // GetStatusInfoList returns a slice of StatusInfo -func GetStatusInfoList(ctx context.Context) []StatusInfo { +func GetStatusInfoList(ctx context.Context, lang translation.Locale) []StatusInfo { // same as those in aggregateJobStatus allStatus := []Status{StatusSuccess, StatusFailure, StatusWaiting, StatusRunning} statusInfoList := make([]StatusInfo, 0, 4) for _, s := range allStatus { statusInfoList = append(statusInfoList, StatusInfo{ Status: int(s), - DisplayedStatus: s.String(), + DisplayedStatus: s.LocaleString(lang), }) } return statusInfoList diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 9a5b3398d7..d07d195713 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -306,7 +306,7 @@ func prepareWorkflowList(ctx *context.Context, workflows []Workflow) { } ctx.Data["Actors"] = shared_user.MakeSelfOnTop(ctx.Doer, actors) - ctx.Data["StatusInfoList"] = actions_model.GetStatusInfoList(ctx) + ctx.Data["StatusInfoList"] = actions_model.GetStatusInfoList(ctx, ctx.Locale) pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) pager.AddParamFromRequest(ctx.Req) From 84d2159ef6a9d299f4b379ea37c0cf17291ad69b Mon Sep 17 00:00:00 2001 From: metiftikci Date: Wed, 19 Feb 2025 03:29:17 +0300 Subject: [PATCH 08/16] fix: add missing locale (#33641) this removed in #23113 but still using in `head_navbar.tmpl` --- options/locale/locale_en-US.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index bce64a81a3..c2c5b07b65 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1702,7 +1702,9 @@ issues.time_estimate_invalid = Time estimate format is invalid issues.start_tracking_history = started working %s issues.tracker_auto_close = Timer will be stopped automatically when this issue gets closed issues.tracking_already_started = `You have already started time tracking on another issue!` +issues.stop_tracking = Stop Timer issues.stop_tracking_history = worked for %[1]s %[2]s +issues.cancel_tracking = Discard issues.cancel_tracking_history = `canceled time tracking %s` issues.del_time = Delete this time log issues.add_time_history = added spent time %[1]s %[2]s From c2e23d3301b1be2b2ad667184030087f92ad2470 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 19 Feb 2025 08:55:19 +0800 Subject: [PATCH 09/16] Fix PR web route permission check (#33636) See the FIXME comment in code. Otherwise, if a repo's issue unit is disabled, then the PRs can't be edited anymore. By the way, make the permission log output look slightly better. --------- Co-authored-by: Lunny Xiao Co-authored-by: metiftikci --- models/perm/access/repo_permission.go | 10 ++++++---- modules/log/logger_impl.go | 23 +++++++++++++++++++---- modules/log/logger_test.go | 14 +++++++++++++- routers/web/web.go | 16 +++++++++------- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index e00b7c5320..5e7ecb31ea 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -152,7 +152,7 @@ func (p *Permission) ReadableUnitTypes() []unit.Type { } func (p *Permission) LogString() string { - format := " 0 } +func asLogStringer(v any) LogStringer { + if s, ok := v.(LogStringer); ok { + return s + } else if a := reflect.ValueOf(v); a.Kind() == reflect.Struct { + // in case the receiver is a pointer, but the value is a struct + vp := reflect.New(a.Type()) + vp.Elem().Set(a) + if s, ok := vp.Interface().(LogStringer); ok { + return s + } + } + return nil +} + // Log prepares the log event, if the level matches, the event will be sent to the writers func (l *LoggerImpl) Log(skip int, level Level, format string, logArgs ...any) { if Level(l.level.Load()) > level { @@ -207,11 +222,11 @@ func (l *LoggerImpl) Log(skip int, level Level, format string, logArgs ...any) { // handle LogStringer values for i, v := range msgArgs { if cv, ok := v.(*ColoredValue); ok { - if s, ok := cv.v.(LogStringer); ok { - cv.v = logStringFormatter{v: s} + if ls := asLogStringer(cv.v); ls != nil { + cv.v = logStringFormatter{v: ls} } - } else if s, ok := v.(LogStringer); ok { - msgArgs[i] = logStringFormatter{v: s} + } else if ls := asLogStringer(v); ls != nil { + msgArgs[i] = logStringFormatter{v: ls} } } diff --git a/modules/log/logger_test.go b/modules/log/logger_test.go index 0de14eb411..e794732ce2 100644 --- a/modules/log/logger_test.go +++ b/modules/log/logger_test.go @@ -116,6 +116,14 @@ func (t testLogString) LogString() string { return "log-string" } +type testLogStringPtrReceiver struct { + Field string +} + +func (t *testLogStringPtrReceiver) LogString() string { + return "log-string-ptr-receiver" +} + func TestLoggerLogString(t *testing.T) { logger := NewLoggerWithWriters(context.Background(), "test") @@ -124,9 +132,13 @@ func TestLoggerLogString(t *testing.T) { logger.AddWriters(w1) logger.Info("%s %s %#v %v", testLogString{}, &testLogString{}, testLogString{Field: "detail"}, NewColoredValue(testLogString{}, FgRed)) + logger.Info("%s %s %#v %v", testLogStringPtrReceiver{}, &testLogStringPtrReceiver{}, testLogStringPtrReceiver{Field: "detail"}, NewColoredValue(testLogStringPtrReceiver{}, FgRed)) logger.Close() - assert.Equal(t, []string{"log-string log-string log.testLogString{Field:\"detail\"} \x1b[31mlog-string\x1b[0m\n"}, w1.GetLogs()) + assert.Equal(t, []string{ + "log-string log-string log.testLogString{Field:\"detail\"} \x1b[31mlog-string\x1b[0m\n", + "log-string-ptr-receiver log-string-ptr-receiver &log.testLogStringPtrReceiver{Field:\"detail\"} \x1b[31mlog-string-ptr-receiver\x1b[0m\n", + }, w1.GetLogs()) } func TestLoggerExpressionFilter(t *testing.T) { diff --git a/routers/web/web.go b/routers/web/web.go index bca20b88ab..a5175e8830 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1196,6 +1196,10 @@ func registerRoutes(m *web.Router) { }) }) } + // FIXME: many "pulls" requests are sent to "issues" endpoints correctly, so the issue endpoints have to tolerate pull request permissions at the moment + m.Group("/{username}/{reponame}/{type:issues}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, context.RequireUnitReader(unit.TypeIssues, unit.TypePullRequests)) + m.Group("/{username}/{reponame}/{type:pulls}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, reqUnitPullsReader) + m.Group("/{username}/{reponame}", func() { m.Get("/comments/{id}/attachments", repo.GetCommentAttachments) m.Get("/labels", repo.RetrieveLabelsForList, repo.Labels) @@ -1203,9 +1207,6 @@ func registerRoutes(m *web.Router) { m.Get("/milestone/{id}", context.RepoRef(), repo.MilestoneIssuesAndPulls) m.Get("/issues/suggestions", repo.IssueSuggestions) }, optSignIn, context.RepoAssignment, reqRepoIssuesOrPullsReader) // issue/pull attachments, labels, milestones - - m.Group("/{username}/{reponame}/{type:issues}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, reqUnitIssuesReader) - m.Group("/{username}/{reponame}/{type:pulls}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, reqUnitPullsReader) // end "/{username}/{reponame}": view milestone, label, issue, pull, etc m.Group("/{username}/{reponame}/{type:issues}", func() { @@ -1224,7 +1225,7 @@ func registerRoutes(m *web.Router) { m.Get("/search", repo.SearchRepoIssuesJSON) }, reqUnitIssuesReader) - addIssuesPullsRoutes := func() { + addIssuesPullsUpdateRoutes := func() { // for "/{username}/{reponame}/issues" or "/{username}/{reponame}/pulls" m.Group("/{index}", func() { m.Post("/title", repo.UpdateIssueTitle) @@ -1267,8 +1268,9 @@ func registerRoutes(m *web.Router) { m.Delete("/unpin/{index}", reqRepoAdmin, repo.IssueUnpin) m.Post("/move_pin", reqRepoAdmin, repo.IssuePinMove) } - m.Group("/{type:issues}", addIssuesPullsRoutes, reqUnitIssuesReader, context.RepoMustNotBeArchived()) - m.Group("/{type:pulls}", addIssuesPullsRoutes, reqUnitPullsReader, context.RepoMustNotBeArchived()) + // FIXME: many "pulls" requests are sent to "issues" endpoints incorrectly, so the issue endpoints have to tolerate pull request permissions at the moment + m.Group("/{type:issues}", addIssuesPullsUpdateRoutes, context.RequireUnitReader(unit.TypeIssues, unit.TypePullRequests), context.RepoMustNotBeArchived()) + m.Group("/{type:pulls}", addIssuesPullsUpdateRoutes, reqUnitPullsReader, context.RepoMustNotBeArchived()) m.Group("/comments/{id}", func() { m.Post("", repo.UpdateCommentContent) @@ -1292,7 +1294,7 @@ func registerRoutes(m *web.Router) { m.Post("/delete", repo.DeleteMilestone) }, reqRepoIssuesOrPullsWriter, context.RepoRef()) - // FIXME: need to move these routes to the proper place + // FIXME: many "pulls" requests are sent to "issues" endpoints incorrectly, need to move these routes to the proper place m.Group("/issues", func() { m.Post("/request_review", repo.UpdatePullReviewRequest) m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview) From 40faa6dc78a5b5730a1609ba39daefddac08aa63 Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Wed, 19 Feb 2025 19:35:08 +0100 Subject: [PATCH 10/16] git graph: don't show detached commits (#33645) Current git graph is not usable for mirrors of repos having a lot of PRs, as can be seen at https://demo.gitea.com/ericLemanissier/conan-center-index/graph ![image](https://github.com/user-attachments/assets/ace40dd2-3eea-4d69-8e19-10fb7224e326) Manually running `git log --graph --date-order --all` on such a repo indeed shows: ``` * commit c4a34bd39d7977c8630177c5f88507000ea3e943 |\ Merge: a4bbd3ad6b 35a102c77c | | Author: toge | | Date: Wed Feb 19 08:36:41 2025 +0000 | | | | Merge 35a102c77cbc38d84baca0ca63466fb410336ea8 into a4bbd3ad6bb5a0f8e5117a897d8c55941f533d98 | | | * commit 35a102c77cbc38d84baca0ca63466fb410336ea8 | | Author: toge | | Date: Wed Feb 19 17:36:35 2025 +0900 | | | | update 4.4.2 | | | | * commit 5d610f4fd3c0428731e402a2f618fad9ce055875 | |/| Merge: a4bbd3ad6b fe916fb70a |/| | Author: Antony Peacock | | | Date: Wed Feb 19 08:31:30 2025 +0000 | | | | | | Merge fe916fb70a8bf49503cce70a5c7124bcc4314ddc into a4bbd3ad6bb5a0f8e5117a897d8c55941f533d98 | | | | | * commit fe916fb70a8bf49503cce70a5c7124bcc4314ddc | | | Author: Antony Peacock | | | Date: Wed Feb 19 08:31:18 2025 +0000 | | | | | | Remove parquet cmakelist patch | | | | | | * commit 9f6d2759d650ec3c86d01bb940e829e7e14220c2 | |_|/| Merge: a4bbd3ad6b f0963429b0 |/| | | Author: Thomas Sedlmair | | | | Date: Wed Feb 19 08:03:08 2025 +0100 | | | | | | | | Merge f0963429b0952499da0da7e559f8d53387097307 into a4bbd3ad6bb5a0f8e5117a897d8c55941f533d98 | | | | | | | * commit f0963429b0952499da0da7e559f8d53387097307 | |_|/ Author: Thomas Sedlmair |/| | Date: Wed Feb 19 08:01:43 2025 +0100 | | | | | | added cwt-cucumber 2.5 | | | ``` On the other hand, running `git log --graph --date-order --branches --tags` returns the expected: ``` * commit a4bbd3ad6bb5a0f8e5117a897d8c55941f533d98 (HEAD -> master) | Author: Dan | Date: Fri Feb 14 18:46:11 2025 +0200 | | grpc: add version 1.69.0 (#26446) | | * grpc: add version 1.69.0 | | * add cmake tool requires | | --------- | | Co-authored-by: Luis Caro Campos <3535649+jcar87@users.noreply.github.com> | * commit a7868807cb2e21206ebf95278cb588f29a3e2205 | Author: Guillaume Egles | Date: Thu Feb 13 05:44:35 2025 -0800 | | openssl: add versions `3.0.16`, `3.1.8`, `3.2.4`, `3.3.3`, `3.4.1`, stop publishing revisions for version `3.0.15` (#26578) | * commit 86057d3e63ac71e2fe48c07bb301f2d54187044d | Author: Luis Caro Campos <3535649+jcar87@users.noreply.github.com> | Date: Thu Feb 13 13:34:41 2025 +0000 | | android-ndk: dont set LD and AS variables (#26581) | | * android-ndk: dont set LD and AS variables | | * android-ndk: refactor test package | * commit 123e382fafd2f5e811e10faac02efc275c45ec2a | Author: Nikita | Date: Thu Feb 13 12:29:39 2025 +0300 | | libffi: fix conditionals when building on Windows (#26500) | | * fix: add missing or `clang` | | * fix: libffi - always require as tool `automake` ``` --- services/repository/gitgraph/graph.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/repository/gitgraph/graph.go b/services/repository/gitgraph/graph.go index 7e12be030f..2628a1a55a 100644 --- a/services/repository/gitgraph/graph.go +++ b/services/repository/gitgraph/graph.go @@ -29,7 +29,7 @@ func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bo } if len(branches) == 0 { - graphCmd.AddArguments("--all") + graphCmd.AddArguments("--tags", "--branches") } graphCmd.AddArguments("-C", "-M", "--date=iso-strict"). From 21af8150b7ba315a9f75264ab77813b0b7c697a8 Mon Sep 17 00:00:00 2001 From: GiteaBot Date: Thu, 20 Feb 2025 00:32:10 +0000 Subject: [PATCH 11/16] [skip ci] Updated translations via Crowdin --- options/locale/locale_pt-PT.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/options/locale/locale_pt-PT.ini b/options/locale/locale_pt-PT.ini index 3913e9cb48..3582755d5e 100644 --- a/options/locale/locale_pt-PT.ini +++ b/options/locale/locale_pt-PT.ini @@ -1701,7 +1701,9 @@ issues.time_estimate_invalid=O formato da estimativa de tempo é inválido issues.start_tracking_history=começou a trabalhar %s issues.tracker_auto_close=O cronómetro será parado automaticamente quando esta questão for fechada issues.tracking_already_started=`Você já iniciou a contagem de tempo noutra questão!` +issues.stop_tracking=Parar cronómetro issues.stop_tracking_history=trabalhou durante %[1]s %[2]s +issues.cancel_tracking=Descartar issues.cancel_tracking_history=`cancelou a contagem de tempo %s` issues.del_time=Eliminar este registo de tempo issues.add_time_history=adicionou %[1]s de tempo gasto %[2]s From 3bbc4828792cf741e6684d13429aeabb271ca1ad Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 20 Feb 2025 01:31:07 -0800 Subject: [PATCH 12/16] Add missed changelogs (#33649) Co-authored-by: wxiaoguang --- CHANGELOG.md | 511 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 511 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab8c2ac223..c32915c1dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,517 @@ This changelog goes through the changes that have been made in each release without substantial changes to our git log; to see the highlights of what has been added to each release, please refer to the [blog](https://blog.gitea.com). +## [1.23.4](https://github.com/go-gitea/gitea/releases/tag/v1.23.4) - 2025-02-16 + +* SECURITY + * Enhance routers for the Actions variable operations (#33547) (#33553) + * Enhance routers for the Actions runner operations (#33549) (#33555) + * Fix project issues list and counting (#33594) #33619 +* PERFORMANCES + * Performance optimization for pull request files loading comments attachments (#33585) (#33592) +* BUGFIXES + * Add a transaction to `pickTask` (#33543) (#33563) + * Fix mirror bug (#33597) (#33607) + * Use default Git timeout when checking repo health (#33593) (#33598) + * Fix PR's target branch dropdown (#33589) (#33591) + * Fix various problems (artifact order, api empty slice, assignee check, fuzzy prompt, mirror proxy, adopt git) (#33569) (#33577) + * Rework suggestion backend (#33538) (#33546) + * Fix context usage (#33554) (#33557) + * Only show the latest version in the Arch index (#33262) (#33580) + * Skip deletion error for action artifacts (#33476) (#33568) + * Make actions URL in commit status webhooks absolute (#33620) #33632 + * Add missing locale (#33641) #33642 + +## [1.23.3](https://github.com/go-gitea/gitea/releases/tag/v1.23.3) - 2025-02-06 + +* Security + * Build Gitea with Golang v1.23.6 to fix security bugs +* BUGFIXES + * Fix a bug caused by status webhook template #33512 + +## [1.23.2](https://github.com/go-gitea/gitea/releases/tag/1.23.2) - 2025-02-04 + +* BREAKING + * Add tests for webhook and fix some webhook bugs (#33396) (#33442) + * Package webhook’s Organization was incorrectly used as the User struct. This PR fixes the issue. + * This changelog is just a hint. The change is not really breaking because most fields are the same, most users are not affected. +* ENHANCEMENTS + * Clone button enhancements (#33362) (#33404) + * Repo homepage styling tweaks (#33289) (#33381) + * Add a confirm dialog for "sync fork" (#33270) (#33273) + * Make tracked time representation display as hours (#33315) (#33334) + * Improve sync fork behavior (#33319) (#33332) +* BUGFIXES + * Fix code button alignment (#33345) (#33351) + * Correct bot label `vertical-align` (#33477) (#33480) + * Fix SSH LFS memory usage (#33455) (#33460) + * Fix issue sidebar dropdown keyboard support (#33447) (#33450) + * Fix user avatar (#33439) + * Fix `GetCommitBranchStart` bug (#33298) (#33421) + * Add pubdate for repository rss and add some tests (#33411) (#33416) + * Add missed auto merge feed message on dashboard (#33309) (#33405) + * Fix issue suggestion bug (#33389) (#33391) + * Make issue suggestion work for all editors (#33340) (#33342) + * Fix issue count (#33338) (#33341) + * Fix Account linking page (#33325) (#33327) + * Fix closed dependency title (#33285) (#33287) + * Fix sidebar milestone link (#33269) (#33272) + * Fix missing license when sync mirror (#33255) (#33258) + * Fix upload file form (#33230) (#33233) + * Fix mirror bug (#33224) (#33225) + * Fix system admin cannot fork or get private fork with API (#33401) (#33417) + * Fix push message behavior (#33215) (#33317) + * Trivial fixes (#33304) (#33312) + * Fix "stop time tracking button" on navbar (#33084) (#33300) + * Fix tag route and empty repo (#33253) + * Fix cache test triggered by non memory cache (#33220) (#33221) + * Revert empty lfs ref name (#33454) (#33457) + * Fix flex width (#33414) (#33418) + * Fix commit status events (#33320) #33493 + * Fix unnecessary comment when moving issue on the same project column (#33496) #33499 + * Add timetzdata build tag to binary releases (#33463) #33503 +* MISC + * Use ProtonMail/go-crypto to replace keybase/go-crypto (#33402) (#33410) + * Update katex to latest version (#33361) + * Update go tool dependencies (#32916) (#33355) + +## [1.23.1](https://github.com/go-gitea/gitea/releases/tag/v1.23.1) - 2025-01-09 + +* ENHANCEMENTS + * Move repo size to sidebar (#33155) (#33182) +* BUGFIXES + * Use updated path to s6-svscan after alpine upgrade (#33185) (#33188) + * Fix fuzz test (#33156) (#33158) + * Fix raw file API ref handling (#33172) (#33189) + * Fix ACME panic (#33178) (#33186) + * Fix branch dropdown not display ref name (#33159) (#33183) + * Fix assignee list overlapping in Issue sidebar (#33176) (#33181) + * Fix sync fork for consistency (#33147) #33192 + * Fix editor markdown not incrementing in a numbered list (#33187) #33193 + +## [1.23.0](https://github.com/go-gitea/gitea/releases/tag/v1.23.0) - 2025-01-08 + +* BREAKING + * Rename config option `[camo].Allways` to `[camo].Always` (#32097) + * Remove SHA1 for support for ssh rsa signing (#31857) + * Use UTC as default timezone when schedule Actions cron tasks (#31742) + * Delete Actions logs older than 1 year by default (#31735) + * Make OIDC introspection authentication strictly require Client ID and secret (#31632) + +* SECURITY + * Include file extension checks in attachment API (#32151) + * Include all security fixes which have been backported to v1.22 + +* FEATURES + * Allow to fork repository into the same owner (#32819) + * Support "merge upstream branch" (Sync fork) (#32741) + * Add Arch package registry (#32692) + * Allow to disable the password-based login (sign-in) form (#32687) + * Allow cropping an avatar before setting it (#32565) + * Support quote selected comments to reply (#32431) + * Add reviewers selection to new pull request (#32403) + * Suggestions for issues (#32327) + * Add priority to protected branch (#32286) + * Included tag search capabilities (#32045) + * Add option to filter board cards by labels and assignees (#31999) + * Add automatic light/dark option for the colorblind theme (#31997) + * Support migration from AWS CodeCommit (#31981) + * Introduce globallock as distributed locks (#31908 & #31813) + * Support compression for Actions logs & enable by default (#31761 & #32013) + * Add pure SSH LFS support (#31516) + * Add Passkey login support (#31504) + * Actions support workflow dispatch event (#28163) + * Support repo license (#24872) + * Issue time estimate, meaningful time tracking (#23113) + * GitHub like repo home page (#32213 & #32847) + * Rearrange Clone Panel (#31142) + * Enhancing Gitea OAuth2 Provider with Granular Scopes for Resource Access (#32573) + * Use env GITEA_RUNNER_REGISTRATION_TOKEN as global runner token (#32946) #32964 + * Update i18n.go - Language Picker (#32933) #32935 + +* PERFORMANCE + * Perf: add extra index to notification table (#32395) + * Introduce OrgList and add LoadTeams, optimaze Load teams for orgs (#32543) + * Improve performance of diffs (#32393) + * Make LFS http_client parallel within a batch. (#32369) + * Add new index for action to resolve the performance problem (#32333) + * Improve get feed with pagination (#31821) + * Performance improvements for pull request list API (#30490) + * Use batch database operations instead of one by one to optimze api pulls (#32680) + * Use gitrepo.GetTreePathLatestCommit to get file lastest commit instead from latest commit cache (#32987) #33046 + +* ENHANCEMENTS + * Code + * Remove unnecessary border in repo home page sidebar (#32767) + * Add 'Copy path' button to file view (#32584) + * Improve diff file tree (#32658) + * Add new [lfs_client].BATCH_SIZE and [server].LFS_MAX_BATCH_SIZE config settings. (#32307) + * Updated tokenizer to better matching when search for code snippets (#32261) + * Change the code search to sort results by relevance (#32134) + * Support migrating GitHub/GitLab PR draft status (#32242) + * Move lock icon position and add additional tooltips to branch list page (#31839) + * Add tag name in the commits list (#31082) + * Add `MAX_ROWS` option for CSV rendering (#30268) + * Allow code search by filename (#32210) + * Make git push options accept short name (#32245) + * Repo file list enhancements (#32835) + + * Markdown & Editor + * Refactor markdown math render, add dollor-backquote syntax support (#32831) + * Make Monaco theme follow browser, fully type codeeditor.ts (#32756) + * Refactor markdown editor and use it for milestone description editor (#32688) + * Add some handy markdown editor features (#32400) + * Improve markdown textarea for indentation and lists (#31406) + + * Issue + * Add label/author/assignee filters to the user/org home issue list (#32779) + * Refactor issue filter (labels, poster, assignee) (#32771) + * Style unification for the issue_management area (#32605) + * Add "View all branches/tags" entry to Branch Selector (#32653) + * Improve textarea paste (#31948) + * Add avif image file support (#32508) + * Prevent from submitting issue/comment on uploading (#32263) + * Issue Templates: add option to have dropdown printed list (#31577) + * Allow searching issues by ID (#31479) + * Add `is_archived` option for issue indexer (#32735) + * Improve attachment upload methods (#30513) + * Support issue template assignees (#31083) + * Prevent simultaneous editing of comments and issues (#31053) + * Add issue comment when moving issues from one column to another of the project (#29311) + + * Pull Request + * Display head branch more comfortable on pull request view (#32000) + * Simplify review UI (#31062) + * Allow force push to protected branches (#28086) + * Add line-through for deleted branch on pull request view page (#32500) + * Support requested_reviewers data in comment webhook events (#26178) + * Allow maintainers to view and edit files of private repos when "Allow maintainers to edit" is enabled (#32215) + * Allow including `Reviewed-on`/`Reviewed-by` lines for custom merge messages (#31211) + + * Actions + * Render job title as commit message (#32748) + * Refactor RepoActionView.vue, add `::group::` support (#32713) + * Make RepoActionView.vue support `##[group]` (#32770) + * Support `pull_request_target` event for commit status (#31703) + * Detect whether action view branch was deleted (#32764) + * Allow users with write permission to run actions (#32644) + * Show latest run when visit /run/latest (#31808) + + * Packages + * Improve rubygems package registry (#31357) + * Add support for npm bundleDependencies (#30751) + * Add signature support for the RPM module (#27069) + * Extract and display readme and comments for Composer packages (#30927) + + * Project + * Add title to project view page (#32747) + * Set the columns height to hug all its contents (#31726) + * Rename project `board` -> `column` to make the UI less confusing (#30170) + + * User & Organazition + * Use better name for userinfo structure (#32544) + * Use user.FullName in Oauth2 id_token response (#32542) + * Limit org member view of restricted users (#32211) + * Allow disabling authentication related user features (#31535) + * Add option to change mail from user display name (#31528) + * Use FullName in Emails to address the recipient if possible (#31527) + + * Administration + * Add support for a credentials chain for minio access (#31051) + * Move admin routers from /admin to /-/admin (#32189) + * Add cache test for admins (#31265) + * Add option for mailer to override mail headers (#27860) + * Azure blob storage support (#30995) + * Supports forced use of S3 virtual-hosted style (#30969) + * Move repository visibility to danger zone in the settings area (#31126) + + * Others + * Remove urls from translations (#31950) + * Simplify 404/500 page (#31409) + * Optimize installation-page experience (#32558) + * Refactor login page (#31530) + * Add new event commit status creation and webhook implementation (#27151) + * Repo Activity: count new issues that were closed (#31776) + * Set manual `tabindex`es on login page (#31689) + * Add `YEAR`, `MONTH`, `MONTH_ENGLISH`, `DAY` variables for template repos (#31584) + * Add typescript guideline and typescript-specific eslint plugins and fix issues (#31521) + * Make toast support preventDuplicates (#31501) + * Fix tautological conditions (#30735) + * Issue change title notifications (#33050) #33065 + +* API + * Implement update branch API (#32433) + * Fix missing outputs for jobs with matrix (#32823) + * Make API "compare" accept commit IDs (#32801) + * Add github compatible tarball download API endpoints (#32572) + * Harden runner updateTask and updateLog api (#32462) + * Add `DISABLE_ORGANIZATIONS_PAGE` and `DISABLE_CODE_PAGE` settings for explore pages and fix an issue related to user search (#32288) + * Make admins adhere to branch protection rules (#32248) + * Calculate `PublicOnly` for org membership only once (#32234) + * Allow filtering PRs by poster in the ListPullRequests API (#32209) + * Return 404 instead of error when commit not exist (#31977) + * Save initial signup information for users to aid in spam prevention (#31852) + * Fix upload maven pacakge parallelly (#31851) + * Fix null requested_reviewer from API (#31773) + * Add permission description for API to add repo collaborator (#31744) + * Add return type to GetRawFileOrLFS and GetRawFile (#31680) + * Add skip secondary authorization option for public oauth2 clients (#31454) + * Add tag protection via rest api #17862 (#31295) + * Document possible action types for the user activity feed API (#31196) + * Add topics for repository API (#31127) + * Add support for searching users by email (#30908) + * Add API endpoints for getting action jobs status (#26673) + +* REFACTOR + * Update JS and PY dependencies (#31940) + * Enable `no-jquery/no-parse-html-literal` and fix violation (#31684) + * Refactor image diff (#31444) + * Refactor CSRF token (#32216) + * Fix some typescript issues (#32586) + * Refactor names (#31405) + * Use per package global lock for container uploads instead of memory lock (#31860) + * Move team related functions to service layer (#32537) + * Move GetFeeds to service layer (#32526) + * Resolve lint for unused parameter and unnecessary type arguments (#30750) + * Reimplement GetUserOrgsList to make it simple and clear (#32486) + * Move some functions from issue.go to standalone files (#32468) + * Refactor sidebar assignee&milestone&project selectors (#32465) + * Refactor sidebar label selector (#32460) + * Fix a number of typescript issues (#32459) + * Refactor language menu and dom utils (#32450) + * Refactor issue page info (#32445) + * Split issue sidebar into small templates (#32444) + * Refactor template ctx and render utils (#32422) + * Refactor repo legacy (#32404) + * Refactor markup package (#32399) + * Refactor markup render system (#32533 & #32589 & #32612) + * Refactor the DB migration system slightly (#32344) + * Remove jQuery import from some files (#32512) + * Strict pagination check (#32548) + * Split mail sender sub package from mailer service package (#32618) + * Remove outdated code about fixture generation (#32708) + * Refactor RepoBranchTagSelector (#32681) + * Refactor issue list (#32755) + * Refactor LabelEdit (#32752) + * Split issue/pull view router function as multiple smaller functions (#32749) + * Refactor some LDAP code (#32849) + * Unify repo search order by logic (#30876) + * Remove duplicate empty repo check in delete branch API (#32569) + * Replace deprecated `math/rand` functions (#30733) + * Remove fomantic dimmer module (#30723) + * Add types to fetch,toast,bootstrap,svg (#31627) + * Refactor webhook (#31587) + * Move AddCollabrator and CreateRepositoryByExample to service layer (#32419) + * Refactor RepoRefByType (#32413) + * Refactor: remove redundant err declarations (#32381) + * Refactor markup code (#31399) + * Refactor render system (orgmode) (#32671) + * Refactor render system (#32492) + * Refactor markdown render (#32736 & #32728) + * Refactor repo unit "disabled" check (#31389) + * Refactor route path normalization (#31381) + * Refactor to use UnsafeStringToBytes (#31358) + * Migrate vue components to setup (#32329) + * Refactor globallock (#31933) + * Use correct function name (#31887) + * Use a common message template instead of a special one (#31878) + * Fix a number of Typescript issues (#31877) + * Refactor dropzone (#31482) + * Move custom `tw-` helpers to tailwind plugin (#31184) + * Replace `gt-word-break` with `tw-break-anywhere` (#31183) + * Drop `IDOrderDesc` for listing Actions task and always order by `id DESC` (#31150) + * Split common-global.js into separate files (#31438) + * Improve detecting empty files (#31332) + * Use `querySelector` over alternative DOM methods (#31280) + * Remove jQuery `.text()` (#30506) + * Use repo as of renderctx's member rather than a repoPath on metas (#29222) + * Refactor some frontend problems (#32646) + * Refactor DateUtils and merge TimeSince (#32409) + * Replace DateTime with proper functions (#32402) + * Replace DateTime with DateUtils (#32383) + * Convert frontend code to typescript (#31559) + * Refactor maven package registry (#33049) #33057 + * Refactor testfixtures #33028 + +* BUGFIXES + * Fix issues with inconsistent spacing in areas (#32607) + * Fix incomplete Actions status aggregations (#32859) + * In some lfs server implementations, they require the ref attribute. (#32838) + * Update the list of watchers and stargazers when clicking watch/unwatch or star/unstar (#32570) + * Fix `recentupdate` sorting bugs (#32505) + * Fix incorrect "Target branch does not exist" in PR title (#32222) + * Handle "close" actionable references for manual merges (#31879) + * render plain text file if the LFS object doesn't exist (#31812) + * Fix Null Pointer error for CommitStatusesHideActionsURL (#31731) + * Fix loadRepository error when access user dashboard (#31719) + * Hide the "Details" link of commit status when the user cannot access actions (#30156) + * Fix duplicate dropdown dividers (#32760) + * Fix SSPI button visibility when SSPI is the only enabled method (#32841) + * Fix overflow on org header (#32837) + * Exclude protected branches from recently pushed (#31748) + * Fix large image overflow in comment page (#31740) + * Fix milestone deadline and date related problems (#32339) + * Fix markdown preview $$ support (#31514) + * Fix a compilation error in the Gitpod environment (#32559) + * Fix PR diff review form submit (#32596) + * Fix a number of typescript issues (#32308) + * Fix some function names in comment (#32300) + * Fix absolute-date (#32375) + * Clarify Actions resources ownership (#31724) + * Try to fix ACME directory problem (#33072) #33077 + * Inherit submodules from template repository content (#16237) #33068 + * Use project's redirect url instead of composing url (#33058) #33064 + * Fix toggle commit body button ui when latest commit message is long (#32997) #33034 + * Fix package error handling and npm meta and empty repo guide #33112 + * Fix empty git repo handling logic and fix mobile view (#33101) #33102 + * Fix line-number and scroll bugs (#33094) #33095 + * Fix bleve fuzziness search (#33078) #33087 + * Fix broken forms #33082 + * Fix empty repo updated time (#33120) #33124 + * Add missing transaction when set merge #33113 + * Fix issue comment number (#30556) #33055 + * Fix duplicate co-author in squashed merge commit messages (#33020) #33054 + * Fix Agit pull request permission check (#32999) #33005 + * Fix scoped label ui when contains emoji (#33007) #33014 + * Fix bug on activities (#33008) #33016 + * Fix review code comment avatar alignment (#33031) #33032 + * Fix templating in pull request comparison (#33025) #33038 + * Fix bug automerge cannot be chosed when there is only 1 merge style (#33040) #33043 + * Fix settings not being loaded at CLI (#26402) #33048 + * Support for email addresses containing uppercase characters when activating user account (#32998) #33001 + * Support org labels when adding labels by label names (#32988) #32996 + * Do not render truncated links in markdown (#32980) #32983 + * Demilestone should not include milestone (#32923) #32979 + * Fix Azure blob object Seek (#32974) #32975 + * Fix maven pom inheritance (#32943) #32976 + * Fix textarea newline handle (#32966) #32977 + * Fix outdated tmpl code (#32953) #32961 + * Fix commit range paging (#32944) #32962 + * Fix repo avatar conflict (#32958) #32960 + * Fix trailing comma not matched in the case of alphanumeric issue (#32945) + * Relax the version checking for Arch packages (#32908) #32913 + * Add more load functions to make sure the reference object loaded (#32901) #32912 + * Filter reviews of one pull request in memory instead of database to reduce slow response because of lacking database index (#33106) #33128 + * Fix git remote error check, fix dependencies, fix js error (#33129) #33133 + +* MISC + * Optimize branch protection rule loading (#32280) + * Bump to go 1.23 (#31855) + * Remove unused call to $.HeadRepo in view_title template (#32317) + * Do not display `attestation-manifest` and use short sha256 instead of full sha256 (#32851) + * Upgrade htmx to 2.0.4 (#32834) + * Improve JSX/TSX support in code editor (#32833) + * Add User-Agent for gitea's self-implemented lfs client. (#32832) + * Use errors.New to replace fmt.Errorf with no parameters (#32800) + * Add "n commits" link to contributors in contributors graph page (#32799) + * Update dependencies, tweak eslint (#32719) + * Remove all "floated" CSS styles (#32691) + * Show tag name on branch/tag selector if repo shown from tag ref (#32689) + * Use new mail package instead of an unmintained one (#32682) + * Optimize the styling of icon buttons within file-header-right (#32675) + * Validate OAuth Redirect URIs (#32643) + * Support optional/configurable IAMEndpoint for Minio Client (#32581) (#32581) + * Make search box in issue sidebar dropdown list always show when scrolling (#32576) + * Bump CI,Flake and Snap to Node 22 (#32487) + * Update `github.com/meilisearch/meilisearch-go` (#32484) + * Add `DEFAULT_MIRROR_REPO_UNITS` and `DEFAULT_TEMPLATE_REPO_UNITS` options (#32416) + * Update go dependencies (#32389) + * Update JS and PY dependencies (#32388) + * Upgrade rollup to 4.24.0 (#32312) + * Upgrade vue to 3.5.12 (#32311) + * Improve the maintainblity of the reserved username list (#32229) + * Upgrade htmx to 2.0.3 (#32192) + * Count typescript files as frontend for labeling (#32088) + * Only use Host header from reverse proxy (#32060) + * Failed authentications are logged to level Warning (#32016) + * Enhance USER_DISABLED_FEATURES to allow disabling change username or full name (#31959) + * Distinguish official vs non-official reviews, add tool tips, and upgr… (#31924) + * Update mermaid to v11 (#31913) + * Bump relative-time-element to v4.4.3 (#31910) + * Upgrade `htmx` to `2.0.2` (#31847) + * Add warning message in merge instructions when `AutodetectManualMerge` was not enabled (#31805) + * Add types to various low-level functions (#31781) + * Update JS dependencies (#31766) + * Remove unused code from models/repos/release.go (#31756) + * Support delete user email in admin panel (#31690) + * Add `username` to OIDC introspection response (#31688) + * Use GetDisplayName() instead of DisplayName() to generate rss feeds (#31687) + * Code editor theme enhancements (#31629) + * Update JS dependencies (#31616) + * Add types for js globals (#31586) + * Add back esbuild-loader for .js files (#31585) + * Don't show hidden labels when filling out an issue template (#31576) + * Allow synchronizing user status from OAuth2 login providers (#31572) + * Display app name in the registration email title (#31562) + * Use stable version of fabric (#31526) + * Support legacy _links LFS batch responses (#31513) + * Fix JS error with disabled attachment and easymde (#31511) + * Always use HTML attributes for avatar size (#31509) + * Use nolyfill to remove some polyfills (#31468) + * Disable issue/PR comment button given empty input (#31463) + * Add simple JS init performance trace (#31459) + * Bump htmx to 2.0.0 (#31413) + * Update JS dependencies, remove `eslint-plugin-jquery` (#31402) + * Split org Propfile README to a new tab `overview` (#31373) + * Update nix flake and add gofumpt (#31320) + * Code optimization (#31315) + * Enable poetry non-package mode (#31282) + * Optimize profile layout to enhance visual experience (#31278) + * Update `golang.org/x/net` (#31260) + * Bump `@github/relative-time-element` to v4.4.1 (#31232) + * Remove unnecessary inline style for tab-size (#31224) + * Update golangci-lint to v1.59.0 (#31221) + * Update chroma to v2.14.0 (#31177) + * Update JS dependencies (#31120) + * Improve the handling of `jobs..if` (#31070) + * Clean up revive linter config, tweak golangci output (#30980) + * Use CSS `inset` shorthand (#30939) + * Forbid deprecated `break-word` in CSS (#30934) + * Remove obsolete monaco workaround (#30893) + * Update JS dependencies, add new eslint rules (#30840) + * Fix body margin shifting with modals, fix error on project column edit (#30831) + * Remove disk-clean workflow (#30741) + * Bump `github.com/google/go-github` to v61 (#30738) + * Add built js files to eslint ignore (#30737) + * Use `ProtonMail/go-crypto` for `opengpg` in tests (#30736) + * Upgrade xorm to v1.3.9 and improve some migrations Sync (#29899) + * Added default sorting milestones by name (#27084) + * Enable `unparam` linter (#31277) + * Use Alpine 3.21 for the docker images (#32924) #32951 + * Bump x/net (#32896) #32899 + * Use -s -w ldflags for release artifacts (#33041) #33042 + * Remove aws go sdk package dependency (#33029) #33047 + +## [1.22.6](https://github.com/go-gitea/gitea/releases/tag/v1.22.6) - 2024-12-12 + +* SECURITY + * Fix misuse of PublicKeyCallback(#32810) +* BUGFIXES + * Fix lfs migration (#32812) (#32818) + * Add missing two sync feed for refs/pull (#32815) +* TESTING + * Avoid MacOS keychain dialog in integration tests (#32813) (#32816) + +## [1.22.5](https://github.com/go-gitea/gitea/releases/tag/v1.22.5) - 2024-12-11 + +* SECURITY + * Upgrade crypto library (#32791) + * Fix delete branch perm checking (#32654) (#32707) +* BUGFIXES + * Add standard-compliant route to serve outdated R packages (#32783) (#32789) + * Fix internal server error when updating labels without write permission (#32776) (#32785) + * Add Swift login endpoint (#32693) (#32701) + * Fix fork page branch selection (#32711) (#32725) + * Fix word overflow in file search page (#32695) (#32699) + * Fix gogit `GetRefCommitID` (#32705) (#32712) + * Fix race condition in mermaid observer (#32599) (#32673) + * Fixe a keystring misuse and refactor duplicates keystrings (#32668) (#32792) + * Bump relative-time-element to v4.4.4 (#32739) +* PERFORMANCE + * Make wiki pages visit fast (#32732) (#32745) +* MISC + * Don't create action when syncing mirror pull refs (#32659) (#32664) + ## [1.22.4](https://github.com/go-gitea/gitea/releases/tag/v1.22.4) - 2024-11-14 * SECURITY From cc1fdc84ca0e51e25b6190010144af10e28ca082 Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Thu, 20 Feb 2025 10:57:40 +0100 Subject: [PATCH 13/16] Use test context in tests and new loop system in benchmarks (#33648) Replace all contexts in tests with go1.24 t.Context() --------- Co-authored-by: Giteabot Co-authored-by: wxiaoguang --- cmd/hook_test.go | 3 +- cmd/migrate_storage_test.go | 3 +- models/auth/oauth2_test.go | 2 +- models/issues/issue_test.go | 3 +- models/renderhelper/repo_comment_test.go | 7 +- models/renderhelper/repo_file_test.go | 13 +- models/renderhelper/repo_wiki_test.go | 7 +- models/renderhelper/simple_document_test.go | 3 +- models/repo/wiki_test.go | 3 +- models/unittest/fixtures_test.go | 4 +- models/user/avatar_test.go | 3 +- models/user/user_test.go | 7 +- models/webhook/webhook_test.go | 13 +- modules/cache/context_test.go | 5 +- modules/csv/csv_test.go | 3 +- modules/git/blame_sha256_test.go | 2 +- modules/git/blame_test.go | 2 +- modules/git/blob_test.go | 2 +- modules/git/command_race_test.go | 4 +- modules/git/command_test.go | 15 +- modules/git/commit_info_test.go | 7 +- modules/git/commit_submodule_file_test.go | 9 +- modules/git/commit_test.go | 3 +- modules/git/grep_test.go | 15 +- modules/git/notes_test.go | 9 +- modules/git/repo_branch_test.go | 2 +- modules/git/repo_test.go | 7 +- modules/git/submodule_test.go | 3 +- modules/git/url/url_test.go | 10 +- modules/globallock/globallock_test.go | 2 +- modules/globallock/locker_test.go | 22 +- modules/gtprof/trace_test.go | 2 +- modules/httplib/url_test.go | 4 +- modules/indexer/code/indexer_test.go | 15 +- modules/indexer/issues/indexer_test.go | 27 +- .../indexer/issues/internal/tests/tests.go | 16 +- modules/indexer/stats/indexer_test.go | 3 +- modules/lfs/http_client_test.go | 4 +- modules/lfs/transferadapter_test.go | 7 +- modules/log/event_writer_conn_test.go | 3 +- modules/log/logger_test.go | 9 +- modules/markup/console/console_test.go | 3 +- modules/markup/csv/csv_test.go | 3 +- modules/markup/html_test.go | 2 +- .../markdown/markdown_benchmark_test.go | 4 +- modules/markup/render_link_test.go | 3 +- modules/process/manager_test.go | 8 +- modules/queue/base_test.go | 4 +- modules/queue/manager_test.go | 9 +- modules/queue/workerqueue_test.go | 5 +- modules/testlogger/testlogger.go | 3 +- modules/util/runtime_test.go | 4 +- modules/util/util_test.go | 2 +- routers/api/actions/ping/ping_test.go | 3 +- routers/common/errpage_test.go | 3 +- routers/private/hook_verification_test.go | 3 +- services/actions/context_test.go | 3 +- services/auth/oauth2_test.go | 5 +- .../auth/source/oauth2/source_sync_test.go | 17 +- services/gitdiff/gitdiff_test.go | 5 +- services/gitdiff/submodule_test.go | 3 +- services/mailer/mail_test.go | 16 +- services/markup/renderhelper_mention_test.go | 9 +- services/migrations/codebase_test.go | 3 +- services/migrations/gitea_downloader_test.go | 3 +- services/migrations/gitea_uploader_test.go | 11 +- services/migrations/github_test.go | 3 +- services/migrations/gitlab_test.go | 5 +- services/migrations/gogs_test.go | 3 +- services/migrations/onedev_test.go | 3 +- services/pull/check_test.go | 3 +- services/repository/gitgraph/graph_test.go | 890 +++++++++--------- services/repository/lfs_test.go | 3 +- services/webhook/deliver_test.go | 9 +- services/webhook/dingtalk_test.go | 3 +- services/webhook/discord_test.go | 3 +- services/webhook/feishu_test.go | 3 +- services/webhook/matrix_test.go | 3 +- services/webhook/msteams_test.go | 3 +- services/webhook/packagist_test.go | 5 +- services/webhook/slack_test.go | 3 +- services/webhook/telegram_test.go | 3 +- tests/e2e/utils_e2e_test.go | 2 +- tests/integration/actions_job_test.go | 17 +- .../integration/actions_runner_modify_test.go | 3 +- tests/integration/actions_runner_test.go | 12 +- tests/integration/actions_variables_test.go | 3 +- .../api_activitypub_person_test.go | 3 +- .../api_helper_for_declarative_test.go | 3 +- tests/integration/api_private_serv_test.go | 4 +- tests/integration/api_pull_test.go | 7 +- .../integration/api_repo_file_create_test.go | 5 +- .../integration/api_repo_file_update_test.go | 3 +- .../integration/api_repo_files_change_test.go | 3 +- tests/integration/auth_ldap_test.go | 13 +- tests/integration/dump_restore_test.go | 7 +- .../git_helper_for_declarative_test.go | 6 +- tests/integration/git_lfs_ssh_test.go | 3 +- tests/integration/git_misc_test.go | 3 +- tests/integration/issue_test.go | 3 +- tests/integration/lfs_view_test.go | 3 +- tests/integration/linguist_test.go | 3 +- .../migration-test/migration_test.go | 9 +- tests/integration/mirror_pull_test.go | 3 +- tests/integration/mirror_push_test.go | 3 +- tests/integration/pull_merge_test.go | 17 +- tests/integration/repo_webhook_test.go | 3 +- tests/integration/wiki_test.go | 3 +- 108 files changed, 712 insertions(+), 794 deletions(-) diff --git a/cmd/hook_test.go b/cmd/hook_test.go index 91f24ff2b4..86cd4834f2 100644 --- a/cmd/hook_test.go +++ b/cmd/hook_test.go @@ -6,7 +6,6 @@ package cmd import ( "bufio" "bytes" - "context" "strings" "testing" @@ -15,7 +14,7 @@ import ( func TestPktLine(t *testing.T) { // test read - ctx := context.Background() + ctx := t.Context() s := strings.NewReader("0000") r := bufio.NewReader(s) result, err := readPktLine(ctx, r, pktLineTypeFlush) diff --git a/cmd/migrate_storage_test.go b/cmd/migrate_storage_test.go index 5d8c867993..f8fa95a927 100644 --- a/cmd/migrate_storage_test.go +++ b/cmd/migrate_storage_test.go @@ -4,7 +4,6 @@ package cmd import ( - "context" "os" "strings" "testing" @@ -53,7 +52,7 @@ func TestMigratePackages(t *testing.T) { assert.NotNil(t, v) assert.NotNil(t, f) - ctx := context.Background() + ctx := t.Context() p := t.TempDir() diff --git a/models/auth/oauth2_test.go b/models/auth/oauth2_test.go index 43daa0b5ec..fa89a58b14 100644 --- a/models/auth/oauth2_test.go +++ b/models/auth/oauth2_test.go @@ -25,7 +25,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) { func BenchmarkOAuth2Application_GenerateClientSecret(b *testing.B) { assert.NoError(b, unittest.PrepareTestDatabase()) app := unittest.AssertExistsAndLoadBean(b, &auth_model.OAuth2Application{ID: 1}) - for i := 0; i < b.N; i++ { + for b.Loop() { _, _ = app.GenerateClientSecret(db.DefaultContext) } } diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index dbbb1e4179..3f76a81bb6 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -4,7 +4,6 @@ package issues_test import ( - "context" "fmt" "sort" "sync" @@ -326,7 +325,7 @@ func TestCorrectIssueStats(t *testing.T) { wg.Wait() // Now we will get all issueID's that match the "Bugs are nasty" query. - issues, err := issues_model.Issues(context.TODO(), &issues_model.IssuesOptions{ + issues, err := issues_model.Issues(t.Context(), &issues_model.IssuesOptions{ Paginator: &db.ListOptions{ PageSize: issueAmount, }, diff --git a/models/renderhelper/repo_comment_test.go b/models/renderhelper/repo_comment_test.go index 01e20b9e02..776152db96 100644 --- a/models/renderhelper/repo_comment_test.go +++ b/models/renderhelper/repo_comment_test.go @@ -4,7 +4,6 @@ package renderhelper import ( - "context" "testing" repo_model "code.gitea.io/gitea/models/repo" @@ -21,7 +20,7 @@ func TestRepoComment(t *testing.T) { repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) t.Run("AutoLink", func(t *testing.T) { - rctx := NewRenderContextRepoComment(context.Background(), repo1).WithMarkupType(markdown.MarkupName) + rctx := NewRenderContextRepoComment(t.Context(), repo1).WithMarkupType(markdown.MarkupName) rendered, err := markup.RenderString(rctx, ` 65f1bf27bc3bf70f64657658635e66094edbcb4d #1 @@ -36,7 +35,7 @@ func TestRepoComment(t *testing.T) { }) t.Run("AbsoluteAndRelative", func(t *testing.T) { - rctx := NewRenderContextRepoComment(context.Background(), repo1).WithMarkupType(markdown.MarkupName) + rctx := NewRenderContextRepoComment(t.Context(), repo1).WithMarkupType(markdown.MarkupName) // It is Gitea's old behavior, the relative path is resolved to the repo path // It is different from GitHub, GitHub resolves relative links to current page's path @@ -56,7 +55,7 @@ func TestRepoComment(t *testing.T) { }) t.Run("WithCurrentRefPath", func(t *testing.T) { - rctx := NewRenderContextRepoComment(context.Background(), repo1, RepoCommentOptions{CurrentRefPath: "/commit/1234"}). + rctx := NewRenderContextRepoComment(t.Context(), repo1, RepoCommentOptions{CurrentRefPath: "/commit/1234"}). WithMarkupType(markdown.MarkupName) // the ref path is only used to render commit message: a commit message is rendered at the commit page with its commit ID path diff --git a/models/renderhelper/repo_file_test.go b/models/renderhelper/repo_file_test.go index 959648b660..29cb45f6f7 100644 --- a/models/renderhelper/repo_file_test.go +++ b/models/renderhelper/repo_file_test.go @@ -4,7 +4,6 @@ package renderhelper import ( - "context" "testing" repo_model "code.gitea.io/gitea/models/repo" @@ -22,7 +21,7 @@ func TestRepoFile(t *testing.T) { repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) t.Run("AutoLink", func(t *testing.T) { - rctx := NewRenderContextRepoFile(context.Background(), repo1).WithMarkupType(markdown.MarkupName) + rctx := NewRenderContextRepoFile(t.Context(), repo1).WithMarkupType(markdown.MarkupName) rendered, err := markup.RenderString(rctx, ` 65f1bf27bc3bf70f64657658635e66094edbcb4d #1 @@ -37,7 +36,7 @@ func TestRepoFile(t *testing.T) { }) t.Run("AbsoluteAndRelative", func(t *testing.T) { - rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}). + rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}). WithMarkupType(markdown.MarkupName) rendered, err := markup.RenderString(rctx, ` [/test](/test) @@ -55,7 +54,7 @@ func TestRepoFile(t *testing.T) { }) t.Run("WithCurrentRefPath", func(t *testing.T) { - rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{CurrentRefPath: "/commit/1234"}). + rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{CurrentRefPath: "/commit/1234"}). WithMarkupType(markdown.MarkupName) rendered, err := markup.RenderString(rctx, ` [/test](/test) @@ -68,7 +67,7 @@ func TestRepoFile(t *testing.T) { }) t.Run("WithCurrentRefPathByTag", func(t *testing.T) { - rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{ + rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{ CurrentRefPath: "/commit/1234", CurrentTreePath: "my-dir", }). @@ -89,7 +88,7 @@ func TestRepoFileOrgMode(t *testing.T) { repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) t.Run("Links", func(t *testing.T) { - rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{ + rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{ CurrentRefPath: "/commit/1234", CurrentTreePath: "my-dir", }).WithRelativePath("my-dir/a.org") @@ -106,7 +105,7 @@ func TestRepoFileOrgMode(t *testing.T) { }) t.Run("CodeHighlight", func(t *testing.T) { - rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org") + rctx := NewRenderContextRepoFile(t.Context(), repo1, RepoFileOptions{}).WithRelativePath("my-dir/a.org") rendered, err := markup.RenderString(rctx, ` #+begin_src c diff --git a/models/renderhelper/repo_wiki_test.go b/models/renderhelper/repo_wiki_test.go index beab2570e7..b24508f1f2 100644 --- a/models/renderhelper/repo_wiki_test.go +++ b/models/renderhelper/repo_wiki_test.go @@ -4,7 +4,6 @@ package renderhelper import ( - "context" "testing" repo_model "code.gitea.io/gitea/models/repo" @@ -20,7 +19,7 @@ func TestRepoWiki(t *testing.T) { repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) t.Run("AutoLink", func(t *testing.T) { - rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName) + rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName) rendered, err := markup.RenderString(rctx, ` 65f1bf27bc3bf70f64657658635e66094edbcb4d #1 @@ -35,7 +34,7 @@ func TestRepoWiki(t *testing.T) { }) t.Run("AbsoluteAndRelative", func(t *testing.T) { - rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName) + rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName) rendered, err := markup.RenderString(rctx, ` [/test](/test) [./test](./test) @@ -52,7 +51,7 @@ func TestRepoWiki(t *testing.T) { }) t.Run("PathInTag", func(t *testing.T) { - rctx := NewRenderContextRepoWiki(context.Background(), repo1).WithMarkupType(markdown.MarkupName) + rctx := NewRenderContextRepoWiki(t.Context(), repo1).WithMarkupType(markdown.MarkupName) rendered, err := markup.RenderString(rctx, `