mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 04:05:42 +01:00
Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551)
Found using `find . -type f -name '*.go' -print -exec vim {} -c ':%s/fmt\.Errorf(\(.*\)%v\(.*\)err/fmt.Errorf(\1%w\2err/g' -c ':wq' \;` Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
7c11a73833
commit
0ebb45cfe7
207 changed files with 857 additions and 857 deletions
|
@ -588,7 +588,7 @@ func runCreateUser(c *cli.Context) error {
|
|||
}
|
||||
|
||||
if err := user_model.CreateUser(u, overwriteDefault); err != nil {
|
||||
return fmt.Errorf("CreateUser: %v", err)
|
||||
return fmt.Errorf("CreateUser: %w", err)
|
||||
}
|
||||
|
||||
if c.Bool("access-token") {
|
||||
|
@ -735,7 +735,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
|
|||
Private: true,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("SearchRepositoryByName: %v", err)
|
||||
return fmt.Errorf("SearchRepositoryByName: %w", err)
|
||||
}
|
||||
if len(repos) == 0 {
|
||||
break
|
||||
|
|
|
@ -68,7 +68,7 @@ Ensure you are running in the correct environment or set the correct configurati
|
|||
If this is the intended configuration file complete the [database] section.`, setting.CustomConf)
|
||||
}
|
||||
if err := db.InitEngine(ctx); err != nil {
|
||||
return fmt.Errorf("unable to initialize the database using the configuration in %q. Error: %v", setting.CustomConf, err)
|
||||
return fmt.Errorf("unable to initialize the database using the configuration in %q. Error: %w", setting.CustomConf, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ func runDumpRepository(ctx *cli.Context) error {
|
|||
// make sure the directory doesn't exist or is empty, prevent from deleting user files
|
||||
repoDir := ctx.String("repo_dir")
|
||||
if exists, err := util.IsExist(repoDir); err != nil {
|
||||
return fmt.Errorf("unable to stat repo_dir %q: %v", repoDir, err)
|
||||
return fmt.Errorf("unable to stat repo_dir %q: %w", repoDir, err)
|
||||
} else if exists {
|
||||
if isDir, _ := util.IsDir(repoDir); !isDir {
|
||||
return fmt.Errorf("repo_dir %q already exists but it's not a directory", repoDir)
|
||||
|
|
|
@ -186,11 +186,11 @@ func runViewDo(c *cli.Context) error {
|
|||
|
||||
data, err := assets[0].Section.Asset(assets[0].Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %v", assets[0].Path, err)
|
||||
return fmt.Errorf("%s: %w", assets[0].Path, err)
|
||||
}
|
||||
|
||||
if _, err = os.Stdout.Write(data); err != nil {
|
||||
return fmt.Errorf("%s: %v", assets[0].Path, err)
|
||||
return fmt.Errorf("%s: %w", assets[0].Path, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -251,11 +251,11 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
|
|||
|
||||
data, err := a.Section.Asset(a.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %v", a.Path, err)
|
||||
return fmt.Errorf("%s: %w", a.Path, err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("%s: %v", dir, err)
|
||||
return fmt.Errorf("%s: %w", dir, err)
|
||||
}
|
||||
|
||||
perms := os.ModePerm & 0o666
|
||||
|
@ -263,7 +263,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
|
|||
fi, err := os.Lstat(dest)
|
||||
if err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("%s: %v", dest, err)
|
||||
return fmt.Errorf("%s: %w", dest, err)
|
||||
}
|
||||
} else if !overwrite && !rename {
|
||||
fmt.Printf("%s already exists; skipped.\n", dest)
|
||||
|
@ -272,7 +272,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
|
|||
return fmt.Errorf("%s already exists, but it's not a regular file", dest)
|
||||
} else if rename {
|
||||
if err := util.Rename(dest, dest+".bak"); err != nil {
|
||||
return fmt.Errorf("Error creating backup for %s: %v", dest, err)
|
||||
return fmt.Errorf("Error creating backup for %s: %w", dest, err)
|
||||
}
|
||||
// Attempt to respect file permissions mask (even if user:group will be set anew)
|
||||
perms = fi.Mode()
|
||||
|
@ -280,12 +280,12 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
|
|||
|
||||
file, err := os.OpenFile(dest, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, perms)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %v", dest, err)
|
||||
return fmt.Errorf("%s: %w", dest, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err = file.Write(data); err != nil {
|
||||
return fmt.Errorf("%s: %v", dest, err)
|
||||
return fmt.Errorf("%s: %w", dest, err)
|
||||
}
|
||||
|
||||
fmt.Println(dest)
|
||||
|
@ -325,7 +325,7 @@ func getPatterns(args []string) ([]glob.Glob, error) {
|
|||
pat := make([]glob.Glob, len(args))
|
||||
for i := range args {
|
||||
if g, err := glob.Compile(args[i], '/'); err != nil {
|
||||
return nil, fmt.Errorf("'%s': Invalid glob pattern: %v", args[i], err)
|
||||
return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err)
|
||||
} else {
|
||||
pat[i] = g
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@ func runHookPostReceive(c *cli.Context) error {
|
|||
|
||||
// First of all run update-server-info no matter what
|
||||
if _, _, err := git.NewCommand(ctx, "update-server-info").RunStdString(nil); err != nil {
|
||||
return fmt.Errorf("Failed to call 'git update-server-info': %v", err)
|
||||
return fmt.Errorf("Failed to call 'git update-server-info': %w", err)
|
||||
}
|
||||
|
||||
// Now if we're an internal don't do anything else
|
||||
|
|
|
@ -359,11 +359,11 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) {
|
|||
actions := make([]*Action, 0, opts.PageSize)
|
||||
|
||||
if err := sess.Desc("`action`.created_unix").Find(&actions); err != nil {
|
||||
return nil, fmt.Errorf("Find: %v", err)
|
||||
return nil, fmt.Errorf("Find: %w", err)
|
||||
}
|
||||
|
||||
if err := ActionList(actions).loadAttributes(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadAttributes: %v", err)
|
||||
return nil, fmt.Errorf("LoadAttributes: %w", err)
|
||||
}
|
||||
|
||||
return actions, nil
|
||||
|
@ -415,7 +415,7 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
|
|||
env := organization.OrgFromUser(opts.RequestedUser).AccessibleTeamReposEnv(opts.RequestedTeam)
|
||||
teamRepoIDs, err := env.RepoIDs(1, opts.RequestedUser.NumRepos)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetTeamRepositories: %v", err)
|
||||
return nil, fmt.Errorf("GetTeamRepositories: %w", err)
|
||||
}
|
||||
cond = cond.And(builder.In("repo_id", teamRepoIDs))
|
||||
}
|
||||
|
@ -477,14 +477,14 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error {
|
|||
// Add feeds for user self and all watchers.
|
||||
watchers, err = repo_model.GetWatchers(ctx, act.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get watchers: %v", err)
|
||||
return fmt.Errorf("get watchers: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Add feed for actioner.
|
||||
act.UserID = act.ActUserID
|
||||
if _, err = e.Insert(act); err != nil {
|
||||
return fmt.Errorf("insert new actioner: %v", err)
|
||||
return fmt.Errorf("insert new actioner: %w", err)
|
||||
}
|
||||
|
||||
if repoChanged {
|
||||
|
@ -493,7 +493,7 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error {
|
|||
|
||||
// check repo owner exist.
|
||||
if err := act.Repo.GetOwner(ctx); err != nil {
|
||||
return fmt.Errorf("can't get repo owner: %v", err)
|
||||
return fmt.Errorf("can't get repo owner: %w", err)
|
||||
}
|
||||
} else if act.Repo == nil {
|
||||
act.Repo = repo
|
||||
|
@ -504,7 +504,7 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error {
|
|||
act.ID = 0
|
||||
act.UserID = act.Repo.Owner.ID
|
||||
if err = db.Insert(ctx, act); err != nil {
|
||||
return fmt.Errorf("insert new actioner: %v", err)
|
||||
return fmt.Errorf("insert new actioner: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,7 +557,7 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error {
|
|||
}
|
||||
|
||||
if err = db.Insert(ctx, act); err != nil {
|
||||
return fmt.Errorf("insert new action: %v", err)
|
||||
return fmt.Errorf("insert new action: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ func (actions ActionList) loadUsers(ctx context.Context) (map[int64]*user_model.
|
|||
In("id", userIDs).
|
||||
Find(&userMaps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find user: %v", err)
|
||||
return nil, fmt.Errorf("find user: %w", err)
|
||||
}
|
||||
|
||||
for _, action := range actions {
|
||||
|
@ -62,7 +62,7 @@ func (actions ActionList) loadRepositories(ctx context.Context) error {
|
|||
repoMaps := make(map[int64]*repo_model.Repository, len(repoIDs))
|
||||
err := db.GetEngine(ctx).In("id", repoIDs).Find(&repoMaps)
|
||||
if err != nil {
|
||||
return fmt.Errorf("find repository: %v", err)
|
||||
return fmt.Errorf("find repository: %w", err)
|
||||
}
|
||||
|
||||
for _, action := range actions {
|
||||
|
|
|
@ -403,7 +403,7 @@ func (n *Notification) loadRepo(ctx context.Context) (err error) {
|
|||
if n.Repository == nil {
|
||||
n.Repository, err = repo_model.GetRepositoryByIDCtx(ctx, n.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getRepositoryByID [%d]: %v", n.RepoID, err)
|
||||
return fmt.Errorf("getRepositoryByID [%d]: %w", n.RepoID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -413,7 +413,7 @@ func (n *Notification) loadIssue(ctx context.Context) (err error) {
|
|||
if n.Issue == nil && n.IssueID != 0 {
|
||||
n.Issue, err = issues_model.GetIssueByID(ctx, n.IssueID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getIssueByID [%d]: %v", n.IssueID, err)
|
||||
return fmt.Errorf("getIssueByID [%d]: %w", n.IssueID, err)
|
||||
}
|
||||
return n.Issue.LoadAttributes(ctx)
|
||||
}
|
||||
|
@ -440,7 +440,7 @@ func (n *Notification) loadUser(ctx context.Context) (err error) {
|
|||
if n.User == nil {
|
||||
n.User, err = user_model.GetUserByIDCtx(ctx, n.UserID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getUserByID [%d]: %v", n.UserID, err)
|
||||
return fmt.Errorf("getUserByID [%d]: %w", n.UserID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -49,32 +49,32 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom
|
|||
stats := &ActivityStats{Code: &git.CodeActivityStats{}}
|
||||
if releases {
|
||||
if err := stats.FillReleases(repo.ID, timeFrom); err != nil {
|
||||
return nil, fmt.Errorf("FillReleases: %v", err)
|
||||
return nil, fmt.Errorf("FillReleases: %w", err)
|
||||
}
|
||||
}
|
||||
if prs {
|
||||
if err := stats.FillPullRequests(repo.ID, timeFrom); err != nil {
|
||||
return nil, fmt.Errorf("FillPullRequests: %v", err)
|
||||
return nil, fmt.Errorf("FillPullRequests: %w", err)
|
||||
}
|
||||
}
|
||||
if issues {
|
||||
if err := stats.FillIssues(repo.ID, timeFrom); err != nil {
|
||||
return nil, fmt.Errorf("FillIssues: %v", err)
|
||||
return nil, fmt.Errorf("FillIssues: %w", err)
|
||||
}
|
||||
}
|
||||
if err := stats.FillUnresolvedIssues(repo.ID, timeFrom, issues, prs); err != nil {
|
||||
return nil, fmt.Errorf("FillUnresolvedIssues: %v", err)
|
||||
return nil, fmt.Errorf("FillUnresolvedIssues: %w", err)
|
||||
}
|
||||
if code {
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||
return nil, fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
code, err := gitRepo.GetCodeActivityStats(timeFrom, repo.DefaultBranch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FillFromGit: %v", err)
|
||||
return nil, fmt.Errorf("FillFromGit: %w", err)
|
||||
}
|
||||
stats.Code = code
|
||||
}
|
||||
|
@ -85,13 +85,13 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom
|
|||
func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository, timeFrom time.Time, count int) ([]*ActivityAuthorData, error) {
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||
return nil, fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
code, err := gitRepo.GetCodeActivityStats(timeFrom, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FillFromGit: %v", err)
|
||||
return nil, fmt.Errorf("FillFromGit: %w", err)
|
||||
}
|
||||
if code.Authors == nil {
|
||||
return nil, nil
|
||||
|
|
|
@ -226,7 +226,7 @@ func DeleteGPGKey(doer *user_model.User, id int64) (err error) {
|
|||
if IsErrGPGKeyNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("GetPublicKeyByID: %v", err)
|
||||
return fmt.Errorf("GetPublicKeyByID: %w", err)
|
||||
}
|
||||
|
||||
// Check if user has access to delete this key.
|
||||
|
|
|
@ -130,7 +130,7 @@ func AddPublicKey(ownerID int64, name, content string, authSourceID int64) (*Pub
|
|||
LoginSourceID: authSourceID,
|
||||
}
|
||||
if err = addKey(ctx, key); err != nil {
|
||||
return nil, fmt.Errorf("addKey: %v", err)
|
||||
return nil, fmt.Errorf("addKey: %w", err)
|
||||
}
|
||||
|
||||
return key, committer.Commit()
|
||||
|
|
|
@ -151,7 +151,7 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey
|
|||
pkey.Content = content
|
||||
pkey.Name = name
|
||||
if err = addKey(ctx, pkey); err != nil {
|
||||
return nil, fmt.Errorf("addKey: %v", err)
|
||||
return nil, fmt.Errorf("addKey: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ func CalcFingerprint(publicKeyContent string) (string, error) {
|
|||
log.Info("%s", publicKeyContent)
|
||||
return "", err
|
||||
}
|
||||
return "", fmt.Errorf("%s: %v", fnName, err)
|
||||
return "", fmt.Errorf("%s: %w", fnName, err)
|
||||
}
|
||||
return fp, nil
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ const ssh2keyStart = "---- BEGIN SSH2 PUBLIC KEY ----"
|
|||
func extractTypeFromBase64Key(key string) (string, error) {
|
||||
b, err := base64.StdEncoding.DecodeString(key)
|
||||
if err != nil || len(b) < 4 {
|
||||
return "", fmt.Errorf("invalid key format: %v", err)
|
||||
return "", fmt.Errorf("invalid key format: %w", err)
|
||||
}
|
||||
|
||||
keyLength := int(binary.BigEndian.Uint32(b))
|
||||
|
@ -85,7 +85,7 @@ func parseKeyString(content string) (string, error) {
|
|||
|
||||
t, err := extractTypeFromBase64Key(keyContent)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("extractTypeFromBase64Key: %v", err)
|
||||
return "", fmt.Errorf("extractTypeFromBase64Key: %w", err)
|
||||
}
|
||||
keyType = t
|
||||
} else {
|
||||
|
@ -104,14 +104,14 @@ func parseKeyString(content string) (string, error) {
|
|||
var pk rsa.PublicKey
|
||||
_, err2 := asn1.Unmarshal(block.Bytes, &pk)
|
||||
if err2 != nil {
|
||||
return "", fmt.Errorf("failed to parse DER encoded public key as either PKIX or PEM RSA Key: %v %v", err, err2)
|
||||
return "", fmt.Errorf("failed to parse DER encoded public key as either PKIX or PEM RSA Key: %v %w", err, err2)
|
||||
}
|
||||
pub = &pk
|
||||
}
|
||||
|
||||
sshKey, err := ssh.NewPublicKey(pub)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to convert to ssh public key: %v", err)
|
||||
return "", fmt.Errorf("unable to convert to ssh public key: %w", err)
|
||||
}
|
||||
content = string(ssh.MarshalAuthorizedKey(sshKey))
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func parseKeyString(content string) (string, error) {
|
|||
// If keyType is not given, extract it from content. If given, validate it.
|
||||
t, err := extractTypeFromBase64Key(keyContent)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("extractTypeFromBase64Key: %v", err)
|
||||
return "", fmt.Errorf("extractTypeFromBase64Key: %w", err)
|
||||
}
|
||||
if len(keyType) == 0 {
|
||||
keyType = t
|
||||
|
@ -149,7 +149,7 @@ func parseKeyString(content string) (string, error) {
|
|||
// Finally we need to check whether we can actually read the proposed key:
|
||||
_, _, _, _, err := ssh.ParseAuthorizedKey([]byte(keyType + " " + keyContent + " " + keyComment))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("invalid ssh public key: %v", err)
|
||||
return "", fmt.Errorf("invalid ssh public key: %w", err)
|
||||
}
|
||||
return keyType + " " + keyContent + " " + keyComment, nil
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ func CheckPublicKeyString(content string) (_ string, err error) {
|
|||
keyType, length, err = SSHKeyGenParsePublicKey(content)
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s: %v", fnName, err)
|
||||
return "", fmt.Errorf("%s: %w", fnName, err)
|
||||
}
|
||||
log.Trace("Key info [native: %v]: %s-%d", setting.SSH.StartBuiltinServer, keyType, length)
|
||||
|
||||
|
@ -220,7 +220,7 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
|
|||
if strings.Contains(err.Error(), "ssh: unknown key algorithm") {
|
||||
return "", 0, ErrKeyUnableVerify{err.Error()}
|
||||
}
|
||||
return "", 0, fmt.Errorf("ParsePublicKey: %v", err)
|
||||
return "", 0, fmt.Errorf("ParsePublicKey: %w", err)
|
||||
}
|
||||
|
||||
// The ssh library can parse the key, so next we find out what key exactly we have.
|
||||
|
@ -267,12 +267,12 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
|
|||
func writeTmpKeyFile(content string) (string, error) {
|
||||
tmpFile, err := os.CreateTemp(setting.SSH.KeyTestPath, "gitea_keytest")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("TempFile: %v", err)
|
||||
return "", fmt.Errorf("TempFile: %w", err)
|
||||
}
|
||||
defer tmpFile.Close()
|
||||
|
||||
if _, err = tmpFile.WriteString(content); err != nil {
|
||||
return "", fmt.Errorf("WriteString: %v", err)
|
||||
return "", fmt.Errorf("WriteString: %w", err)
|
||||
}
|
||||
return tmpFile.Name(), nil
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ func writeTmpKeyFile(content string) (string, error) {
|
|||
func SSHKeyGenParsePublicKey(key string) (string, int, error) {
|
||||
tmpName, err := writeTmpKeyFile(key)
|
||||
if err != nil {
|
||||
return "", 0, fmt.Errorf("writeTmpKeyFile: %v", err)
|
||||
return "", 0, fmt.Errorf("writeTmpKeyFile: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := util.Remove(tmpName); err != nil {
|
||||
|
|
|
@ -51,7 +51,7 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public
|
|||
LoginSourceID: authSourceID,
|
||||
}
|
||||
if err = db.Insert(ctx, key); err != nil {
|
||||
return nil, fmt.Errorf("addKey: %v", err)
|
||||
return nil, fmt.Errorf("addKey: %w", err)
|
||||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
|
|
|
@ -570,7 +570,7 @@ func DeleteOAuth2RelictsByUserID(ctx context.Context, userID int64) error {
|
|||
&OAuth2Application{UID: userID},
|
||||
&OAuth2Grant{UserID: userID},
|
||||
); err != nil {
|
||||
return fmt.Errorf("DeleteBeans: %v", err)
|
||||
return fmt.Errorf("DeleteBeans: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -86,7 +86,7 @@ func init() {
|
|||
var err error
|
||||
successfulAccessTokenCache, err = lru.New(setting.SuccessfulTokensCacheSize)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to allocate AccessToken cache: %v", err)
|
||||
return fmt.Errorf("unable to allocate AccessToken cache: %w", err)
|
||||
}
|
||||
} else {
|
||||
successfulAccessTokenCache = nil
|
||||
|
|
|
@ -130,7 +130,7 @@ func SyncAllTables() error {
|
|||
func InitEngine(ctx context.Context) error {
|
||||
xormEngine, err := newXORMEngine()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to database: %v", err)
|
||||
return fmt.Errorf("failed to connect to database: %w", err)
|
||||
}
|
||||
|
||||
xormEngine.SetMapper(names.GonicMapper{})
|
||||
|
@ -189,16 +189,16 @@ func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine)
|
|||
// However, we should think carefully about should we support re-install on an installed instance,
|
||||
// as there may be other problems due to secret reinitialization.
|
||||
if err = migrateFunc(x); err != nil {
|
||||
return fmt.Errorf("migrate: %v", err)
|
||||
return fmt.Errorf("migrate: %w", err)
|
||||
}
|
||||
|
||||
if err = SyncAllTables(); err != nil {
|
||||
return fmt.Errorf("sync database struct error: %v", err)
|
||||
return fmt.Errorf("sync database struct error: %w", err)
|
||||
}
|
||||
|
||||
for _, initFunc := range initFuncs {
|
||||
if err := initFunc(); err != nil {
|
||||
return fmt.Errorf("initFunc failed: %v", err)
|
||||
return fmt.Errorf("initFunc failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ type WhitelistOptions struct {
|
|||
// to avoid unnecessary whitelist delete and regenerate.
|
||||
func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) {
|
||||
if err = repo.GetOwner(ctx); err != nil {
|
||||
return fmt.Errorf("GetOwner: %v", err)
|
||||
return fmt.Errorf("GetOwner: %w", err)
|
||||
}
|
||||
|
||||
whitelist, err := updateUserWhitelist(ctx, repo, protectBranch.WhitelistUserIDs, opts.UserIDs)
|
||||
|
@ -313,13 +313,13 @@ func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, prote
|
|||
// Make sure protectBranch.ID is not 0 for whitelists
|
||||
if protectBranch.ID == 0 {
|
||||
if _, err = db.GetEngine(ctx).Insert(protectBranch); err != nil {
|
||||
return fmt.Errorf("Insert: %v", err)
|
||||
return fmt.Errorf("Insert: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err = db.GetEngine(ctx).ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -378,11 +378,11 @@ func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, curre
|
|||
for _, userID := range newWhitelist {
|
||||
user, err := user_model.GetUserByIDCtx(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
|
||||
return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err)
|
||||
}
|
||||
perm, err := access_model.GetUserRepoPermission(ctx, repo, user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
|
||||
return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err)
|
||||
}
|
||||
|
||||
if !perm.CanWrite(unit.TypeCode) {
|
||||
|
@ -405,7 +405,7 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre
|
|||
|
||||
teams, err := organization.GetTeamsWithAccessToRepo(ctx, repo.OwnerID, repo.ID, perm.AccessModeRead)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetTeamsWithAccessToRepo [org_id: %d, repo_id: %d]: %v", repo.OwnerID, repo.ID, err)
|
||||
return nil, fmt.Errorf("GetTeamsWithAccessToRepo [org_id: %d, repo_id: %d]: %w", repo.OwnerID, repo.ID, err)
|
||||
}
|
||||
|
||||
whitelist = make([]int64, 0, len(teams))
|
||||
|
|
|
@ -128,13 +128,13 @@ func (status *CommitStatus) loadAttributes(ctx context.Context) (err error) {
|
|||
if status.Repo == nil {
|
||||
status.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, status.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getRepositoryByID [%d]: %v", status.RepoID, err)
|
||||
return fmt.Errorf("getRepositoryByID [%d]: %w", status.RepoID, err)
|
||||
}
|
||||
}
|
||||
if status.Creator == nil && status.CreatorID > 0 {
|
||||
status.Creator, err = user_model.GetUserByIDCtx(ctx, status.CreatorID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getUserByID [%d]: %v", status.CreatorID, err)
|
||||
return fmt.Errorf("getUserByID [%d]: %w", status.CreatorID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -294,12 +294,12 @@ func NewCommitStatus(opts NewCommitStatusOptions) error {
|
|||
// Get the next Status Index
|
||||
idx, err := GetNextCommitStatusIndex(opts.Repo.ID, opts.SHA)
|
||||
if err != nil {
|
||||
return fmt.Errorf("generate commit status index failed: %v", err)
|
||||
return fmt.Errorf("generate commit status index failed: %w", err)
|
||||
}
|
||||
|
||||
ctx, committer, err := db.TxContext()
|
||||
if err != nil {
|
||||
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", opts.Repo.ID, opts.Creator.ID, opts.SHA, err)
|
||||
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", opts.Repo.ID, opts.Creator.ID, opts.SHA, err)
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
|
@ -316,7 +316,7 @@ func NewCommitStatus(opts NewCommitStatusOptions) error {
|
|||
|
||||
// Insert new CommitStatus
|
||||
if _, err = db.GetEngine(ctx).Insert(opts.CommitStatus); err != nil {
|
||||
return fmt.Errorf("Insert CommitStatus[%s, %s]: %v", repoPath, opts.SHA, err)
|
||||
return fmt.Errorf("Insert CommitStatus[%s, %s]: %w", repoPath, opts.SHA, err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
|
|
@ -316,7 +316,7 @@ func CopyLFS(ctx context.Context, newRepo, oldRepo *repo_model.Repository) error
|
|||
func GetRepoLFSSize(ctx context.Context, repoID int64) (int64, error) {
|
||||
lfsSize, err := db.GetEngine(ctx).Where("repository_id = ?", repoID).SumInt(new(LFSMetaObject), "size")
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err)
|
||||
return 0, fmt.Errorf("updateSize: GetLFSMetaObjects: %w", err)
|
||||
}
|
||||
return lfsSize, nil
|
||||
}
|
||||
|
|
|
@ -85,12 +85,12 @@ func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64)
|
|||
func toggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64, isCreate bool) (removed bool, comment *Comment, err error) {
|
||||
removed, err = toggleUserAssignee(ctx, issue, assigneeID)
|
||||
if err != nil {
|
||||
return false, nil, fmt.Errorf("UpdateIssueUserByAssignee: %v", err)
|
||||
return false, nil, fmt.Errorf("UpdateIssueUserByAssignee: %w", err)
|
||||
}
|
||||
|
||||
// Repo infos
|
||||
if err = issue.LoadRepo(ctx); err != nil {
|
||||
return false, nil, fmt.Errorf("loadRepo: %v", err)
|
||||
return false, nil, fmt.Errorf("loadRepo: %w", err)
|
||||
}
|
||||
|
||||
opts := &CreateCommentOptions{
|
||||
|
@ -104,7 +104,7 @@ func toggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.Use
|
|||
// Comment
|
||||
comment, err = CreateCommentCtx(ctx, opts)
|
||||
if err != nil {
|
||||
return false, nil, fmt.Errorf("createComment: %v", err)
|
||||
return false, nil, fmt.Errorf("createComment: %w", err)
|
||||
}
|
||||
|
||||
// if pull request is in the middle of creation - don't call webhook
|
||||
|
|
|
@ -573,13 +573,13 @@ func (c *Comment) UpdateAttachments(uuids []string) error {
|
|||
|
||||
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", uuids, err)
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err)
|
||||
}
|
||||
for i := 0; i < len(attachments); i++ {
|
||||
attachments[i].IssueID = c.IssueID
|
||||
attachments[i].CommentID = c.ID
|
||||
if err := repo_model.UpdateAttachment(ctx, attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err)
|
||||
return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
return committer.Commit()
|
||||
|
@ -874,7 +874,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
|
|||
// Check attachments
|
||||
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", opts.Attachments, err)
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err)
|
||||
}
|
||||
|
||||
for i := range attachments {
|
||||
|
@ -882,7 +882,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
|
|||
attachments[i].CommentID = comment.ID
|
||||
// No assign value could be 0, so ignore AllCols().
|
||||
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
|
||||
return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
case CommentTypeReopen, CommentTypeClose:
|
||||
|
@ -1034,7 +1034,7 @@ func CreateRefComment(doer *user_model.User, repo *repo_model.Repository, issue
|
|||
CommitSHA: commitSHA,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("check reference comment: %v", err)
|
||||
return fmt.Errorf("check reference comment: %w", err)
|
||||
} else if has {
|
||||
return nil
|
||||
}
|
||||
|
@ -1152,7 +1152,7 @@ func UpdateComment(c *Comment, doer *user_model.User) error {
|
|||
return err
|
||||
}
|
||||
if err := committer.Commit(); err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -196,7 +196,7 @@ func (issue *Issue) LoadRepo(ctx context.Context) (err error) {
|
|||
if issue.Repo == nil {
|
||||
issue.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, issue.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getRepositoryByID [%d]: %v", issue.RepoID, err)
|
||||
return fmt.Errorf("getRepositoryByID [%d]: %w", issue.RepoID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -234,7 +234,7 @@ func (issue *Issue) LoadLabels(ctx context.Context) (err error) {
|
|||
if issue.Labels == nil {
|
||||
issue.Labels, err = GetLabelsByIssueID(ctx, issue.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getLabelsByIssueID [%d]: %v", issue.ID, err)
|
||||
return fmt.Errorf("getLabelsByIssueID [%d]: %w", issue.ID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -252,7 +252,7 @@ func (issue *Issue) loadPoster(ctx context.Context) (err error) {
|
|||
issue.PosterID = -1
|
||||
issue.Poster = user_model.NewGhostUser()
|
||||
if !user_model.IsErrUserNotExist(err) {
|
||||
return fmt.Errorf("getUserByID.(poster) [%d]: %v", issue.PosterID, err)
|
||||
return fmt.Errorf("getUserByID.(poster) [%d]: %w", issue.PosterID, err)
|
||||
}
|
||||
err = nil
|
||||
return
|
||||
|
@ -268,7 +268,7 @@ func (issue *Issue) loadPullRequest(ctx context.Context) (err error) {
|
|||
if IsErrPullRequestNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("getPullRequestByIssueID [%d]: %v", issue.ID, err)
|
||||
return fmt.Errorf("getPullRequestByIssueID [%d]: %w", issue.ID, err)
|
||||
}
|
||||
issue.PullRequest.Issue = issue
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ func (issue *Issue) loadMilestone(ctx context.Context) (err error) {
|
|||
if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 {
|
||||
issue.Milestone, err = GetMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
|
||||
if err != nil && !IsErrMilestoneNotExist(err) {
|
||||
return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err)
|
||||
return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %w", issue.RepoID, issue.MilestoneID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -401,7 +401,7 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) {
|
|||
if issue.Attachments == nil {
|
||||
issue.Attachments, err = repo_model.GetAttachmentsByIssueID(ctx, issue.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getAttachmentsByIssueID [%d]: %v", issue.ID, err)
|
||||
return fmt.Errorf("getAttachmentsByIssueID [%d]: %w", issue.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -518,19 +518,19 @@ func (issue *Issue) getLabels(ctx context.Context) (err error) {
|
|||
|
||||
issue.Labels, err = GetLabelsByIssueID(ctx, issue.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getLabelsByIssueID: %v", err)
|
||||
return fmt.Errorf("getLabelsByIssueID: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func clearIssueLabels(ctx context.Context, issue *Issue, doer *user_model.User) (err error) {
|
||||
if err = issue.getLabels(ctx); err != nil {
|
||||
return fmt.Errorf("getLabels: %v", err)
|
||||
return fmt.Errorf("getLabels: %w", err)
|
||||
}
|
||||
|
||||
for i := range issue.Labels {
|
||||
if err = deleteIssueLabel(ctx, issue, issue.Labels[i], doer); err != nil {
|
||||
return fmt.Errorf("removeLabel: %v", err)
|
||||
return fmt.Errorf("removeLabel: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -565,7 +565,7 @@ func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) {
|
|||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -635,13 +635,13 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e
|
|||
|
||||
if len(toAdd) > 0 {
|
||||
if err = newIssueLabels(ctx, issue, toAdd, doer); err != nil {
|
||||
return fmt.Errorf("addLabels: %v", err)
|
||||
return fmt.Errorf("addLabels: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, l := range toRemove {
|
||||
if err = deleteIssueLabel(ctx, issue, l, doer); err != nil {
|
||||
return fmt.Errorf("removeLabel: %v", err)
|
||||
return fmt.Errorf("removeLabel: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -766,11 +766,11 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err
|
|||
defer committer.Close()
|
||||
|
||||
if err = UpdateIssueCols(ctx, issue, "name"); err != nil {
|
||||
return fmt.Errorf("updateIssueCols: %v", err)
|
||||
return fmt.Errorf("updateIssueCols: %w", err)
|
||||
}
|
||||
|
||||
if err = issue.LoadRepo(ctx); err != nil {
|
||||
return fmt.Errorf("loadRepo: %v", err)
|
||||
return fmt.Errorf("loadRepo: %w", err)
|
||||
}
|
||||
|
||||
opts := &CreateCommentOptions{
|
||||
|
@ -782,7 +782,7 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err
|
|||
NewTitle: issue.Title,
|
||||
}
|
||||
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||
return fmt.Errorf("createComment: %v", err)
|
||||
return fmt.Errorf("createComment: %w", err)
|
||||
}
|
||||
if err = issue.AddCrossReferences(ctx, doer, true); err != nil {
|
||||
return err
|
||||
|
@ -800,11 +800,11 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err
|
|||
defer committer.Close()
|
||||
|
||||
if err = UpdateIssueCols(ctx, issue, "ref"); err != nil {
|
||||
return fmt.Errorf("updateIssueCols: %v", err)
|
||||
return fmt.Errorf("updateIssueCols: %w", err)
|
||||
}
|
||||
|
||||
if err = issue.LoadRepo(ctx); err != nil {
|
||||
return fmt.Errorf("loadRepo: %v", err)
|
||||
return fmt.Errorf("loadRepo: %w", err)
|
||||
}
|
||||
oldRefFriendly := strings.TrimPrefix(oldRef, git.BranchPrefix)
|
||||
newRefFriendly := strings.TrimPrefix(issue.Ref, git.BranchPrefix)
|
||||
|
@ -818,7 +818,7 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err
|
|||
NewRef: newRefFriendly,
|
||||
}
|
||||
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||
return fmt.Errorf("createComment: %v", err)
|
||||
return fmt.Errorf("createComment: %w", err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
@ -850,12 +850,12 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
|
|||
defer committer.Close()
|
||||
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", uuids, err)
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err)
|
||||
}
|
||||
for i := 0; i < len(attachments); i++ {
|
||||
attachments[i].IssueID = issueID
|
||||
if err := repo_model.UpdateAttachment(ctx, attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err)
|
||||
return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
return committer.Commit()
|
||||
|
@ -871,28 +871,28 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er
|
|||
|
||||
hasContentHistory, err := HasIssueContentHistory(ctx, issue.ID, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("HasIssueContentHistory: %v", err)
|
||||
return fmt.Errorf("HasIssueContentHistory: %w", err)
|
||||
}
|
||||
if !hasContentHistory {
|
||||
if err = SaveIssueContentHistory(ctx, issue.PosterID, issue.ID, 0,
|
||||
issue.CreatedUnix, issue.Content, true); err != nil {
|
||||
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
||||
return fmt.Errorf("SaveIssueContentHistory: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
issue.Content = content
|
||||
|
||||
if err = UpdateIssueCols(ctx, issue, "content"); err != nil {
|
||||
return fmt.Errorf("UpdateIssueCols: %v", err)
|
||||
return fmt.Errorf("UpdateIssueCols: %w", err)
|
||||
}
|
||||
|
||||
if err = SaveIssueContentHistory(ctx, doer.ID, issue.ID, 0,
|
||||
timeutil.TimeStampNow(), issue.Content, false); err != nil {
|
||||
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
||||
return fmt.Errorf("SaveIssueContentHistory: %w", err)
|
||||
}
|
||||
|
||||
if err = issue.AddCrossReferences(ctx, doer, true); err != nil {
|
||||
return fmt.Errorf("addCrossReferences: %v", err)
|
||||
return fmt.Errorf("addCrossReferences: %w", err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
@ -969,7 +969,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
|
|||
if opts.Issue.MilestoneID > 0 {
|
||||
milestone, err := GetMilestoneByRepoID(ctx, opts.Issue.RepoID, opts.Issue.MilestoneID)
|
||||
if err != nil && !IsErrMilestoneNotExist(err) {
|
||||
return fmt.Errorf("getMilestoneByID: %v", err)
|
||||
return fmt.Errorf("getMilestoneByID: %w", err)
|
||||
}
|
||||
|
||||
// Assume milestone is invalid and drop silently.
|
||||
|
@ -1023,7 +1023,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
|
|||
// So we have to get all needed labels first.
|
||||
labels := make([]*Label, 0, len(opts.LabelIDs))
|
||||
if err = e.In("id", opts.LabelIDs).Find(&labels); err != nil {
|
||||
return fmt.Errorf("find all labels [label_ids: %v]: %v", opts.LabelIDs, err)
|
||||
return fmt.Errorf("find all labels [label_ids: %v]: %w", opts.LabelIDs, err)
|
||||
}
|
||||
|
||||
if err = opts.Issue.loadPoster(ctx); err != nil {
|
||||
|
@ -1037,7 +1037,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
|
|||
}
|
||||
|
||||
if err = newIssueLabel(ctx, opts.Issue, label, opts.Issue.Poster); err != nil {
|
||||
return fmt.Errorf("addLabel [id: %d]: %v", label.ID, err)
|
||||
return fmt.Errorf("addLabel [id: %d]: %w", label.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1049,13 +1049,13 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
|
|||
if len(opts.Attachments) > 0 {
|
||||
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", opts.Attachments, err)
|
||||
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err)
|
||||
}
|
||||
|
||||
for i := 0; i < len(attachments); i++ {
|
||||
attachments[i].IssueID = opts.Issue.ID
|
||||
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err)
|
||||
return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1090,11 +1090,11 @@ func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids
|
|||
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("newIssue: %v", err)
|
||||
return fmt.Errorf("newIssue: %w", err)
|
||||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1614,7 +1614,7 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
|
|||
ids[i] = u.ID
|
||||
}
|
||||
if err := UpdateIssueUsersByMentions(ctx, issueID, ids); err != nil {
|
||||
return fmt.Errorf("UpdateIssueUsersByMentions: %v", err)
|
||||
return fmt.Errorf("UpdateIssueUsersByMentions: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1992,7 +1992,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
|
|||
defer committer.Close()
|
||||
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
return nil, false, fmt.Errorf("loadRepo: %v", err)
|
||||
return nil, false, fmt.Errorf("loadRepo: %w", err)
|
||||
}
|
||||
|
||||
// Reload the issue
|
||||
|
@ -2020,7 +2020,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
|
|||
}
|
||||
_, err := CreateCommentCtx(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("createComment: %v", err)
|
||||
return nil, false, fmt.Errorf("createComment: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2056,7 +2056,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us
|
|||
|
||||
// Make the comment
|
||||
if _, err = createDeadlineComment(ctx, doer, issue, deadlineUnix); err != nil {
|
||||
return fmt.Errorf("createRemovedDueDateComment: %v", err)
|
||||
return fmt.Errorf("createRemovedDueDateComment: %w", err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
@ -2093,7 +2093,7 @@ func (issue *Issue) GetParticipantIDsByIssue(ctx context.Context) ([]int64, erro
|
|||
Join("INNER", "`user`", "`user`.id = `comment`.poster_id").
|
||||
Distinct("poster_id").
|
||||
Find(&userIDs); err != nil {
|
||||
return nil, fmt.Errorf("get poster IDs: %v", err)
|
||||
return nil, fmt.Errorf("get poster IDs: %w", err)
|
||||
}
|
||||
if !util.IsInt64InSlice(issue.PosterID, userIDs) {
|
||||
return append(userIDs, issue.PosterID), nil
|
||||
|
@ -2151,10 +2151,10 @@ func FindAndUpdateIssueMentions(ctx context.Context, issue *Issue, doer *user_mo
|
|||
rawMentions := references.FindAllMentionsMarkdown(content)
|
||||
mentions, err = ResolveIssueMentionsByVisibility(ctx, issue, doer, rawMentions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
|
||||
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err)
|
||||
}
|
||||
if err = UpdateIssueMentions(ctx, issue.ID, mentions); err != nil {
|
||||
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
|
||||
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err)
|
||||
}
|
||||
return mentions, err
|
||||
}
|
||||
|
@ -2206,7 +2206,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
|
|||
Where("team_repo.repo_id=?", issue.Repo.ID).
|
||||
In("team.lower_name", mentionTeams).
|
||||
Find(&teams); err != nil {
|
||||
return nil, fmt.Errorf("find mentioned teams: %v", err)
|
||||
return nil, fmt.Errorf("find mentioned teams: %w", err)
|
||||
}
|
||||
if len(teams) != 0 {
|
||||
checked := make([]int64, 0, len(teams))
|
||||
|
@ -2222,7 +2222,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
|
|||
}
|
||||
has, err := db.GetEngine(ctx).Get(&organization.TeamUnit{OrgID: issue.Repo.Owner.ID, TeamID: team.ID, Type: unittype})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get team units (%d): %v", team.ID, err)
|
||||
return nil, fmt.Errorf("get team units (%d): %w", team.ID, err)
|
||||
}
|
||||
if has {
|
||||
checked = append(checked, team.ID)
|
||||
|
@ -2237,7 +2237,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
|
|||
And("`user`.is_active = ?", true).
|
||||
And("`user`.prohibit_login = ?", false).
|
||||
Find(&teamusers); err != nil {
|
||||
return nil, fmt.Errorf("get teams users: %v", err)
|
||||
return nil, fmt.Errorf("get teams users: %w", err)
|
||||
}
|
||||
if len(teamusers) > 0 {
|
||||
users = make([]*user_model.User, 0, len(teamusers))
|
||||
|
@ -2273,7 +2273,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
|
|||
And("`user`.prohibit_login = ?", false).
|
||||
In("`user`.lower_name", mentionUsers).
|
||||
Find(&unchecked); err != nil {
|
||||
return nil, fmt.Errorf("find mentioned users: %v", err)
|
||||
return nil, fmt.Errorf("find mentioned users: %w", err)
|
||||
}
|
||||
for _, user := range unchecked {
|
||||
if already := resolved[user.LowerName]; already || user.IsOrganization() {
|
||||
|
@ -2282,7 +2282,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
|
|||
// Normal users must have read access to the referencing issue
|
||||
perm, err := access_model.GetUserRepoPermission(ctx, issue.Repo, user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetUserRepoPermission [%d]: %v", user.ID, err)
|
||||
return nil, fmt.Errorf("GetUserRepoPermission [%d]: %w", user.ID, err)
|
||||
}
|
||||
if !perm.CanReadIssuesOrPulls(issue.IsPull) {
|
||||
continue
|
||||
|
|
|
@ -51,7 +51,7 @@ func (issues IssueList) loadRepositories(ctx context.Context) ([]*repo_model.Rep
|
|||
In("id", repoIDs[:limit]).
|
||||
Find(&repoMaps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find repository: %v", err)
|
||||
return nil, fmt.Errorf("find repository: %w", err)
|
||||
}
|
||||
left -= limit
|
||||
repoIDs = repoIDs[limit:]
|
||||
|
@ -161,7 +161,7 @@ func (issues IssueList) loadLabels(ctx context.Context) error {
|
|||
err = rows.Scan(&labelIssue)
|
||||
if err != nil {
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadLabels: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadLabels: Close: %w", err1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ func (issues IssueList) loadLabels(ctx context.Context) error {
|
|||
// When there are no rows left and we try to close it.
|
||||
// Since that is not relevant for us, we can safely ignore it.
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadLabels: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadLabels: Close: %w", err1)
|
||||
}
|
||||
left -= limit
|
||||
issueIDs = issueIDs[limit:]
|
||||
|
@ -287,7 +287,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error {
|
|||
err = rows.Scan(&assigneeIssue)
|
||||
if err != nil {
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadAssignees: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadAssignees: Close: %w", err1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error {
|
|||
assignees[assigneeIssue.IssueAssignee.IssueID] = append(assignees[assigneeIssue.IssueAssignee.IssueID], assigneeIssue.Assignee)
|
||||
}
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadAssignees: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadAssignees: Close: %w", err1)
|
||||
}
|
||||
left -= limit
|
||||
issueIDs = issueIDs[limit:]
|
||||
|
@ -342,14 +342,14 @@ func (issues IssueList) loadPullRequests(ctx context.Context) error {
|
|||
err = rows.Scan(&pr)
|
||||
if err != nil {
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadPullRequests: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadPullRequests: Close: %w", err1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
pullRequestMaps[pr.IssueID] = &pr
|
||||
}
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadPullRequests: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadPullRequests: Close: %w", err1)
|
||||
}
|
||||
left -= limit
|
||||
issuesIDs = issuesIDs[limit:]
|
||||
|
@ -387,14 +387,14 @@ func (issues IssueList) loadAttachments(ctx context.Context) (err error) {
|
|||
err = rows.Scan(&attachment)
|
||||
if err != nil {
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadAttachments: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadAttachments: Close: %w", err1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
attachments[attachment.IssueID] = append(attachments[attachment.IssueID], &attachment)
|
||||
}
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadAttachments: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadAttachments: Close: %w", err1)
|
||||
}
|
||||
left -= limit
|
||||
issuesIDs = issuesIDs[limit:]
|
||||
|
@ -433,14 +433,14 @@ func (issues IssueList) loadComments(ctx context.Context, cond builder.Cond) (er
|
|||
err = rows.Scan(&comment)
|
||||
if err != nil {
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadComments: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadComments: Close: %w", err1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
comments[comment.IssueID] = append(comments[comment.IssueID], &comment)
|
||||
}
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadComments: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadComments: Close: %w", err1)
|
||||
}
|
||||
left -= limit
|
||||
issuesIDs = issuesIDs[limit:]
|
||||
|
@ -492,14 +492,14 @@ func (issues IssueList) loadTotalTrackedTimes(ctx context.Context) (err error) {
|
|||
err = rows.Scan(&totalTime)
|
||||
if err != nil {
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %w", err1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
trackedTimes[totalTime.IssueID] = totalTime.Time
|
||||
}
|
||||
if err1 := rows.Close(); err1 != nil {
|
||||
return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %v", err1)
|
||||
return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %w", err1)
|
||||
}
|
||||
left -= limit
|
||||
ids = ids[limit:]
|
||||
|
@ -514,35 +514,35 @@ func (issues IssueList) loadTotalTrackedTimes(ctx context.Context) (err error) {
|
|||
// loadAttributes loads all attributes, expect for attachments and comments
|
||||
func (issues IssueList) loadAttributes(ctx context.Context) error {
|
||||
if _, err := issues.loadRepositories(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadRepositories: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadRepositories: %w", err)
|
||||
}
|
||||
|
||||
if err := issues.loadPosters(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadPosters: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadPosters: %w", err)
|
||||
}
|
||||
|
||||
if err := issues.loadLabels(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadLabels: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadLabels: %w", err)
|
||||
}
|
||||
|
||||
if err := issues.loadMilestones(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadMilestones: %w", err)
|
||||
}
|
||||
|
||||
if err := issues.loadProjects(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadProjects: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadProjects: %w", err)
|
||||
}
|
||||
|
||||
if err := issues.loadAssignees(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadAssignees: %w", err)
|
||||
}
|
||||
|
||||
if err := issues.loadPullRequests(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadPullRequests: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadPullRequests: %w", err)
|
||||
}
|
||||
|
||||
if err := issues.loadTotalTrackedTimes(ctx); err != nil {
|
||||
return fmt.Errorf("issue.loadAttributes: loadTotalTrackedTimes: %v", err)
|
||||
return fmt.Errorf("issue.loadAttributes: loadTotalTrackedTimes: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -29,7 +29,7 @@ func init() {
|
|||
func NewIssueUsers(ctx context.Context, repo *repo_model.Repository, issue *Issue) error {
|
||||
assignees, err := repo_model.GetRepoAssignees(ctx, repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getAssignees: %v", err)
|
||||
return fmt.Errorf("getAssignees: %w", err)
|
||||
}
|
||||
|
||||
// Poster can be anyone, append later if not one of assignees.
|
||||
|
|
|
@ -334,7 +334,7 @@ func (pr *PullRequest) ResolveCrossReferences(ctx context.Context) ([]*Comment,
|
|||
In("ref_action", []references.XRefAction{references.XRefActionCloses, references.XRefActionReopens}).
|
||||
OrderBy("id").
|
||||
Find(&unfiltered); err != nil {
|
||||
return nil, fmt.Errorf("get reference: %v", err)
|
||||
return nil, fmt.Errorf("get reference: %w", err)
|
||||
}
|
||||
|
||||
refs := make([]*Comment, 0, len(unfiltered))
|
||||
|
|
|
@ -667,7 +667,7 @@ func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *us
|
|||
}
|
||||
|
||||
if err = newIssueLabel(ctx, issue, label, doer); err != nil {
|
||||
return fmt.Errorf("newIssueLabel: %v", err)
|
||||
return fmt.Errorf("newIssueLabel: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ func (pr *PullRequest) loadAttributes(ctx context.Context) (err error) {
|
|||
pr.MergerID = -1
|
||||
pr.Merger = user_model.NewGhostUser()
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("getUserByID [%d]: %v", pr.MergerID, err)
|
||||
return fmt.Errorf("getUserByID [%d]: %w", pr.MergerID, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ func (pr *PullRequest) LoadHeadRepoCtx(ctx context.Context) (err error) {
|
|||
|
||||
pr.HeadRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.HeadRepoID)
|
||||
if err != nil && !repo_model.IsErrRepoNotExist(err) { // Head repo maybe deleted, but it should still work
|
||||
return fmt.Errorf("getRepositoryByID(head): %v", err)
|
||||
return fmt.Errorf("getRepositoryByID(head): %w", err)
|
||||
}
|
||||
pr.isHeadRepoLoaded = true
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ func (pr *PullRequest) LoadBaseRepoCtx(ctx context.Context) (err error) {
|
|||
|
||||
pr.BaseRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.BaseRepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("repo_model.GetRepositoryByID(base): %v", err)
|
||||
return fmt.Errorf("repo_model.GetRepositoryByID(base): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -482,7 +482,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) {
|
|||
}
|
||||
|
||||
if _, err := changeIssueStatus(ctx, pr.Issue, pr.Merger, true, true); err != nil {
|
||||
return false, fmt.Errorf("Issue.changeStatus: %v", err)
|
||||
return false, fmt.Errorf("Issue.changeStatus: %w", err)
|
||||
}
|
||||
|
||||
// reset the conflicted files as there cannot be any if we're merged
|
||||
|
@ -490,7 +490,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) {
|
|||
|
||||
// We need to save all of the data used to compute this merge as it may have already been changed by TestPatch. FIXME: need to set some state to prevent TestPatch from running whilst we are merging.
|
||||
if _, err := sess.Where("id = ?", pr.ID).Cols("has_merged, status, merge_base, merged_commit_id, merger_id, merged_unix, conflicted_files").Update(pr); err != nil {
|
||||
return false, fmt.Errorf("Failed to update pr[%d]: %v", pr.ID, err)
|
||||
return false, fmt.Errorf("Failed to update pr[%d]: %w", pr.ID, err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
@ -507,7 +507,7 @@ func NewPullRequest(outerCtx context.Context, repo *repo_model.Repository, issue
|
|||
|
||||
idx, err := db.GetNextResourceIndex(ctx, "issue_index", repo.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("generate pull request index failed: %v", err)
|
||||
return fmt.Errorf("generate pull request index failed: %w", err)
|
||||
}
|
||||
|
||||
issue.Index = idx
|
||||
|
@ -522,18 +522,18 @@ func NewPullRequest(outerCtx context.Context, repo *repo_model.Repository, issue
|
|||
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("newIssue: %v", err)
|
||||
return fmt.Errorf("newIssue: %w", err)
|
||||
}
|
||||
|
||||
pr.Index = issue.Index
|
||||
pr.BaseRepo = repo
|
||||
pr.IssueID = issue.ID
|
||||
if err = db.Insert(ctx, pr); err != nil {
|
||||
return fmt.Errorf("insert pull repo: %v", err)
|
||||
return fmt.Errorf("insert pull repo: %w", err)
|
||||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -168,7 +168,7 @@ func (prs PullRequestList) loadAttributes(ctx context.Context) error {
|
|||
Where("id > 0").
|
||||
In("id", issueIDs).
|
||||
Find(&issues); err != nil {
|
||||
return fmt.Errorf("find issues: %v", err)
|
||||
return fmt.Errorf("find issues: %w", err)
|
||||
}
|
||||
|
||||
set := make(map[int64]*Issue)
|
||||
|
@ -205,7 +205,7 @@ func (prs PullRequestList) InvalidateCodeComments(ctx context.Context, doer *use
|
|||
Where("type = ? and invalidated = ?", CommentTypeCode, false).
|
||||
In("issue_id", issueIDs).
|
||||
Find(&codeComments); err != nil {
|
||||
return fmt.Errorf("find code comments: %v", err)
|
||||
return fmt.Errorf("find code comments: %w", err)
|
||||
}
|
||||
for _, comment := range codeComments {
|
||||
if err := comment.CheckInvalidation(repo, doer, branch); err != nil {
|
||||
|
|
|
@ -355,7 +355,7 @@ func (list ReactionList) LoadUsers(ctx context.Context, repo *repo_model.Reposit
|
|||
In("id", userIDs).
|
||||
Find(&userMaps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find user: %v", err)
|
||||
return nil, fmt.Errorf("find user: %w", err)
|
||||
}
|
||||
|
||||
for _, reaction := range list {
|
||||
|
|
|
@ -790,10 +790,10 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_
|
|||
|
||||
official, err := IsOfficialReviewerTeam(ctx, issue, reviewer)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("isOfficialReviewerTeam(): %v", err)
|
||||
return nil, fmt.Errorf("isOfficialReviewerTeam(): %w", err)
|
||||
} else if !official {
|
||||
if official, err = IsOfficialReviewer(ctx, issue, doer); err != nil {
|
||||
return nil, fmt.Errorf("isOfficialReviewer(): %v", err)
|
||||
return nil, fmt.Errorf("isOfficialReviewer(): %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -823,7 +823,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_
|
|||
ReviewID: review.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("CreateCommentCtx(): %v", err)
|
||||
return nil, fmt.Errorf("CreateCommentCtx(): %w", err)
|
||||
}
|
||||
|
||||
return comment, committer.Commit()
|
||||
|
@ -852,7 +852,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *us
|
|||
|
||||
official, err := IsOfficialReviewerTeam(ctx, issue, reviewer)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("isOfficialReviewerTeam(): %v", err)
|
||||
return nil, fmt.Errorf("isOfficialReviewerTeam(): %w", err)
|
||||
}
|
||||
|
||||
if official {
|
||||
|
@ -882,7 +882,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *us
|
|||
AssigneeTeamID: reviewer.ID, // Use AssigneeTeamID as reviewer team ID
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("CreateCommentCtx(): %v", err)
|
||||
return nil, fmt.Errorf("CreateCommentCtx(): %w", err)
|
||||
}
|
||||
|
||||
return comment, committer.Commit()
|
||||
|
|
|
@ -428,13 +428,13 @@ var migrations = []Migration{
|
|||
// GetCurrentDBVersion returns the current db version
|
||||
func GetCurrentDBVersion(x *xorm.Engine) (int64, error) {
|
||||
if err := x.Sync(new(Version)); err != nil {
|
||||
return -1, fmt.Errorf("sync: %v", err)
|
||||
return -1, fmt.Errorf("sync: %w", err)
|
||||
}
|
||||
|
||||
currentVersion := &Version{ID: 1}
|
||||
has, err := x.Get(currentVersion)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("get: %v", err)
|
||||
return -1, fmt.Errorf("get: %w", err)
|
||||
}
|
||||
if !has {
|
||||
return -1, nil
|
||||
|
@ -476,13 +476,13 @@ func Migrate(x *xorm.Engine) error {
|
|||
// Set a new clean the default mapper to GonicMapper as that is the default for Gitea.
|
||||
x.SetMapper(names.GonicMapper{})
|
||||
if err := x.Sync(new(Version)); err != nil {
|
||||
return fmt.Errorf("sync: %v", err)
|
||||
return fmt.Errorf("sync: %w", err)
|
||||
}
|
||||
|
||||
currentVersion := &Version{ID: 1}
|
||||
has, err := x.Get(currentVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get: %v", err)
|
||||
return fmt.Errorf("get: %w", err)
|
||||
} else if !has {
|
||||
// If the version record does not exist we think
|
||||
// it is a fresh installation and we can skip all migrations.
|
||||
|
@ -490,7 +490,7 @@ func Migrate(x *xorm.Engine) error {
|
|||
currentVersion.Version = int64(minDBVersion + len(migrations))
|
||||
|
||||
if _, err = x.InsertOne(currentVersion); err != nil {
|
||||
return fmt.Errorf("insert: %v", err)
|
||||
return fmt.Errorf("insert: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,7 +519,7 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t
|
|||
// Reset the mapper between each migration - migrations are not supposed to depend on each other
|
||||
x.SetMapper(names.GonicMapper{})
|
||||
if err = m.Migrate(x); err != nil {
|
||||
return fmt.Errorf("migration[%d]: %s failed: %v", v+int64(i), m.Description(), err)
|
||||
return fmt.Errorf("migration[%d]: %s failed: %w", v+int64(i), m.Description(), err)
|
||||
}
|
||||
currentVersion.Version = v + int64(i) + 1
|
||||
if _, err = x.ID(1).Update(currentVersion); err != nil {
|
||||
|
@ -918,7 +918,7 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
|
|||
cols += "DROP COLUMN `" + col + "` CASCADE"
|
||||
}
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
|
||||
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
|
||||
return fmt.Errorf("Drop table `%s` columns %v: %w", tableName, columnNames, err)
|
||||
}
|
||||
case setting.Database.UseMySQL:
|
||||
// Drop indexes on columns first
|
||||
|
@ -946,7 +946,7 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
|
|||
cols += "DROP COLUMN `" + col + "`"
|
||||
}
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
|
||||
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
|
||||
return fmt.Errorf("Drop table `%s` columns %v: %w", tableName, columnNames, err)
|
||||
}
|
||||
case setting.Database.UseMSSQL:
|
||||
cols := ""
|
||||
|
@ -960,27 +960,27 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
|
|||
tableName, strings.ReplaceAll(cols, "`", "'"))
|
||||
constraints := make([]string, 0)
|
||||
if err := sess.SQL(sql).Find(&constraints); err != nil {
|
||||
return fmt.Errorf("Find constraints: %v", err)
|
||||
return fmt.Errorf("Find constraints: %w", err)
|
||||
}
|
||||
for _, constraint := range constraints {
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP CONSTRAINT `%s`", tableName, constraint)); err != nil {
|
||||
return fmt.Errorf("Drop table `%s` default constraint `%s`: %v", tableName, constraint, err)
|
||||
return fmt.Errorf("Drop table `%s` default constraint `%s`: %w", tableName, constraint, err)
|
||||
}
|
||||
}
|
||||
sql = fmt.Sprintf("SELECT DISTINCT Name FROM sys.indexes INNER JOIN sys.index_columns ON indexes.index_id = index_columns.index_id AND indexes.object_id = index_columns.object_id WHERE indexes.object_id = OBJECT_ID('%[1]s') AND index_columns.column_id IN (SELECT column_id FROM sys.columns WHERE LOWER(name) IN (%[2]s) AND object_id = OBJECT_ID('%[1]s'))",
|
||||
tableName, strings.ReplaceAll(cols, "`", "'"))
|
||||
constraints = make([]string, 0)
|
||||
if err := sess.SQL(sql).Find(&constraints); err != nil {
|
||||
return fmt.Errorf("Find constraints: %v", err)
|
||||
return fmt.Errorf("Find constraints: %w", err)
|
||||
}
|
||||
for _, constraint := range constraints {
|
||||
if _, err := sess.Exec(fmt.Sprintf("DROP INDEX `%[2]s` ON `%[1]s`", tableName, constraint)); err != nil {
|
||||
return fmt.Errorf("Drop index `%[2]s` on `%[1]s`: %v", tableName, constraint, err)
|
||||
return fmt.Errorf("Drop index `%s` on `%s`: %w", constraint, tableName, err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP COLUMN %s", tableName, cols)); err != nil {
|
||||
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
|
||||
return fmt.Errorf("Drop table `%s` columns %v: %w", tableName, columnNames, err)
|
||||
}
|
||||
default:
|
||||
log.Fatal("Unrecognized DB")
|
||||
|
|
|
@ -17,7 +17,7 @@ func featureChangeTargetBranch(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Comment)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -45,11 +45,11 @@ func renameExistingUserAvatarName(x *xorm.Engine) error {
|
|||
migrated := 0
|
||||
for {
|
||||
if err := sess.Begin(); err != nil {
|
||||
return fmt.Errorf("session.Begin: %v", err)
|
||||
return fmt.Errorf("session.Begin: %w", err)
|
||||
}
|
||||
users := make([]*User, 0, 50)
|
||||
if err := sess.Table("user").Asc("id").Limit(50, start).Find(&users); err != nil {
|
||||
return fmt.Errorf("select users from id [%d]: %v", start, err)
|
||||
return fmt.Errorf("select users from id [%d]: %w", start, err)
|
||||
}
|
||||
if len(users) == 0 {
|
||||
_ = sess.Rollback()
|
||||
|
@ -76,7 +76,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error {
|
|||
newAvatar, err := copyOldAvatarToNewLocation(user.ID, oldAvatar)
|
||||
if err != nil {
|
||||
_ = sess.Rollback()
|
||||
return fmt.Errorf("[user: %s] %v", user.LowerName, err)
|
||||
return fmt.Errorf("[user: %s] %w", user.LowerName, err)
|
||||
} else if newAvatar == oldAvatar {
|
||||
continue
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error {
|
|||
user.Avatar = newAvatar
|
||||
if _, err := sess.ID(user.ID).Cols("avatar").Update(user); err != nil {
|
||||
_ = sess.Rollback()
|
||||
return fmt.Errorf("[user: %s] user table update: %v", user.LowerName, err)
|
||||
return fmt.Errorf("[user: %s] user table update: %w", user.LowerName, err)
|
||||
}
|
||||
|
||||
deleteList.Add(filepath.Join(setting.Avatar.Path, oldAvatar))
|
||||
|
@ -104,7 +104,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error {
|
|||
}
|
||||
if err := sess.Commit(); err != nil {
|
||||
_ = sess.Rollback()
|
||||
return fmt.Errorf("commit session: %v", err)
|
||||
return fmt.Errorf("commit session: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,13 +138,13 @@ func renameExistingUserAvatarName(x *xorm.Engine) error {
|
|||
func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) {
|
||||
fr, err := os.Open(filepath.Join(setting.Avatar.Path, oldAvatar))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("os.Open: %v", err)
|
||||
return "", fmt.Errorf("os.Open: %w", err)
|
||||
}
|
||||
defer fr.Close()
|
||||
|
||||
data, err := io.ReadAll(fr)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("io.ReadAll: %v", err)
|
||||
return "", fmt.Errorf("io.ReadAll: %w", err)
|
||||
}
|
||||
|
||||
newAvatar := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", userID, md5.Sum(data)))))
|
||||
|
@ -153,7 +153,7 @@ func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error)
|
|||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(setting.Avatar.Path, newAvatar), data, 0o666); err != nil {
|
||||
return "", fmt.Errorf("os.WriteFile: %v", err)
|
||||
return "", fmt.Errorf("os.WriteFile: %w", err)
|
||||
}
|
||||
|
||||
return newAvatar, nil
|
||||
|
|
|
@ -17,7 +17,7 @@ func addReviewMigrateInfo(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Review)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ func addLanguageStats(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(LanguageStat)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
if err := x.Sync2(new(RepoIndexerStatus)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ func fixMergeBase(x *xorm.Engine) error {
|
|||
for {
|
||||
prs := make([]PullRequest, 0, 50)
|
||||
if err := x.Limit(limit, start).Asc("id").Find(&prs); err != nil {
|
||||
return fmt.Errorf("Find: %v", err)
|
||||
return fmt.Errorf("Find: %w", err)
|
||||
}
|
||||
if len(prs) == 0 {
|
||||
break
|
||||
|
@ -70,7 +70,7 @@ func fixMergeBase(x *xorm.Engine) error {
|
|||
baseRepo := &Repository{ID: pr.BaseRepoID}
|
||||
has, err := x.Table("repository").Get(baseRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to get base repo %d %v", pr.BaseRepoID, err)
|
||||
return fmt.Errorf("Unable to get base repo %d %w", pr.BaseRepoID, err)
|
||||
}
|
||||
if !has {
|
||||
log.Error("Missing base repo with id %d for PR ID %d", pr.BaseRepoID, pr.ID)
|
||||
|
|
|
@ -16,7 +16,7 @@ func addSystemWebhookColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Webhook)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func addBranchProtectionProtectedFilesColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(ProtectedBranch)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func refixMergeBase(x *xorm.Engine) error {
|
|||
for {
|
||||
prs := make([]PullRequest, 0, 50)
|
||||
if err := x.Limit(limit, start).Asc("id").Where("has_merged = ?", true).Find(&prs); err != nil {
|
||||
return fmt.Errorf("Find: %v", err)
|
||||
return fmt.Errorf("Find: %w", err)
|
||||
}
|
||||
if len(prs) == 0 {
|
||||
break
|
||||
|
@ -69,7 +69,7 @@ func refixMergeBase(x *xorm.Engine) error {
|
|||
baseRepo := &Repository{ID: pr.BaseRepoID}
|
||||
has, err := x.Table("repository").Get(baseRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to get base repo %d %v", pr.BaseRepoID, err)
|
||||
return fmt.Errorf("Unable to get base repo %d %w", pr.BaseRepoID, err)
|
||||
}
|
||||
if !has {
|
||||
log.Error("Missing base repo with id %d for PR ID %d", pr.BaseRepoID, pr.ID)
|
||||
|
|
|
@ -16,7 +16,7 @@ func addOrgIDLabelColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Label)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(PullRequest)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
last := 0
|
||||
|
@ -80,7 +80,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error {
|
|||
baseRepo := &Repository{ID: pr.BaseRepoID}
|
||||
has, err := x.Table("repository").Get(baseRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to get base repo %d %v", pr.BaseRepoID, err)
|
||||
return fmt.Errorf("Unable to get base repo %d %w", pr.BaseRepoID, err)
|
||||
}
|
||||
if !has {
|
||||
log.Error("Missing base repo with id %d for PR ID %d", pr.BaseRepoID, pr.ID)
|
||||
|
@ -101,7 +101,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error {
|
|||
pr.CommitsBehind = divergence.Behind
|
||||
|
||||
if _, err = sess.ID(pr.ID).Cols("commits_ahead", "commits_behind").Update(pr); err != nil {
|
||||
return fmt.Errorf("Update Cols: %v", err)
|
||||
return fmt.Errorf("Update Cols: %w", err)
|
||||
}
|
||||
migrated++
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func addResolveDoerIDCommentColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Comment)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func fixLanguageStatsToSaveSize(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(LanguageStat)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
x.Delete(&RepoIndexerStatus{IndexerType: RepoIndexerTypeStats})
|
||||
|
|
|
@ -16,7 +16,7 @@ func addKeepActivityPrivateUserColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(User)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -53,16 +53,16 @@ func increaseLanguageField(x *xorm.Engine) error {
|
|||
if err := sess.SQL(`SELECT i.name AS Name
|
||||
FROM sys.indexes i INNER JOIN sys.index_columns ic
|
||||
ON i.index_id = ic.index_id AND i.object_id = ic.object_id
|
||||
INNER JOIN sys.tables AS t
|
||||
INNER JOIN sys.tables AS t
|
||||
ON t.object_id = i.object_id
|
||||
INNER JOIN sys.columns c
|
||||
ON t.object_id = c.object_id AND ic.column_id = c.column_id
|
||||
WHERE t.name = 'language_stat' AND c.name = 'language'`).Find(&constraints); err != nil {
|
||||
return fmt.Errorf("Find constraints: %v", err)
|
||||
return fmt.Errorf("Find constraints: %w", err)
|
||||
}
|
||||
for _, constraint := range constraints {
|
||||
if _, err := sess.Exec(fmt.Sprintf("DROP INDEX [%s] ON `language_stat`", constraint)); err != nil {
|
||||
return fmt.Errorf("Drop table `language_stat` constraint `%s`: %v", constraint, err)
|
||||
return fmt.Errorf("Drop table `language_stat` constraint `%s`: %w", constraint, err)
|
||||
}
|
||||
}
|
||||
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE language_stat ALTER COLUMN language %s", sqlType)); err != nil {
|
||||
|
|
|
@ -19,7 +19,7 @@ func addCreatedAndUpdatedToMilestones(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Milestone)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func addChangedProtectedFilesPullRequestColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(PullRequest)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
|
|||
continue
|
||||
}
|
||||
log.Error("Error whilst getting commit for Tag: %s in [%d]%s/%s. Error: %v", release.TagName, repo.ID, repo.OwnerName, repo.Name, err)
|
||||
return fmt.Errorf("GetTagCommit: %v", err)
|
||||
return fmt.Errorf("GetTagCommit: %w", err)
|
||||
}
|
||||
|
||||
if commit.Author.Email == "" {
|
||||
|
@ -135,7 +135,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
|
|||
continue
|
||||
}
|
||||
log.Error("Error whilst getting commit for Tag: %s in [%d]%s/%s. Error: %v", release.TagName, repo.ID, repo.OwnerName, repo.Name, err)
|
||||
return fmt.Errorf("GetCommit: %v", err)
|
||||
return fmt.Errorf("GetCommit: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ func (grant *OAuth2Grant) TableName() string {
|
|||
|
||||
func addScopeAndNonceColumnsToOAuth2Grant(x *xorm.Engine) error {
|
||||
if err := x.Sync2(new(OAuth2Grant)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ func addUserRedirect(x *xorm.Engine) (err error) {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(UserRedirect)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func addDismissedReviewColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Review)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func addSortingColToProjectBoard(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(ProjectBoard)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func addTimeIDCommentColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Comment)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func addRepoTransfer(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := sess.Sync2(new(RepoTransfer)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
|
|
|
@ -25,7 +25,7 @@ func deleteOrphanedIssueLabels(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := sess.Sync2(new(IssueLabel)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
if _, err := sess.Exec(`DELETE FROM issue_label WHERE issue_label.id IN (
|
||||
|
|
|
@ -32,7 +32,7 @@ func createPushMirrorTable(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := sess.Sync2(new(PushMirror)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
|
|
|
@ -43,7 +43,7 @@ func renameTaskErrorsToMessage(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := sess.Sync2(new(Task)); err != nil {
|
||||
return fmt.Errorf("error on Sync2: %v", err)
|
||||
return fmt.Errorf("error on Sync2: %w", err)
|
||||
}
|
||||
|
||||
if messageExist {
|
||||
|
|
|
@ -18,7 +18,7 @@ func addAgitFlowPullRequest(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(PullRequest)); err != nil {
|
||||
return fmt.Errorf("sync2: %v", err)
|
||||
return fmt.Errorf("sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func addBranchProtectionUnprotectedFilesColumn(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(ProtectedBranch)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func addTableCommitStatusIndex(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(CommitStatusIndex)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
|
|
|
@ -16,7 +16,7 @@ func addColorColToProjectBoard(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(ProjectBoard)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ func addTableIssueContentHistory(x *xorm.Engine) error {
|
|||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Sync2(new(IssueContentHistory)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func addTableAppState(x *xorm.Engine) error {
|
|||
Content string `xorm:"LONGTEXT"`
|
||||
}
|
||||
if err := x.Sync2(new(AppState)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ func createUserSettingsTable(x *xorm.Engine) error {
|
|||
SettingValue string `xorm:"text"`
|
||||
}
|
||||
if err := x.Sync2(new(UserSetting)); err != nil {
|
||||
return fmt.Errorf("sync2: %v", err)
|
||||
return fmt.Errorf("sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func addAuthorizeColForTeamUnit(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(TeamUnit)); err != nil {
|
||||
return fmt.Errorf("sync2: %v", err)
|
||||
return fmt.Errorf("sync2: %w", err)
|
||||
}
|
||||
|
||||
// migrate old permission
|
||||
|
|
|
@ -144,7 +144,7 @@ func remigrateU2FCredentials(x *xorm.Engine) error {
|
|||
if !has {
|
||||
has, err := sess.Where("`lower_name`=?", remigrated.LowerName).And("`user_id`=?", remigrated.UserID).Exist(new(webauthnCredential))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to check webauthn_credential[lower_name: %s, user_id:%v]. Error: %w", remigrated.LowerName, remigrated.UserID, err)
|
||||
return fmt.Errorf("unable to check webauthn_credential[lower_name: %s, user_id: %d]. Error: %w", remigrated.LowerName, remigrated.UserID, err)
|
||||
}
|
||||
if !has {
|
||||
_, err = sess.Insert(remigrated)
|
||||
|
|
|
@ -20,7 +20,7 @@ func createForeignReferenceTable(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(ForeignReference)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func renameCredentialIDBytes(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := sess.Sync2(new(webauthnCredential)); err != nil {
|
||||
return fmt.Errorf("error on Sync2: %v", err)
|
||||
return fmt.Errorf("error on Sync2: %w", err)
|
||||
}
|
||||
|
||||
if credentialIDExist {
|
||||
|
|
|
@ -45,7 +45,7 @@ func insertSettingsIfNotExist(x *xorm.Engine, sysSettings []*SystemSetting) erro
|
|||
|
||||
func createSystemSettingsTable(x *xorm.Engine) error {
|
||||
if err := x.Sync2(new(SystemSetting)); err != nil {
|
||||
return fmt.Errorf("sync2: %v", err)
|
||||
return fmt.Errorf("sync2: %w", err)
|
||||
}
|
||||
|
||||
// migrate xx to database
|
||||
|
|
|
@ -38,7 +38,7 @@ func addIssueDependencies(x *xorm.Engine) (err error) {
|
|||
)
|
||||
|
||||
if err = x.Sync(new(IssueDependency)); err != nil {
|
||||
return fmt.Errorf("Error creating issue_dependency_table column definition: %v", err)
|
||||
return fmt.Errorf("Error creating issue_dependency_table column definition: %w", err)
|
||||
}
|
||||
|
||||
// Update Comment definition
|
||||
|
@ -76,7 +76,7 @@ func addIssueDependencies(x *xorm.Engine) (err error) {
|
|||
}
|
||||
|
||||
if err = x.Sync(new(Comment)); err != nil {
|
||||
return fmt.Errorf("Error updating issue_comment table column definition: %v", err)
|
||||
return fmt.Errorf("Error updating issue_comment table column definition: %w", err)
|
||||
}
|
||||
|
||||
// RepoUnit describes all units of a repository
|
||||
|
@ -93,7 +93,7 @@ func addIssueDependencies(x *xorm.Engine) (err error) {
|
|||
units := make([]*RepoUnit, 0, 100)
|
||||
err = x.Where("`type` = ?", v16UnitTypeIssues).Find(&units)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Query repo units: %v", err)
|
||||
return fmt.Errorf("Query repo units: %w", err)
|
||||
}
|
||||
for _, unit := range units {
|
||||
if unit.Config == nil {
|
||||
|
|
|
@ -30,7 +30,7 @@ func addScratchHash(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(TwoFactor)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
|
@ -61,7 +61,7 @@ func addScratchHash(x *xorm.Engine) error {
|
|||
tfa.ScratchHash = hashToken(tfa.ScratchToken, salt)
|
||||
|
||||
if _, err := sess.ID(tfa.ID).Cols("scratch_salt, scratch_hash").Update(tfa); err != nil {
|
||||
return fmt.Errorf("couldn't add in scratch_hash and scratch_salt: %v", err)
|
||||
return fmt.Errorf("couldn't add in scratch_hash and scratch_salt: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func addReview(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := x.Sync2(new(Review)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func addPullRequestRebaseWithMerge(x *xorm.Engine) error {
|
|||
// Updating existing issue units
|
||||
units := make([]*RepoUnit, 0, 100)
|
||||
if err := sess.Where("`type` = ?", v16UnitTypePRs).Find(&units); err != nil {
|
||||
return fmt.Errorf("Query repo units: %v", err)
|
||||
return fmt.Errorf("Query repo units: %w", err)
|
||||
}
|
||||
for _, unit := range units {
|
||||
if unit.Config == nil {
|
||||
|
|
|
@ -24,7 +24,7 @@ func changeU2FCounterType(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error changing u2f_registration counter column type: %v", err)
|
||||
return fmt.Errorf("Error changing u2f_registration counter column type: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -41,7 +41,7 @@ func hashAppToken(x *xorm.Engine) error {
|
|||
}
|
||||
|
||||
if err := sess.Sync2(new(AccessToken)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
|
||||
if err := sess.Commit(); err != nil {
|
||||
|
@ -79,7 +79,7 @@ func hashAppToken(x *xorm.Engine) error {
|
|||
token.Sha1 = "" // ensure to blank out column in case drop column doesn't work
|
||||
|
||||
if _, err := sess.ID(token.ID).Cols("token_hash, token_salt, token_last_eight, sha1").Update(token); err != nil {
|
||||
return fmt.Errorf("couldn't add in sha1, token_hash, token_salt and token_last_eight: %v", err)
|
||||
return fmt.Errorf("couldn't add in sha1, token_hash, token_salt and token_last_eight: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func resyncHashAppTokenWithUniqueHash(x *xorm.Engine) error {
|
|||
return err
|
||||
}
|
||||
if err := sess.Sync2(new(AccessToken)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
return fmt.Errorf("Sync2: %w", err)
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
|
|
@ -25,14 +25,14 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error {
|
|||
And("org_id=?", orgID).
|
||||
Get(ou)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get org-user: %v", err)
|
||||
return fmt.Errorf("get org-user: %w", err)
|
||||
} else if !has {
|
||||
return nil
|
||||
}
|
||||
|
||||
org, err := organization.GetOrgByID(ctx, orgID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetUserByID [%d]: %v", orgID, err)
|
||||
return fmt.Errorf("GetUserByID [%d]: %w", orgID, err)
|
||||
}
|
||||
|
||||
// Check if the user to delete is the last member in owner team.
|
||||
|
@ -62,11 +62,11 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error {
|
|||
// Delete all repository accesses and unwatch them.
|
||||
env, err := organization.AccessibleReposEnv(ctx, org, userID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("AccessibleReposEnv: %v", err)
|
||||
return fmt.Errorf("AccessibleReposEnv: %w", err)
|
||||
}
|
||||
repoIDs, err := env.RepoIDs(1, org.NumRepos)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetUserRepositories [%d]: %v", userID, err)
|
||||
return fmt.Errorf("GetUserRepositories [%d]: %w", userID, err)
|
||||
}
|
||||
for _, repoID := range repoIDs {
|
||||
if err = repo_model.WatchRepo(ctx, userID, repoID, false); err != nil {
|
||||
|
|
|
@ -31,23 +31,23 @@ func AddRepository(ctx context.Context, t *organization.Team, repo *repo_model.R
|
|||
}
|
||||
|
||||
if err = organization.IncrTeamRepoNum(ctx, t.ID); err != nil {
|
||||
return fmt.Errorf("update team: %v", err)
|
||||
return fmt.Errorf("update team: %w", err)
|
||||
}
|
||||
|
||||
t.NumRepos++
|
||||
|
||||
if err = access_model.RecalculateTeamAccesses(ctx, repo, 0); err != nil {
|
||||
return fmt.Errorf("recalculateAccesses: %v", err)
|
||||
return fmt.Errorf("recalculateAccesses: %w", err)
|
||||
}
|
||||
|
||||
// Make all team members watch this repo if enabled in global settings
|
||||
if setting.Service.AutoWatchNewRepos {
|
||||
if err = t.GetMembersCtx(ctx); err != nil {
|
||||
return fmt.Errorf("getMembers: %v", err)
|
||||
return fmt.Errorf("getMembers: %w", err)
|
||||
}
|
||||
for _, u := range t.Members {
|
||||
if err = repo_model.WatchRepo(ctx, u.ID, repo.ID, true); err != nil {
|
||||
return fmt.Errorf("watchRepo: %v", err)
|
||||
return fmt.Errorf("watchRepo: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,13 +60,13 @@ func AddRepository(ctx context.Context, t *organization.Team, repo *repo_model.R
|
|||
func addAllRepositories(ctx context.Context, t *organization.Team) error {
|
||||
orgRepos, err := organization.GetOrgRepositories(ctx, t.OrgID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get org repos: %v", err)
|
||||
return fmt.Errorf("get org repos: %w", err)
|
||||
}
|
||||
|
||||
for _, repo := range orgRepos {
|
||||
if !organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) {
|
||||
if err := AddRepository(ctx, t, repo); err != nil {
|
||||
return fmt.Errorf("AddRepository: %v", err)
|
||||
return fmt.Errorf("AddRepository: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ func removeRepository(ctx context.Context, t *organization.Team, repo *repo_mode
|
|||
|
||||
teamUsers, err := organization.GetTeamUsersByTeamID(ctx, t.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getTeamUsersByTeamID: %v", err)
|
||||
return fmt.Errorf("getTeamUsersByTeamID: %w", err)
|
||||
}
|
||||
for _, teamUser := range teamUsers {
|
||||
has, err := access_model.HasAccess(ctx, teamUser.UID, repo)
|
||||
|
@ -287,7 +287,7 @@ func NewTeam(t *organization.Team) (err error) {
|
|||
if t.IncludesAllRepositories {
|
||||
err = addAllRepositories(ctx, t)
|
||||
if err != nil {
|
||||
return fmt.Errorf("addAllRepositories: %v", err)
|
||||
return fmt.Errorf("addAllRepositories: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err
|
|||
|
||||
if _, err = sess.ID(t.ID).Cols("name", "lower_name", "description",
|
||||
"can_create_org_repo", "authorize", "includes_all_repositories").Update(t); err != nil {
|
||||
return fmt.Errorf("update: %v", err)
|
||||
return fmt.Errorf("update: %w", err)
|
||||
}
|
||||
|
||||
// update units for team
|
||||
|
@ -351,12 +351,12 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err
|
|||
// Update access for team members if needed.
|
||||
if authChanged {
|
||||
if err = t.GetRepositoriesCtx(ctx); err != nil {
|
||||
return fmt.Errorf("getRepositories: %v", err)
|
||||
return fmt.Errorf("getRepositories: %w", err)
|
||||
}
|
||||
|
||||
for _, repo := range t.Repos {
|
||||
if err = access_model.RecalculateTeamAccesses(ctx, repo, 0); err != nil {
|
||||
return fmt.Errorf("recalculateTeamAccesses: %v", err)
|
||||
return fmt.Errorf("recalculateTeamAccesses: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err
|
|||
if includeAllChanged && t.IncludesAllRepositories {
|
||||
err = addAllRepositories(ctx, t)
|
||||
if err != nil {
|
||||
return fmt.Errorf("addAllRepositories: %v", err)
|
||||
return fmt.Errorf("addAllRepositories: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ func DeleteTeam(t *organization.Team) error {
|
|||
builder.Select("id").From("repository").Where(builder.Eq{"owner_id": t.OrgID})).
|
||||
Find(&protections)
|
||||
if err != nil {
|
||||
return fmt.Errorf("findProtectedBranches: %v", err)
|
||||
return fmt.Errorf("findProtectedBranches: %w", err)
|
||||
}
|
||||
for _, p := range protections {
|
||||
var matched1, matched2, matched3 bool
|
||||
|
@ -419,7 +419,7 @@ func DeleteTeam(t *organization.Team) error {
|
|||
"merge_whitelist_team_i_ds",
|
||||
"approvals_whitelist_team_i_ds",
|
||||
).Update(p); err != nil {
|
||||
return fmt.Errorf("updateProtectedBranches: %v", err)
|
||||
return fmt.Errorf("updateProtectedBranches: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -496,14 +496,14 @@ func AddTeamMember(team *organization.Team, userID int64) error {
|
|||
And("mode < ?", team.AccessMode).
|
||||
SetExpr("mode", team.AccessMode).
|
||||
Update(new(access_model.Access)); err != nil {
|
||||
return fmt.Errorf("update user accesses: %v", err)
|
||||
return fmt.Errorf("update user accesses: %w", err)
|
||||
}
|
||||
|
||||
// for not exist access
|
||||
var repoIDs []int64
|
||||
accessSubQuery := builder.Select("repo_id").From("access").Where(builder.Eq{"user_id": userID})
|
||||
if err := sess.SQL(subQuery.And(builder.NotIn("repo_id", accessSubQuery))).Find(&repoIDs); err != nil {
|
||||
return fmt.Errorf("select id accesses: %v", err)
|
||||
return fmt.Errorf("select id accesses: %w", err)
|
||||
}
|
||||
|
||||
accesses := make([]*access_model.Access, 0, 100)
|
||||
|
@ -511,7 +511,7 @@ func AddTeamMember(team *organization.Team, userID int64) error {
|
|||
accesses = append(accesses, &access_model.Access{RepoID: repoID, UserID: userID, Mode: team.AccessMode})
|
||||
if (i%100 == 0 || i == len(repoIDs)-1) && len(accesses) > 0 {
|
||||
if err = db.Insert(ctx, accesses); err != nil {
|
||||
return fmt.Errorf("insert new user accesses: %v", err)
|
||||
return fmt.Errorf("insert new user accesses: %w", err)
|
||||
}
|
||||
accesses = accesses[:0]
|
||||
}
|
||||
|
|
|
@ -288,10 +288,10 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
|
|||
}
|
||||
|
||||
if err = db.Insert(ctx, org); err != nil {
|
||||
return fmt.Errorf("insert organization: %v", err)
|
||||
return fmt.Errorf("insert organization: %w", err)
|
||||
}
|
||||
if err = user_model.GenerateRandomAvatar(ctx, org.AsUser()); err != nil {
|
||||
return fmt.Errorf("generate random avatar: %v", err)
|
||||
return fmt.Errorf("generate random avatar: %w", err)
|
||||
}
|
||||
|
||||
// Add initial creator to organization and owner team.
|
||||
|
@ -299,7 +299,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
|
|||
UID: owner.ID,
|
||||
OrgID: org.ID,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("insert org-user relation: %v", err)
|
||||
return fmt.Errorf("insert org-user relation: %w", err)
|
||||
}
|
||||
|
||||
// Create default owner team.
|
||||
|
@ -313,7 +313,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
|
|||
CanCreateOrgRepo: true,
|
||||
}
|
||||
if err = db.Insert(ctx, t); err != nil {
|
||||
return fmt.Errorf("insert owner team: %v", err)
|
||||
return fmt.Errorf("insert owner team: %w", err)
|
||||
}
|
||||
|
||||
// insert units for team
|
||||
|
@ -335,7 +335,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
|
|||
OrgID: org.ID,
|
||||
TeamID: t.ID,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("insert team-user relation: %v", err)
|
||||
return fmt.Errorf("insert team-user relation: %w", err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
@ -372,11 +372,11 @@ func DeleteOrganization(ctx context.Context, org *Organization) error {
|
|||
&TeamUnit{OrgID: org.ID},
|
||||
&TeamInvite{OrgID: org.ID},
|
||||
); err != nil {
|
||||
return fmt.Errorf("DeleteBeans: %v", err)
|
||||
return fmt.Errorf("DeleteBeans: %w", err)
|
||||
}
|
||||
|
||||
if _, err := db.GetEngine(ctx).ID(org.ID).Delete(new(user_model.User)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
return fmt.Errorf("Delete: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -760,7 +760,7 @@ func (env *accessibleReposEnv) CountRepos() (int64, error) {
|
|||
Distinct("`repository`.id").
|
||||
Count(&repo_model.Repository{})
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("count user repositories in organization: %v", err)
|
||||
return 0, fmt.Errorf("count user repositories in organization: %w", err)
|
||||
}
|
||||
return repoCount, nil
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) {
|
|||
func (env *accessibleReposEnv) Repos(page, pageSize int) ([]*repo_model.Repository, error) {
|
||||
repoIDs, err := env.RepoIDs(page, pageSize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetUserRepositoryIDs: %v", err)
|
||||
return nil, fmt.Errorf("GetUserRepositoryIDs: %w", err)
|
||||
}
|
||||
|
||||
repos := make([]*repo_model.Repository, 0, len(repoIDs))
|
||||
|
@ -814,7 +814,7 @@ func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) {
|
|||
func (env *accessibleReposEnv) MirrorRepos() ([]*repo_model.Repository, error) {
|
||||
repoIDs, err := env.MirrorRepoIDs()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("MirrorRepoIDs: %v", err)
|
||||
return nil, fmt.Errorf("MirrorRepoIDs: %w", err)
|
||||
}
|
||||
|
||||
repos := make([]*repo_model.Repository, 0, len(repoIDs))
|
||||
|
|
|
@ -118,7 +118,7 @@ func loadOrganizationOwners(ctx context.Context, users user_model.UserList, orgI
|
|||
And("team_id=?", ownerTeam.ID).
|
||||
Find(&ownerMaps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find team users: %v", err)
|
||||
return nil, fmt.Errorf("find team users: %w", err)
|
||||
}
|
||||
return ownerMaps, nil
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ func updateUserAccess(accessMap map[int64]*userAccess, user *user_model.User, mo
|
|||
func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap map[int64]*userAccess) (err error) {
|
||||
minMode := perm.AccessModeRead
|
||||
if err := repo.GetOwner(ctx); err != nil {
|
||||
return fmt.Errorf("GetOwner: %v", err)
|
||||
return fmt.Errorf("GetOwner: %w", err)
|
||||
}
|
||||
|
||||
// If the repo isn't private and isn't owned by a organization,
|
||||
|
@ -111,14 +111,14 @@ func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap
|
|||
|
||||
// Delete old accesses and insert new ones for repository.
|
||||
if _, err = db.DeleteByBean(ctx, &Access{RepoID: repo.ID}); err != nil {
|
||||
return fmt.Errorf("delete old accesses: %v", err)
|
||||
return fmt.Errorf("delete old accesses: %w", err)
|
||||
}
|
||||
if len(newAccesses) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = db.Insert(ctx, newAccesses); err != nil {
|
||||
return fmt.Errorf("insert new accesses: %v", err)
|
||||
return fmt.Errorf("insert new accesses: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap
|
|||
func refreshCollaboratorAccesses(ctx context.Context, repoID int64, accessMap map[int64]*userAccess) error {
|
||||
collaborators, err := repo_model.GetCollaborators(ctx, repoID, db.ListOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("getCollaborations: %v", err)
|
||||
return fmt.Errorf("getCollaborations: %w", err)
|
||||
}
|
||||
for _, c := range collaborators {
|
||||
if c.User.IsGhost() {
|
||||
|
@ -151,7 +151,7 @@ func RecalculateTeamAccesses(ctx context.Context, repo *repo_model.Repository, i
|
|||
}
|
||||
|
||||
if err = refreshCollaboratorAccesses(ctx, repo.ID, accessMap); err != nil {
|
||||
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
|
||||
return fmt.Errorf("refreshCollaboratorAccesses: %w", err)
|
||||
}
|
||||
|
||||
teams, err := organization.FindOrgTeams(ctx, repo.Owner.ID)
|
||||
|
@ -173,7 +173,7 @@ func RecalculateTeamAccesses(ctx context.Context, repo *repo_model.Repository, i
|
|||
}
|
||||
|
||||
if err = t.GetMembersCtx(ctx); err != nil {
|
||||
return fmt.Errorf("getMembers '%d': %v", t.ID, err)
|
||||
return fmt.Errorf("getMembers '%d': %w", t.ID, err)
|
||||
}
|
||||
for _, m := range t.Members {
|
||||
updateUserAccess(accessMap, m, t.AccessMode)
|
||||
|
@ -224,10 +224,10 @@ func RecalculateUserAccess(ctx context.Context, repo *repo_model.Repository, uid
|
|||
|
||||
// Delete old user accesses and insert new one for repository.
|
||||
if _, err = e.Delete(&Access{RepoID: repo.ID, UserID: uid}); err != nil {
|
||||
return fmt.Errorf("delete old user accesses: %v", err)
|
||||
return fmt.Errorf("delete old user accesses: %w", err)
|
||||
} else if accessMode >= minMode {
|
||||
if err = db.Insert(ctx, &Access{RepoID: repo.ID, UserID: uid, Mode: accessMode}); err != nil {
|
||||
return fmt.Errorf("insert new user accesses: %v", err)
|
||||
return fmt.Errorf("insert new user accesses: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -241,7 +241,7 @@ func RecalculateAccesses(ctx context.Context, repo *repo_model.Repository) error
|
|||
|
||||
accessMap := make(map[int64]*userAccess, 20)
|
||||
if err := refreshCollaboratorAccesses(ctx, repo.ID, accessMap); err != nil {
|
||||
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
|
||||
return fmt.Errorf("refreshCollaboratorAccesses: %w", err)
|
||||
}
|
||||
return refreshAccesses(ctx, repo, accessMap)
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ func GetProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, er
|
|||
|
||||
count, err := e.Where(cond).Count(new(Project))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
return nil, 0, fmt.Errorf("Count: %w", err)
|
||||
}
|
||||
|
||||
e = e.Where(cond)
|
||||
|
|
|
@ -74,12 +74,12 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
|||
// Delete Deploy Keys
|
||||
deployKeys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: repoID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("listDeployKeys: %v", err)
|
||||
return fmt.Errorf("listDeployKeys: %w", err)
|
||||
}
|
||||
needRewriteKeysFile := len(deployKeys) > 0
|
||||
for _, dKey := range deployKeys {
|
||||
if err := DeleteDeployKey(ctx, doer, dKey.ID); err != nil {
|
||||
return fmt.Errorf("deleteDeployKeys: %v", err)
|
||||
return fmt.Errorf("deleteDeployKeys: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
|||
&repo_model.Watch{RepoID: repoID},
|
||||
&webhook.Webhook{RepoID: repoID},
|
||||
); err != nil {
|
||||
return fmt.Errorf("deleteBeans: %v", err)
|
||||
return fmt.Errorf("deleteBeans: %w", err)
|
||||
}
|
||||
|
||||
// Delete Labels and related objects
|
||||
|
@ -178,7 +178,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
|||
|
||||
if repo.IsFork {
|
||||
if _, err := db.Exec(ctx, "UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
|
||||
return fmt.Errorf("decrease fork count: %v", err)
|
||||
return fmt.Errorf("decrease fork count: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
|||
}
|
||||
|
||||
if err := project_model.DeleteProjectByRepoIDCtx(ctx, repoID); err != nil {
|
||||
return fmt.Errorf("unable to delete projects for repo[%d]: %v", repoID, err)
|
||||
return fmt.Errorf("unable to delete projects for repo[%d]: %w", repoID, err)
|
||||
}
|
||||
|
||||
// Remove LFS objects
|
||||
|
@ -310,7 +310,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
|||
|
||||
if len(repo.Avatar) > 0 {
|
||||
if err := storage.RepoAvatars.Delete(repo.CustomAvatarRelativePath()); err != nil {
|
||||
return fmt.Errorf("Failed to remove %s: %v", repo.Avatar, err)
|
||||
return fmt.Errorf("Failed to remove %s: %w", repo.Avatar, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -619,18 +619,18 @@ func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error
|
|||
if asymkey_model.IsErrDeployKeyNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("GetDeployKeyByID: %v", err)
|
||||
return fmt.Errorf("GetDeployKeyByID: %w", err)
|
||||
}
|
||||
|
||||
// Check if user has access to delete this key.
|
||||
if !doer.IsAdmin {
|
||||
repo, err := repo_model.GetRepositoryByIDCtx(ctx, key.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByID: %v", err)
|
||||
return fmt.Errorf("GetRepositoryByID: %w", err)
|
||||
}
|
||||
has, err := access_model.IsUserRepoAdmin(ctx, repo, doer)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetUserRepoPermission: %v", err)
|
||||
return fmt.Errorf("GetUserRepoPermission: %w", err)
|
||||
} else if !has {
|
||||
return asymkey_model.ErrKeyAccessDenied{
|
||||
UserID: doer.ID,
|
||||
|
@ -643,7 +643,7 @@ func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error
|
|||
if _, err := db.DeleteByBean(ctx, &asymkey_model.DeployKey{
|
||||
ID: key.ID,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("delete deploy key [%d]: %v", key.ID, err)
|
||||
return fmt.Errorf("delete deploy key [%d]: %w", key.ID, err)
|
||||
}
|
||||
|
||||
// Check if this is the last reference to same key content.
|
||||
|
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
func (a *Attachment) IncreaseDownloadCount() error {
|
||||
// Update download count.
|
||||
if _, err := db.GetEngine(db.DefaultContext).Exec("UPDATE `attachment` SET download_count=download_count+1 WHERE id=?", a.ID); err != nil {
|
||||
return fmt.Errorf("increase attachment count: %v", err)
|
||||
return fmt.Errorf("increase attachment count: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -36,7 +36,7 @@ func generateRandomAvatar(ctx context.Context, repo *Repository) error {
|
|||
seed := idToString
|
||||
img, err := avatar.RandomImage([]byte(seed))
|
||||
if err != nil {
|
||||
return fmt.Errorf("RandomImage: %v", err)
|
||||
return fmt.Errorf("RandomImage: %w", err)
|
||||
}
|
||||
|
||||
repo.Avatar = idToString
|
||||
|
@ -47,7 +47,7 @@ func generateRandomAvatar(ctx context.Context, repo *Repository) error {
|
|||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Failed to create dir %s: %v", repo.CustomAvatarRelativePath(), err)
|
||||
return fmt.Errorf("Failed to create dir %s: %w", repo.CustomAvatarRelativePath(), err)
|
||||
}
|
||||
|
||||
log.Info("New random avatar created for repository: %d", repo.ID)
|
||||
|
|
|
@ -40,7 +40,7 @@ type Collaborator struct {
|
|||
func GetCollaborators(ctx context.Context, repoID int64, listOptions db.ListOptions) ([]*Collaborator, error) {
|
||||
collaborations, err := getCollaborations(ctx, repoID, listOptions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getCollaborations: %v", err)
|
||||
return nil, fmt.Errorf("getCollaborations: %w", err)
|
||||
}
|
||||
|
||||
collaborators := make([]*Collaborator, 0, len(collaborations))
|
||||
|
@ -114,7 +114,7 @@ func ChangeCollaborationAccessModeCtx(ctx context.Context, repo *Repository, uid
|
|||
}
|
||||
has, err := e.Get(collaboration)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get collaboration: %v", err)
|
||||
return fmt.Errorf("get collaboration: %w", err)
|
||||
} else if !has {
|
||||
return nil
|
||||
}
|
||||
|
@ -128,9 +128,9 @@ func ChangeCollaborationAccessModeCtx(ctx context.Context, repo *Repository, uid
|
|||
ID(collaboration.ID).
|
||||
Cols("mode").
|
||||
Update(collaboration); err != nil {
|
||||
return fmt.Errorf("update collaboration: %v", err)
|
||||
return fmt.Errorf("update collaboration: %w", err)
|
||||
} else if _, err = e.Exec("UPDATE access SET mode = ? WHERE user_id = ? AND repo_id = ?", mode, uid, repo.ID); err != nil {
|
||||
return fmt.Errorf("update access table: %v", err)
|
||||
return fmt.Errorf("update access table: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -156,7 +156,7 @@ func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs
|
|||
// Check attachments
|
||||
attachments, err := GetAttachmentsByUUIDs(ctx, attachmentUUIDs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", attachmentUUIDs, err)
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %w", attachmentUUIDs, err)
|
||||
}
|
||||
|
||||
for i := range attachments {
|
||||
|
@ -166,7 +166,7 @@ func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs
|
|||
attachments[i].ReleaseID = releaseID
|
||||
// No assign value could be 0, so ignore AllCols().
|
||||
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
|
||||
return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ func PushUpdateDeleteTagsContext(ctx context.Context, repo *Repository, tags []s
|
|||
Where("repo_id = ? AND is_tag = ?", repo.ID, true).
|
||||
In("lower_tag_name", lowerTags).
|
||||
Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
return fmt.Errorf("Delete: %w", err)
|
||||
}
|
||||
|
||||
if _, err := db.GetEngine(ctx).
|
||||
|
@ -423,7 +423,7 @@ func PushUpdateDeleteTagsContext(ctx context.Context, repo *Repository, tags []s
|
|||
Update(&Release{
|
||||
IsDraft: true,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -436,18 +436,18 @@ func PushUpdateDeleteTag(repo *Repository, tagName string) error {
|
|||
if IsErrReleaseNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("GetRelease: %v", err)
|
||||
return fmt.Errorf("GetRelease: %w", err)
|
||||
}
|
||||
if rel.IsTag {
|
||||
if _, err = db.GetEngine(db.DefaultContext).ID(rel.ID).Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
return fmt.Errorf("Delete: %w", err)
|
||||
}
|
||||
} else {
|
||||
rel.IsDraft = true
|
||||
rel.NumCommits = 0
|
||||
rel.Sha1 = ""
|
||||
if _, err = db.GetEngine(db.DefaultContext).ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,13 +458,13 @@ func PushUpdateDeleteTag(repo *Repository, tagName string) error {
|
|||
func SaveOrUpdateTag(repo *Repository, newRel *Release) error {
|
||||
rel, err := GetRelease(repo.ID, newRel.TagName)
|
||||
if err != nil && !IsErrReleaseNotExist(err) {
|
||||
return fmt.Errorf("GetRelease: %v", err)
|
||||
return fmt.Errorf("GetRelease: %w", err)
|
||||
}
|
||||
|
||||
if rel == nil {
|
||||
rel = newRel
|
||||
if _, err = db.GetEngine(db.DefaultContext).Insert(rel); err != nil {
|
||||
return fmt.Errorf("InsertOne: %v", err)
|
||||
return fmt.Errorf("InsertOne: %w", err)
|
||||
}
|
||||
} else {
|
||||
rel.Sha1 = newRel.Sha1
|
||||
|
@ -475,7 +475,7 @@ func SaveOrUpdateTag(repo *Repository, newRel *Release) error {
|
|||
rel.PublisherID = newRel.PublisherID
|
||||
}
|
||||
if _, err = db.GetEngine(db.DefaultContext).ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -760,7 +760,7 @@ func CountRepositories(ctx context.Context, opts CountRepositoryOptions) (int64,
|
|||
|
||||
count, err := sess.Count(new(Repository))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("countRepositories: %v", err)
|
||||
return 0, fmt.Errorf("countRepositories: %w", err)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
|
|
@ -95,13 +95,13 @@ func GetIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoInd
|
|||
func UpdateIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoIndexerType, sha string) error {
|
||||
status, err := GetIndexerStatus(ctx, repo, indexerType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to getIndexerStatus for repo: %s Error: %v", repo.FullName(), err)
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to getIndexerStatus for repo: %s Error: %w", repo.FullName(), err)
|
||||
}
|
||||
|
||||
if len(status.CommitSha) == 0 {
|
||||
status.CommitSha = sha
|
||||
if err := db.Insert(ctx, status); err != nil {
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to insert repoIndexerStatus for repo: %s Sha: %s Error: %v", repo.FullName(), sha, err)
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to insert repoIndexerStatus for repo: %s Sha: %s Error: %w", repo.FullName(), sha, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ func UpdateIndexerStatus(ctx context.Context, repo *Repository, indexerType Repo
|
|||
_, err = db.GetEngine(ctx).ID(status.ID).Cols("commit_sha").
|
||||
Update(status)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to update repoIndexerStatus for repo: %s Sha: %s Error: %v", repo.FullName(), sha, err)
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to update repoIndexerStatus for repo: %s Sha: %s Error: %w", repo.FullName(), sha, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func (repos RepositoryList) loadAttributes(ctx context.Context) error {
|
|||
Where("id > 0").
|
||||
In("id", set.Values()).
|
||||
Find(&users); err != nil {
|
||||
return fmt.Errorf("find users: %v", err)
|
||||
return fmt.Errorf("find users: %w", err)
|
||||
}
|
||||
for i := range repos {
|
||||
repos[i].Owner = users[repos[i].OwnerID]
|
||||
|
@ -93,7 +93,7 @@ func (repos RepositoryList) loadAttributes(ctx context.Context) error {
|
|||
Where("`is_primary` = ? AND `language` != ?", true, "other").
|
||||
In("`repo_id`", repoIDs).
|
||||
Find(&stats); err != nil {
|
||||
return fmt.Errorf("find primary languages: %v", err)
|
||||
return fmt.Errorf("find primary languages: %w", err)
|
||||
}
|
||||
stats.LoadAttributes()
|
||||
for i := range repos {
|
||||
|
@ -537,7 +537,7 @@ func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond, loa
|
|||
}
|
||||
repos := make(RepositoryList, 0, defaultSize)
|
||||
if err := sess.Find(&repos); err != nil {
|
||||
return nil, 0, fmt.Errorf("Repo: %v", err)
|
||||
return nil, 0, fmt.Errorf("Repo: %w", err)
|
||||
}
|
||||
|
||||
if opts.PageSize <= 0 {
|
||||
|
@ -546,7 +546,7 @@ func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond, loa
|
|||
|
||||
if loadAttributes {
|
||||
if err := repos.loadAttributes(ctx); err != nil {
|
||||
return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
|
||||
return nil, 0, fmt.Errorf("LoadAttributes: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -582,7 +582,7 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
|
|||
Where(cond).
|
||||
Count(new(Repository))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
return nil, 0, fmt.Errorf("Count: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -725,7 +725,7 @@ func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error)
|
|||
|
||||
count, err := sess.Where(cond).Count(new(Repository))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
return nil, 0, fmt.Errorf("Count: %w", err)
|
||||
}
|
||||
|
||||
sess = sess.Where(cond).OrderBy(opts.OrderBy.String())
|
||||
|
|
|
@ -119,7 +119,7 @@ func CheckCreateRepository(doer, u *user_model.User, name string, overwriteOrAdo
|
|||
|
||||
has, err := IsRepositoryExist(db.DefaultContext, u, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("IsRepositoryExist: %v", err)
|
||||
return fmt.Errorf("IsRepositoryExist: %w", err)
|
||||
} else if has {
|
||||
return ErrRepoAlreadyExist{u.Name, name}
|
||||
}
|
||||
|
@ -150,14 +150,14 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
|
|||
|
||||
has, err := IsRepositoryExist(db.DefaultContext, repo.Owner, newRepoName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("IsRepositoryExist: %v", err)
|
||||
return fmt.Errorf("IsRepositoryExist: %w", err)
|
||||
} else if has {
|
||||
return ErrRepoAlreadyExist{repo.Owner.Name, newRepoName}
|
||||
}
|
||||
|
||||
newRepoPath := RepoPath(repo.Owner.Name, newRepoName)
|
||||
if err = util.Rename(repo.RepoPath(), newRepoPath); err != nil {
|
||||
return fmt.Errorf("rename repository directory: %v", err)
|
||||
return fmt.Errorf("rename repository directory: %w", err)
|
||||
}
|
||||
|
||||
wikiPath := repo.WikiPath()
|
||||
|
@ -168,7 +168,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
|
|||
}
|
||||
if isExist {
|
||||
if err = util.Rename(wikiPath, WikiPath(repo.Owner.Name, newRepoName)); err != nil {
|
||||
return fmt.Errorf("rename repository wiki: %v", err)
|
||||
return fmt.Errorf("rename repository wiki: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,19 +70,19 @@ func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err err
|
|||
|
||||
localPath := upload.LocalPath()
|
||||
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
|
||||
return nil, fmt.Errorf("MkdirAll: %v", err)
|
||||
return nil, fmt.Errorf("MkdirAll: %w", err)
|
||||
}
|
||||
|
||||
fw, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Create: %v", err)
|
||||
return nil, fmt.Errorf("Create: %w", err)
|
||||
}
|
||||
defer fw.Close()
|
||||
|
||||
if _, err = fw.Write(buf); err != nil {
|
||||
return nil, fmt.Errorf("Write: %v", err)
|
||||
return nil, fmt.Errorf("Write: %w", err)
|
||||
} else if _, err = io.Copy(fw, file); err != nil {
|
||||
return nil, fmt.Errorf("Copy: %v", err)
|
||||
return nil, fmt.Errorf("Copy: %w", err)
|
||||
}
|
||||
|
||||
if _, err := db.GetEngine(db.DefaultContext).Insert(upload); err != nil {
|
||||
|
@ -134,7 +134,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
|
|||
if _, err = db.GetEngine(ctx).
|
||||
In("id", ids).
|
||||
Delete(new(Upload)); err != nil {
|
||||
return fmt.Errorf("delete uploads: %v", err)
|
||||
return fmt.Errorf("delete uploads: %w", err)
|
||||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
|
@ -152,7 +152,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
|
|||
}
|
||||
|
||||
if err := util.Remove(localPath); err != nil {
|
||||
return fmt.Errorf("remove upload: %v", err)
|
||||
return fmt.Errorf("remove upload: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,11 +166,11 @@ func DeleteUploadByUUID(uuid string) error {
|
|||
if IsErrUploadNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("GetUploadByUUID: %v", err)
|
||||
return fmt.Errorf("GetUploadByUUID: %w", err)
|
||||
}
|
||||
|
||||
if err := DeleteUploads(upload); err != nil {
|
||||
return fmt.Errorf("DeleteUpload: %v", err)
|
||||
return fmt.Errorf("DeleteUpload: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -66,7 +66,7 @@ func reconsiderRepoIssuesAssignee(ctx context.Context, repo *repo_model.Reposito
|
|||
if _, err := db.GetEngine(ctx).Where(builder.Eq{"assignee_id": uid}).
|
||||
In("issue_id", builder.Select("id").From("issue").Where(builder.Eq{"repo_id": repo.ID})).
|
||||
Delete(&issues_model.IssueAssignees{}); err != nil {
|
||||
return fmt.Errorf("Could not delete assignee[%d] %v", uid, err)
|
||||
return fmt.Errorf("Could not delete assignee[%d] %w", uid, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ func CreatePendingRepositoryTransfer(doer, newOwner *user_model.User, repoID int
|
|||
|
||||
// Check if new owner has repository with same name.
|
||||
if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil {
|
||||
return fmt.Errorf("IsRepositoryExist: %v", err)
|
||||
return fmt.Errorf("IsRepositoryExist: %w", err)
|
||||
} else if has {
|
||||
return repo_model.ErrRepoAlreadyExist{
|
||||
Uname: newOwner.LowerName,
|
||||
|
@ -253,13 +253,13 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
|
||||
newOwner, err := user_model.GetUserByName(ctx, newOwnerName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
|
||||
return fmt.Errorf("get new owner '%s': %w", newOwnerName, err)
|
||||
}
|
||||
newOwnerName = newOwner.Name // ensure capitalisation matches
|
||||
|
||||
// Check if new owner has repository with same name.
|
||||
if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil {
|
||||
return fmt.Errorf("IsRepositoryExist: %v", err)
|
||||
return fmt.Errorf("IsRepositoryExist: %w", err)
|
||||
} else if has {
|
||||
return repo_model.ErrRepoAlreadyExist{
|
||||
Uname: newOwnerName,
|
||||
|
@ -278,13 +278,13 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
|
||||
// Update repository.
|
||||
if _, err := sess.ID(repo.ID).Update(repo); err != nil {
|
||||
return fmt.Errorf("update owner: %v", err)
|
||||
return fmt.Errorf("update owner: %w", err)
|
||||
}
|
||||
|
||||
// Remove redundant collaborators.
|
||||
collaborators, err := repo_model.GetCollaborators(ctx, repo.ID, db.ListOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("getCollaborators: %v", err)
|
||||
return fmt.Errorf("getCollaborators: %w", err)
|
||||
}
|
||||
|
||||
// Dummy object.
|
||||
|
@ -293,7 +293,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
if c.IsGhost() {
|
||||
collaboration.ID = c.Collaboration.ID
|
||||
if _, err := sess.Delete(collaboration); err != nil {
|
||||
return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
|
||||
return fmt.Errorf("remove collaborator '%d': %w", c.ID, err)
|
||||
}
|
||||
collaboration.ID = 0
|
||||
}
|
||||
|
@ -301,14 +301,14 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
if c.ID != newOwner.ID {
|
||||
isMember, err := organization.IsOrganizationMember(ctx, newOwner.ID, c.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("IsOrgMember: %v", err)
|
||||
return fmt.Errorf("IsOrgMember: %w", err)
|
||||
} else if !isMember {
|
||||
continue
|
||||
}
|
||||
}
|
||||
collaboration.UserID = c.ID
|
||||
if _, err := sess.Delete(collaboration); err != nil {
|
||||
return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
|
||||
return fmt.Errorf("remove collaborator '%d': %w", c.ID, err)
|
||||
}
|
||||
collaboration.UserID = 0
|
||||
}
|
||||
|
@ -316,42 +316,42 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
// Remove old team-repository relations.
|
||||
if oldOwner.IsOrganization() {
|
||||
if err := organization.RemoveOrgRepo(ctx, oldOwner.ID, repo.ID); err != nil {
|
||||
return fmt.Errorf("removeOrgRepo: %v", err)
|
||||
return fmt.Errorf("removeOrgRepo: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if newOwner.IsOrganization() {
|
||||
teams, err := organization.FindOrgTeams(ctx, newOwner.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("LoadTeams: %v", err)
|
||||
return fmt.Errorf("LoadTeams: %w", err)
|
||||
}
|
||||
for _, t := range teams {
|
||||
if t.IncludesAllRepositories {
|
||||
if err := AddRepository(ctx, t, repo); err != nil {
|
||||
return fmt.Errorf("AddRepository: %v", err)
|
||||
return fmt.Errorf("AddRepository: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if err := access_model.RecalculateAccesses(ctx, repo); err != nil {
|
||||
// Organization called this in addRepository method.
|
||||
return fmt.Errorf("recalculateAccesses: %v", err)
|
||||
return fmt.Errorf("recalculateAccesses: %w", err)
|
||||
}
|
||||
|
||||
// Update repository count.
|
||||
if _, err := sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
|
||||
return fmt.Errorf("increase new owner repository count: %v", err)
|
||||
return fmt.Errorf("increase new owner repository count: %w", err)
|
||||
} else if _, err := sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", oldOwner.ID); err != nil {
|
||||
return fmt.Errorf("decrease old owner repository count: %v", err)
|
||||
return fmt.Errorf("decrease old owner repository count: %w", err)
|
||||
}
|
||||
|
||||
if err := repo_model.WatchRepo(ctx, doer.ID, repo.ID, true); err != nil {
|
||||
return fmt.Errorf("watchRepo: %v", err)
|
||||
return fmt.Errorf("watchRepo: %w", err)
|
||||
}
|
||||
|
||||
// Remove watch for organization.
|
||||
if oldOwner.IsOrganization() {
|
||||
if err := repo_model.WatchRepo(ctx, oldOwner.ID, repo.ID, false); err != nil {
|
||||
return fmt.Errorf("watchRepo [false]: %v", err)
|
||||
return fmt.Errorf("watchRepo [false]: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
WHERE
|
||||
issue.repo_id = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != ?))
|
||||
) AS il_too )`, repo.ID, newOwner.ID); err != nil {
|
||||
return fmt.Errorf("Unable to remove old org labels: %v", err)
|
||||
return fmt.Errorf("Unable to remove old org labels: %w", err)
|
||||
}
|
||||
|
||||
if _, err := sess.Exec(`DELETE FROM comment WHERE comment.id IN (
|
||||
|
@ -378,7 +378,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
WHERE
|
||||
com.type = ? AND issue.repo_id = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != ?))
|
||||
) AS il_too)`, issues_model.CommentTypeLabel, repo.ID, newOwner.ID); err != nil {
|
||||
return fmt.Errorf("Unable to remove old org label comments: %v", err)
|
||||
return fmt.Errorf("Unable to remove old org label comments: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,11 +386,11 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
dir := user_model.UserPath(newOwner.Name)
|
||||
|
||||
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("Failed to create dir %s: %v", dir, err)
|
||||
return fmt.Errorf("Failed to create dir %s: %w", dir, err)
|
||||
}
|
||||
|
||||
if err := util.Rename(repo_model.RepoPath(oldOwner.Name, repo.Name), repo_model.RepoPath(newOwner.Name, repo.Name)); err != nil {
|
||||
return fmt.Errorf("rename repository directory: %v", err)
|
||||
return fmt.Errorf("rename repository directory: %w", err)
|
||||
}
|
||||
repoRenamed = true
|
||||
|
||||
|
@ -402,13 +402,13 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
return err
|
||||
} else if isExist {
|
||||
if err := util.Rename(wikiPath, repo_model.WikiPath(newOwner.Name, repo.Name)); err != nil {
|
||||
return fmt.Errorf("rename repository wiki: %v", err)
|
||||
return fmt.Errorf("rename repository wiki: %w", err)
|
||||
}
|
||||
wikiRenamed = true
|
||||
}
|
||||
|
||||
if err := deleteRepositoryTransfer(ctx, repo.ID); err != nil {
|
||||
return fmt.Errorf("deleteRepositoryTransfer: %v", err)
|
||||
return fmt.Errorf("deleteRepositoryTransfer: %w", err)
|
||||
}
|
||||
repo.Status = repo_model.RepositoryReady
|
||||
if err := repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil {
|
||||
|
@ -417,11 +417,11 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
|
|||
|
||||
// If there was previously a redirect at this location, remove it.
|
||||
if err := repo_model.DeleteRedirect(ctx, newOwner.ID, repo.Name); err != nil {
|
||||
return fmt.Errorf("delete repo redirect: %v", err)
|
||||
return fmt.Errorf("delete repo redirect: %w", err)
|
||||
}
|
||||
|
||||
if err := repo_model.NewRedirect(ctx, oldOwner.ID, repo.ID, repo.Name, repo.Name); err != nil {
|
||||
return fmt.Errorf("repo_model.NewRedirect: %v", err)
|
||||
return fmt.Errorf("repo_model.NewRedirect: %w", err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
|
|
@ -243,7 +243,7 @@ func Init() error {
|
|||
var err error
|
||||
GravatarSourceURL, err = url.Parse(setting.GravatarSource)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to parse Gravatar URL(%s): %v", setting.GravatarSource, err)
|
||||
return fmt.Errorf("Failed to parse Gravatar URL(%s): %w", setting.GravatarSource, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,10 +35,10 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
watchedRepoIDs := make([]int64, 0, 10)
|
||||
if err = e.Table("watch").Cols("watch.repo_id").
|
||||
Where("watch.user_id = ?", u.ID).And("watch.mode <>?", repo_model.WatchModeDont).Find(&watchedRepoIDs); err != nil {
|
||||
return fmt.Errorf("get all watches: %v", err)
|
||||
return fmt.Errorf("get all watches: %w", err)
|
||||
}
|
||||
if _, err = e.Decr("num_watches").In("id", watchedRepoIDs).NoAutoTime().Update(new(repo_model.Repository)); err != nil {
|
||||
return fmt.Errorf("decrease repository num_watches: %v", err)
|
||||
return fmt.Errorf("decrease repository num_watches: %w", err)
|
||||
}
|
||||
// ***** END: Watch *****
|
||||
|
||||
|
@ -46,9 +46,9 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
starredRepoIDs := make([]int64, 0, 10)
|
||||
if err = e.Table("star").Cols("star.repo_id").
|
||||
Where("star.uid = ?", u.ID).Find(&starredRepoIDs); err != nil {
|
||||
return fmt.Errorf("get all stars: %v", err)
|
||||
return fmt.Errorf("get all stars: %w", err)
|
||||
} else if _, err = e.Decr("num_stars").In("id", starredRepoIDs).NoAutoTime().Update(new(repo_model.Repository)); err != nil {
|
||||
return fmt.Errorf("decrease repository num_stars: %v", err)
|
||||
return fmt.Errorf("decrease repository num_stars: %w", err)
|
||||
}
|
||||
// ***** END: Star *****
|
||||
|
||||
|
@ -56,17 +56,17 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
followeeIDs := make([]int64, 0, 10)
|
||||
if err = e.Table("follow").Cols("follow.follow_id").
|
||||
Where("follow.user_id = ?", u.ID).Find(&followeeIDs); err != nil {
|
||||
return fmt.Errorf("get all followees: %v", err)
|
||||
return fmt.Errorf("get all followees: %w", err)
|
||||
} else if _, err = e.Decr("num_followers").In("id", followeeIDs).Update(new(user_model.User)); err != nil {
|
||||
return fmt.Errorf("decrease user num_followers: %v", err)
|
||||
return fmt.Errorf("decrease user num_followers: %w", err)
|
||||
}
|
||||
|
||||
followerIDs := make([]int64, 0, 10)
|
||||
if err = e.Table("follow").Cols("follow.user_id").
|
||||
Where("follow.follow_id = ?", u.ID).Find(&followerIDs); err != nil {
|
||||
return fmt.Errorf("get all followers: %v", err)
|
||||
return fmt.Errorf("get all followers: %w", err)
|
||||
} else if _, err = e.Decr("num_following").In("id", followerIDs).Update(new(user_model.User)); err != nil {
|
||||
return fmt.Errorf("decrease user num_following: %v", err)
|
||||
return fmt.Errorf("decrease user num_following: %w", err)
|
||||
}
|
||||
// ***** END: Follow *****
|
||||
|
||||
|
@ -90,7 +90,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
&pull_model.AutoMerge{DoerID: u.ID},
|
||||
&pull_model.ReviewState{UserID: u.ID},
|
||||
); err != nil {
|
||||
return fmt.Errorf("deleteBeans: %v", err)
|
||||
return fmt.Errorf("deleteBeans: %w", err)
|
||||
}
|
||||
|
||||
if err := auth_model.DeleteOAuth2RelictsByUserID(ctx, u.ID); err != nil {
|
||||
|
@ -135,7 +135,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
// Also, as we didn't update branch protections when removing entries from `access` table,
|
||||
// it's safer to iterate all protected branches.
|
||||
if err = e.Limit(batchSize, start).Find(&protections); err != nil {
|
||||
return fmt.Errorf("findProtectedBranches: %v", err)
|
||||
return fmt.Errorf("findProtectedBranches: %w", err)
|
||||
}
|
||||
if len(protections) == 0 {
|
||||
break
|
||||
|
@ -160,7 +160,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
"merge_whitelist_user_i_ds",
|
||||
"approvals_whitelist_user_i_ds",
|
||||
).Update(p); err != nil {
|
||||
return fmt.Errorf("updateProtectedBranches: %v", err)
|
||||
return fmt.Errorf("updateProtectedBranches: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,39 +170,39 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
|||
|
||||
// ***** START: PublicKey *****
|
||||
if _, err = db.DeleteByBean(ctx, &asymkey_model.PublicKey{OwnerID: u.ID}); err != nil {
|
||||
return fmt.Errorf("deletePublicKeys: %v", err)
|
||||
return fmt.Errorf("deletePublicKeys: %w", err)
|
||||
}
|
||||
// ***** END: PublicKey *****
|
||||
|
||||
// ***** START: GPGPublicKey *****
|
||||
keys, err := asymkey_model.ListGPGKeys(ctx, u.ID, db.ListOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("ListGPGKeys: %v", err)
|
||||
return fmt.Errorf("ListGPGKeys: %w", err)
|
||||
}
|
||||
// Delete GPGKeyImport(s).
|
||||
for _, key := range keys {
|
||||
if _, err = db.DeleteByBean(ctx, &asymkey_model.GPGKeyImport{KeyID: key.KeyID}); err != nil {
|
||||
return fmt.Errorf("deleteGPGKeyImports: %v", err)
|
||||
return fmt.Errorf("deleteGPGKeyImports: %w", err)
|
||||
}
|
||||
}
|
||||
if _, err = db.DeleteByBean(ctx, &asymkey_model.GPGKey{OwnerID: u.ID}); err != nil {
|
||||
return fmt.Errorf("deleteGPGKeys: %v", err)
|
||||
return fmt.Errorf("deleteGPGKeys: %w", err)
|
||||
}
|
||||
// ***** END: GPGPublicKey *****
|
||||
|
||||
// Clear assignee.
|
||||
if _, err = db.DeleteByBean(ctx, &issues_model.IssueAssignees{AssigneeID: u.ID}); err != nil {
|
||||
return fmt.Errorf("clear assignee: %v", err)
|
||||
return fmt.Errorf("clear assignee: %w", err)
|
||||
}
|
||||
|
||||
// ***** START: ExternalLoginUser *****
|
||||
if err = user_model.RemoveAllAccountLinks(ctx, u); err != nil {
|
||||
return fmt.Errorf("ExternalLoginUser: %v", err)
|
||||
return fmt.Errorf("ExternalLoginUser: %w", err)
|
||||
}
|
||||
// ***** END: ExternalLoginUser *****
|
||||
|
||||
if _, err = e.ID(u.ID).Delete(new(user_model.User)); err != nil {
|
||||
return fmt.Errorf("delete: %v", err)
|
||||
return fmt.Errorf("delete: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -35,7 +35,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
|
|||
|
||||
img, err := avatar.RandomImage([]byte(seed))
|
||||
if err != nil {
|
||||
return fmt.Errorf("RandomImage: %v", err)
|
||||
return fmt.Errorf("RandomImage: %w", err)
|
||||
}
|
||||
|
||||
u.Avatar = avatars.HashEmail(seed)
|
||||
|
@ -47,7 +47,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
|
|||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err)
|
||||
return fmt.Errorf("Failed to create dir %s: %w", u.CustomAvatarRelativePath(), err)
|
||||
}
|
||||
|
||||
if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar").Update(u); err != nil {
|
||||
|
|
|
@ -264,7 +264,7 @@ func AddEmailAddresses(emails []*EmailAddress) error {
|
|||
}
|
||||
|
||||
if err := db.Insert(db.DefaultContext, emails); err != nil {
|
||||
return fmt.Errorf("Insert: %v", err)
|
||||
return fmt.Errorf("Insert: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -485,7 +485,7 @@ func SearchEmails(opts *SearchEmailOptions) ([]*SearchEmailResult, int64, error)
|
|||
count, err := db.GetEngine(db.DefaultContext).Join("INNER", "`user`", "`user`.ID = email_address.uid").
|
||||
Where(cond).Count(new(EmailAddress))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
return nil, 0, fmt.Errorf("Count: %w", err)
|
||||
}
|
||||
|
||||
orderby := opts.SortType.String()
|
||||
|
@ -530,7 +530,7 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
|
|||
}
|
||||
if activate {
|
||||
if used, err := IsEmailActive(ctx, email, addr.ID); err != nil {
|
||||
return fmt.Errorf("unable to check isEmailActive() for %s: %v", email, err)
|
||||
return fmt.Errorf("unable to check isEmailActive() for %s: %w", email, err)
|
||||
} else if used {
|
||||
return ErrEmailAlreadyUsed{Email: email}
|
||||
}
|
||||
|
@ -551,10 +551,10 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
|
|||
if user.IsActive != activate {
|
||||
user.IsActive = activate
|
||||
if user.Rands, err = GetUserSalt(); err != nil {
|
||||
return fmt.Errorf("unable to generate salt: %v", err)
|
||||
return fmt.Errorf("unable to generate salt: %w", err)
|
||||
}
|
||||
if err = UpdateUserCols(ctx, &user, "is_active", "rands"); err != nil {
|
||||
return fmt.Errorf("unable to updateUserCols() for user ID: %d: %v", userID, err)
|
||||
return fmt.Errorf("unable to updateUserCols() for user ID: %d: %w", userID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func (users UserList) loadTwoFactorStatus(ctx context.Context) (map[int64]*auth.
|
|||
userIDs := users.GetUserIDs()
|
||||
tokenMaps := make(map[int64]*auth.TwoFactor, len(userIDs))
|
||||
if err := db.GetEngine(ctx).In("uid", userIDs).Find(&tokenMaps); err != nil {
|
||||
return nil, fmt.Errorf("find two factor: %v", err)
|
||||
return nil, fmt.Errorf("find two factor: %w", err)
|
||||
}
|
||||
return tokenMaps, nil
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (users UserList) userIDsWithWebAuthn(ctx context.Context) ([]int64, error)
|
|||
}
|
||||
ids := make([]int64, 0, len(users))
|
||||
if err := db.GetEngine(ctx).Table(new(auth.WebAuthnCredential)).In("user_id", users.GetUserIDs()).Select("user_id").Distinct("user_id").Find(&ids); err != nil {
|
||||
return nil, fmt.Errorf("find two factor: %v", err)
|
||||
return nil, fmt.Errorf("find two factor: %w", err)
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue