code.gitea.io/gitea@v1.21.7/routers/web/repo/helper.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package repo 5 6 import ( 7 "net/url" 8 "sort" 9 10 "code.gitea.io/gitea/models/user" 11 "code.gitea.io/gitea/modules/context" 12 "code.gitea.io/gitea/modules/git" 13 ) 14 15 func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User { 16 if doer != nil { 17 sort.Slice(users, func(i, j int) bool { 18 if users[i].ID == users[j].ID { 19 return false 20 } 21 return users[i].ID == doer.ID // if users[i] is self, put it before others, so less=true 22 }) 23 } 24 return users 25 } 26 27 func HandleGitError(ctx *context.Context, msg string, err error) { 28 if git.IsErrNotExist(err) { 29 refType := "" 30 switch { 31 case ctx.Repo.IsViewBranch: 32 refType = "branch" 33 case ctx.Repo.IsViewTag: 34 refType = "tag" 35 case ctx.Repo.IsViewCommit: 36 refType = "commit" 37 } 38 ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_"+refType, ctx.Repo.TreePath, url.PathEscape(ctx.Repo.RefName)) 39 ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/" + refType + "/" + url.PathEscape(ctx.Repo.RefName) 40 ctx.NotFound(msg, err) 41 } else { 42 ctx.ServerError(msg, err) 43 } 44 }