loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Penultimate round of `db.DefaultContext` refactor (#27414)

Part of #27065

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>

authored by

JakobDev
Lunny Xiao
and committed by
GitHub
ebe803e5 50166d1f

+428 -421
+2 -2
cmd/admin_auth.go
··· 62 62 return err 63 63 } 64 64 65 - authSources, err := auth_model.Sources() 65 + authSources, err := auth_model.Sources(ctx) 66 66 if err != nil { 67 67 return err 68 68 } ··· 100 100 return err 101 101 } 102 102 103 - source, err := auth_model.GetSourceByID(c.Int64("id")) 103 + source, err := auth_model.GetSourceByID(ctx, c.Int64("id")) 104 104 if err != nil { 105 105 return err 106 106 }
+11 -11
cmd/admin_auth_ldap.go
··· 17 17 type ( 18 18 authService struct { 19 19 initDB func(ctx context.Context) error 20 - createAuthSource func(*auth.Source) error 21 - updateAuthSource func(*auth.Source) error 22 - getAuthSourceByID func(id int64) (*auth.Source, error) 20 + createAuthSource func(context.Context, *auth.Source) error 21 + updateAuthSource func(context.Context, *auth.Source) error 22 + getAuthSourceByID func(ctx context.Context, id int64) (*auth.Source, error) 23 23 } 24 24 ) 25 25 ··· 289 289 290 290 // getAuthSource gets the login source by its id defined in the command line flags. 291 291 // It returns an error if the id is not set, does not match any source or if the source is not of expected type. 292 - func (a *authService) getAuthSource(c *cli.Context, authType auth.Type) (*auth.Source, error) { 292 + func (a *authService) getAuthSource(ctx context.Context, c *cli.Context, authType auth.Type) (*auth.Source, error) { 293 293 if err := argsSet(c, "id"); err != nil { 294 294 return nil, err 295 295 } 296 296 297 - authSource, err := a.getAuthSourceByID(c.Int64("id")) 297 + authSource, err := a.getAuthSourceByID(ctx, c.Int64("id")) 298 298 if err != nil { 299 299 return nil, err 300 300 } ··· 332 332 return err 333 333 } 334 334 335 - return a.createAuthSource(authSource) 335 + return a.createAuthSource(ctx, authSource) 336 336 } 337 337 338 338 // updateLdapBindDn updates a new LDAP via Bind DN authentication source. ··· 344 344 return err 345 345 } 346 346 347 - authSource, err := a.getAuthSource(c, auth.LDAP) 347 + authSource, err := a.getAuthSource(ctx, c, auth.LDAP) 348 348 if err != nil { 349 349 return err 350 350 } ··· 354 354 return err 355 355 } 356 356 357 - return a.updateAuthSource(authSource) 357 + return a.updateAuthSource(ctx, authSource) 358 358 } 359 359 360 360 // addLdapSimpleAuth adds a new LDAP (simple auth) authentication source. ··· 383 383 return err 384 384 } 385 385 386 - return a.createAuthSource(authSource) 386 + return a.createAuthSource(ctx, authSource) 387 387 } 388 388 389 389 // updateLdapBindDn updates a new LDAP (simple auth) authentication source. ··· 395 395 return err 396 396 } 397 397 398 - authSource, err := a.getAuthSource(c, auth.DLDAP) 398 + authSource, err := a.getAuthSource(ctx, c, auth.DLDAP) 399 399 if err != nil { 400 400 return err 401 401 } ··· 405 405 return err 406 406 } 407 407 408 - return a.updateAuthSource(authSource) 408 + return a.updateAuthSource(ctx, authSource) 409 409 }
+12 -12
cmd/admin_auth_ldap_test.go
··· 210 210 initDB: func(context.Context) error { 211 211 return nil 212 212 }, 213 - createAuthSource: func(authSource *auth.Source) error { 213 + createAuthSource: func(ctx context.Context, authSource *auth.Source) error { 214 214 createdAuthSource = authSource 215 215 return nil 216 216 }, 217 - updateAuthSource: func(authSource *auth.Source) error { 217 + updateAuthSource: func(ctx context.Context, authSource *auth.Source) error { 218 218 assert.FailNow(t, "case %d: should not call updateAuthSource", n) 219 219 return nil 220 220 }, 221 - getAuthSourceByID: func(id int64) (*auth.Source, error) { 221 + getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) { 222 222 assert.FailNow(t, "case %d: should not call getAuthSourceByID", n) 223 223 return nil, nil 224 224 }, ··· 441 441 initDB: func(context.Context) error { 442 442 return nil 443 443 }, 444 - createAuthSource: func(authSource *auth.Source) error { 444 + createAuthSource: func(ctx context.Context, authSource *auth.Source) error { 445 445 createdAuthSource = authSource 446 446 return nil 447 447 }, 448 - updateAuthSource: func(authSource *auth.Source) error { 448 + updateAuthSource: func(ctx context.Context, authSource *auth.Source) error { 449 449 assert.FailNow(t, "case %d: should not call updateAuthSource", n) 450 450 return nil 451 451 }, 452 - getAuthSourceByID: func(id int64) (*auth.Source, error) { 452 + getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) { 453 453 assert.FailNow(t, "case %d: should not call getAuthSourceByID", n) 454 454 return nil, nil 455 455 }, ··· 896 896 initDB: func(context.Context) error { 897 897 return nil 898 898 }, 899 - createAuthSource: func(authSource *auth.Source) error { 899 + createAuthSource: func(ctx context.Context, authSource *auth.Source) error { 900 900 assert.FailNow(t, "case %d: should not call createAuthSource", n) 901 901 return nil 902 902 }, 903 - updateAuthSource: func(authSource *auth.Source) error { 903 + updateAuthSource: func(ctx context.Context, authSource *auth.Source) error { 904 904 updatedAuthSource = authSource 905 905 return nil 906 906 }, 907 - getAuthSourceByID: func(id int64) (*auth.Source, error) { 907 + getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) { 908 908 if c.id != 0 { 909 909 assert.Equal(t, c.id, id, "case %d: wrong id", n) 910 910 } ··· 1286 1286 initDB: func(context.Context) error { 1287 1287 return nil 1288 1288 }, 1289 - createAuthSource: func(authSource *auth.Source) error { 1289 + createAuthSource: func(ctx context.Context, authSource *auth.Source) error { 1290 1290 assert.FailNow(t, "case %d: should not call createAuthSource", n) 1291 1291 return nil 1292 1292 }, 1293 - updateAuthSource: func(authSource *auth.Source) error { 1293 + updateAuthSource: func(ctx context.Context, authSource *auth.Source) error { 1294 1294 updatedAuthSource = authSource 1295 1295 return nil 1296 1296 }, 1297 - getAuthSourceByID: func(id int64) (*auth.Source, error) { 1297 + getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) { 1298 1298 if c.id != 0 { 1299 1299 assert.Equal(t, c.id, id, "case %d: wrong id", n) 1300 1300 }
+3 -3
cmd/admin_auth_oauth.go
··· 183 183 } 184 184 } 185 185 186 - return auth_model.CreateSource(&auth_model.Source{ 186 + return auth_model.CreateSource(ctx, &auth_model.Source{ 187 187 Type: auth_model.OAuth2, 188 188 Name: c.String("name"), 189 189 IsActive: true, ··· 203 203 return err 204 204 } 205 205 206 - source, err := auth_model.GetSourceByID(c.Int64("id")) 206 + source, err := auth_model.GetSourceByID(ctx, c.Int64("id")) 207 207 if err != nil { 208 208 return err 209 209 } ··· 294 294 oAuth2Config.CustomURLMapping = customURLMapping 295 295 source.Cfg = oAuth2Config 296 296 297 - return auth_model.UpdateSource(source) 297 + return auth_model.UpdateSource(ctx, source) 298 298 }
+3 -3
cmd/admin_auth_stmp.go
··· 156 156 smtpConfig.Auth = "PLAIN" 157 157 } 158 158 159 - return auth_model.CreateSource(&auth_model.Source{ 159 + return auth_model.CreateSource(ctx, &auth_model.Source{ 160 160 Type: auth_model.SMTP, 161 161 Name: c.String("name"), 162 162 IsActive: active, ··· 176 176 return err 177 177 } 178 178 179 - source, err := auth_model.GetSourceByID(c.Int64("id")) 179 + source, err := auth_model.GetSourceByID(ctx, c.Int64("id")) 180 180 if err != nil { 181 181 return err 182 182 } ··· 197 197 198 198 source.Cfg = smtpConfig 199 199 200 - return auth_model.UpdateSource(source) 200 + return auth_model.UpdateSource(ctx, source) 201 201 }
+1 -1
models/actions/run_job_list.go
··· 42 42 for _, r := range runs { 43 43 runsList = append(runsList, r) 44 44 } 45 - return runsList.LoadRepos() 45 + return runsList.LoadRepos(ctx) 46 46 } 47 47 return nil 48 48 }
+2 -2
models/actions/run_list.go
··· 52 52 return nil 53 53 } 54 54 55 - func (runs RunList) LoadRepos() error { 55 + func (runs RunList) LoadRepos(ctx context.Context) error { 56 56 repoIDs := runs.GetRepoIDs() 57 - repos, err := repo_model.GetRepositoriesMapByIDs(repoIDs) 57 + repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs) 58 58 if err != nil { 59 59 return err 60 60 }
+2 -2
models/actions/schedule_list.go
··· 49 49 return nil 50 50 } 51 51 52 - func (schedules ScheduleList) LoadRepos() error { 52 + func (schedules ScheduleList) LoadRepos(ctx context.Context) error { 53 53 repoIDs := schedules.GetRepoIDs() 54 - repos, err := repo_model.GetRepositoriesMapByIDs(repoIDs) 54 + repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs) 55 55 if err != nil { 56 56 return err 57 57 }
+2 -2
models/actions/schedule_spec_list.go
··· 53 53 return ids.Values() 54 54 } 55 55 56 - func (specs SpecList) LoadRepos() error { 56 + func (specs SpecList) LoadRepos(ctx context.Context) error { 57 57 repoIDs := specs.GetRepoIDs() 58 - repos, err := repo_model.GetRepositoriesMapByIDs(repoIDs) 58 + repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs) 59 59 if err != nil { 60 60 return err 61 61 }
+1 -1
models/activities/statistic.go
··· 102 102 stats.Counter.Follow, _ = e.Count(new(user_model.Follow)) 103 103 stats.Counter.Mirror, _ = e.Count(new(repo_model.Mirror)) 104 104 stats.Counter.Release, _ = e.Count(new(repo_model.Release)) 105 - stats.Counter.AuthSource = auth.CountSources() 105 + stats.Counter.AuthSource = auth.CountSources(ctx) 106 106 stats.Counter.Webhook, _ = e.Count(new(webhook.Webhook)) 107 107 stats.Counter.Milestone, _ = e.Count(new(issues_model.Milestone)) 108 108 stats.Counter.Label, _ = e.Count(new(issues_model.Label))
+28 -28
models/asymkey/ssh_key.go
··· 91 91 } 92 92 93 93 // AddPublicKey adds new public key to database and authorized_keys file. 94 - func AddPublicKey(ownerID int64, name, content string, authSourceID int64) (*PublicKey, error) { 94 + func AddPublicKey(ctx context.Context, ownerID int64, name, content string, authSourceID int64) (*PublicKey, error) { 95 95 log.Trace(content) 96 96 97 97 fingerprint, err := CalcFingerprint(content) ··· 99 99 return nil, err 100 100 } 101 101 102 - ctx, committer, err := db.TxContext(db.DefaultContext) 102 + ctx, committer, err := db.TxContext(ctx) 103 103 if err != nil { 104 104 return nil, err 105 105 } ··· 136 136 } 137 137 138 138 // GetPublicKeyByID returns public key by given ID. 139 - func GetPublicKeyByID(keyID int64) (*PublicKey, error) { 139 + func GetPublicKeyByID(ctx context.Context, keyID int64) (*PublicKey, error) { 140 140 key := new(PublicKey) 141 - has, err := db.GetEngine(db.DefaultContext). 141 + has, err := db.GetEngine(ctx). 142 142 ID(keyID). 143 143 Get(key) 144 144 if err != nil { ··· 180 180 } 181 181 182 182 // SearchPublicKey returns a list of public keys matching the provided arguments. 183 - func SearchPublicKey(uid int64, fingerprint string) ([]*PublicKey, error) { 183 + func SearchPublicKey(ctx context.Context, uid int64, fingerprint string) ([]*PublicKey, error) { 184 184 keys := make([]*PublicKey, 0, 5) 185 185 cond := builder.NewCond() 186 186 if uid != 0 { ··· 189 189 if fingerprint != "" { 190 190 cond = cond.And(builder.Eq{"fingerprint": fingerprint}) 191 191 } 192 - return keys, db.GetEngine(db.DefaultContext).Where(cond).Find(&keys) 192 + return keys, db.GetEngine(ctx).Where(cond).Find(&keys) 193 193 } 194 194 195 195 // ListPublicKeys returns a list of public keys belongs to given user. 196 - func ListPublicKeys(uid int64, listOptions db.ListOptions) ([]*PublicKey, error) { 197 - sess := db.GetEngine(db.DefaultContext).Where("owner_id = ? AND type != ?", uid, KeyTypePrincipal) 196 + func ListPublicKeys(ctx context.Context, uid int64, listOptions db.ListOptions) ([]*PublicKey, error) { 197 + sess := db.GetEngine(ctx).Where("owner_id = ? AND type != ?", uid, KeyTypePrincipal) 198 198 if listOptions.Page != 0 { 199 199 sess = db.SetSessionPagination(sess, &listOptions) 200 200 ··· 207 207 } 208 208 209 209 // CountPublicKeys count public keys a user has 210 - func CountPublicKeys(userID int64) (int64, error) { 211 - sess := db.GetEngine(db.DefaultContext).Where("owner_id = ? AND type != ?", userID, KeyTypePrincipal) 210 + func CountPublicKeys(ctx context.Context, userID int64) (int64, error) { 211 + sess := db.GetEngine(ctx).Where("owner_id = ? AND type != ?", userID, KeyTypePrincipal) 212 212 return sess.Count(&PublicKey{}) 213 213 } 214 214 215 215 // ListPublicKeysBySource returns a list of synchronized public keys for a given user and login source. 216 - func ListPublicKeysBySource(uid, authSourceID int64) ([]*PublicKey, error) { 216 + func ListPublicKeysBySource(ctx context.Context, uid, authSourceID int64) ([]*PublicKey, error) { 217 217 keys := make([]*PublicKey, 0, 5) 218 - return keys, db.GetEngine(db.DefaultContext). 218 + return keys, db.GetEngine(ctx). 219 219 Where("owner_id = ? AND login_source_id = ?", uid, authSourceID). 220 220 Find(&keys) 221 221 } 222 222 223 223 // UpdatePublicKeyUpdated updates public key use time. 224 - func UpdatePublicKeyUpdated(id int64) error { 224 + func UpdatePublicKeyUpdated(ctx context.Context, id int64) error { 225 225 // Check if key exists before update as affected rows count is unreliable 226 226 // and will return 0 affected rows if two updates are made at the same time 227 - if cnt, err := db.GetEngine(db.DefaultContext).ID(id).Count(&PublicKey{}); err != nil { 227 + if cnt, err := db.GetEngine(ctx).ID(id).Count(&PublicKey{}); err != nil { 228 228 return err 229 229 } else if cnt != 1 { 230 230 return ErrKeyNotExist{id} 231 231 } 232 232 233 - _, err := db.GetEngine(db.DefaultContext).ID(id).Cols("updated_unix").Update(&PublicKey{ 233 + _, err := db.GetEngine(ctx).ID(id).Cols("updated_unix").Update(&PublicKey{ 234 234 UpdatedUnix: timeutil.TimeStampNow(), 235 235 }) 236 236 if err != nil { ··· 250 250 } 251 251 252 252 // PublicKeysAreExternallyManaged returns whether the provided KeyID represents an externally managed Key 253 - func PublicKeysAreExternallyManaged(keys []*PublicKey) ([]bool, error) { 253 + func PublicKeysAreExternallyManaged(ctx context.Context, keys []*PublicKey) ([]bool, error) { 254 254 sources := make([]*auth.Source, 0, 5) 255 255 externals := make([]bool, len(keys)) 256 256 keyloop: ··· 272 272 273 273 if source == nil { 274 274 var err error 275 - source, err = auth.GetSourceByID(key.LoginSourceID) 275 + source, err = auth.GetSourceByID(ctx, key.LoginSourceID) 276 276 if err != nil { 277 277 if auth.IsErrSourceNotExist(err) { 278 278 externals[i] = false ··· 295 295 } 296 296 297 297 // PublicKeyIsExternallyManaged returns whether the provided KeyID represents an externally managed Key 298 - func PublicKeyIsExternallyManaged(id int64) (bool, error) { 299 - key, err := GetPublicKeyByID(id) 298 + func PublicKeyIsExternallyManaged(ctx context.Context, id int64) (bool, error) { 299 + key, err := GetPublicKeyByID(ctx, id) 300 300 if err != nil { 301 301 return false, err 302 302 } 303 303 if key.LoginSourceID == 0 { 304 304 return false, nil 305 305 } 306 - source, err := auth.GetSourceByID(key.LoginSourceID) 306 + source, err := auth.GetSourceByID(ctx, key.LoginSourceID) 307 307 if err != nil { 308 308 if auth.IsErrSourceNotExist(err) { 309 309 return false, nil ··· 318 318 } 319 319 320 320 // deleteKeysMarkedForDeletion returns true if ssh keys needs update 321 - func deleteKeysMarkedForDeletion(keys []string) (bool, error) { 321 + func deleteKeysMarkedForDeletion(ctx context.Context, keys []string) (bool, error) { 322 322 // Start session 323 - ctx, committer, err := db.TxContext(db.DefaultContext) 323 + ctx, committer, err := db.TxContext(ctx) 324 324 if err != nil { 325 325 return false, err 326 326 } ··· 349 349 } 350 350 351 351 // AddPublicKeysBySource add a users public keys. Returns true if there are changes. 352 - func AddPublicKeysBySource(usr *user_model.User, s *auth.Source, sshPublicKeys []string) bool { 352 + func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string) bool { 353 353 var sshKeysNeedUpdate bool 354 354 for _, sshKey := range sshPublicKeys { 355 355 var err error ··· 368 368 marshalled = marshalled[:len(marshalled)-1] 369 369 sshKeyName := fmt.Sprintf("%s-%s", s.Name, ssh.FingerprintSHA256(out)) 370 370 371 - if _, err := AddPublicKey(usr.ID, sshKeyName, marshalled, s.ID); err != nil { 371 + if _, err := AddPublicKey(ctx, usr.ID, sshKeyName, marshalled, s.ID); err != nil { 372 372 if IsErrKeyAlreadyExist(err) { 373 373 log.Trace("AddPublicKeysBySource[%s]: Public SSH Key %s already exists for user", sshKeyName, usr.Name) 374 374 } else { ··· 387 387 } 388 388 389 389 // SynchronizePublicKeys updates a users public keys. Returns true if there are changes. 390 - func SynchronizePublicKeys(usr *user_model.User, s *auth.Source, sshPublicKeys []string) bool { 390 + func SynchronizePublicKeys(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string) bool { 391 391 var sshKeysNeedUpdate bool 392 392 393 393 log.Trace("synchronizePublicKeys[%s]: Handling Public SSH Key synchronization for user %s", s.Name, usr.Name) 394 394 395 395 // Get Public Keys from DB with current LDAP source 396 396 var giteaKeys []string 397 - keys, err := ListPublicKeysBySource(usr.ID, s.ID) 397 + keys, err := ListPublicKeysBySource(ctx, usr.ID, s.ID) 398 398 if err != nil { 399 399 log.Error("synchronizePublicKeys[%s]: Error listing Public SSH Keys for user %s: %v", s.Name, usr.Name, err) 400 400 } ··· 429 429 newKeys = append(newKeys, key) 430 430 } 431 431 } 432 - if AddPublicKeysBySource(usr, s, newKeys) { 432 + if AddPublicKeysBySource(ctx, usr, s, newKeys) { 433 433 sshKeysNeedUpdate = true 434 434 } 435 435 ··· 443 443 } 444 444 445 445 // Delete keys from DB that no longer exist in the source 446 - needUpd, err := deleteKeysMarkedForDeletion(giteaKeysToDelete) 446 + needUpd, err := deleteKeysMarkedForDeletion(ctx, giteaKeysToDelete) 447 447 if err != nil { 448 448 log.Error("synchronizePublicKeys[%s]: Error deleting Public Keys marked for deletion for user %s: %v", s.Name, usr.Name, err) 449 449 }
+1 -1
models/asymkey/ssh_key_commit_verification.go
··· 21 21 func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committer *user_model.User) *CommitVerification { 22 22 // Now try to associate the signature with the committer, if present 23 23 if committer.ID != 0 { 24 - keys, err := ListPublicKeys(committer.ID, db.ListOptions{}) 24 + keys, err := ListPublicKeys(ctx, committer.ID, db.ListOptions{}) 25 25 if err != nil { // Skipping failed to get ssh keys of user 26 26 log.Error("ListPublicKeys: %v", err) 27 27 return &CommitVerification{
+2 -2
models/asymkey/ssh_key_deploy.go
··· 48 48 } 49 49 50 50 // GetContent gets associated public key content. 51 - func (key *DeployKey) GetContent() error { 52 - pkey, err := GetPublicKeyByID(key.KeyID) 51 + func (key *DeployKey) GetContent(ctx context.Context) error { 52 + pkey, err := GetPublicKeyByID(ctx, key.KeyID) 53 53 if err != nil { 54 54 return err 55 55 }
+24 -23
models/auth/source.go
··· 5 5 package auth 6 6 7 7 import ( 8 + "context" 8 9 "fmt" 9 10 "reflect" 10 11 ··· 199 200 200 201 // CreateSource inserts a AuthSource in the DB if not already 201 202 // existing with the given name. 202 - func CreateSource(source *Source) error { 203 - has, err := db.GetEngine(db.DefaultContext).Where("name=?", source.Name).Exist(new(Source)) 203 + func CreateSource(ctx context.Context, source *Source) error { 204 + has, err := db.GetEngine(ctx).Where("name=?", source.Name).Exist(new(Source)) 204 205 if err != nil { 205 206 return err 206 207 } else if has { ··· 211 212 source.IsSyncEnabled = false 212 213 } 213 214 214 - _, err = db.GetEngine(db.DefaultContext).Insert(source) 215 + _, err = db.GetEngine(ctx).Insert(source) 215 216 if err != nil { 216 217 return err 217 218 } ··· 232 233 err = registerableSource.RegisterSource() 233 234 if err != nil { 234 235 // remove the AuthSource in case of errors while registering configuration 235 - if _, err := db.GetEngine(db.DefaultContext).Delete(source); err != nil { 236 + if _, err := db.GetEngine(ctx).Delete(source); err != nil { 236 237 log.Error("CreateSource: Error while wrapOpenIDConnectInitializeError: %v", err) 237 238 } 238 239 } ··· 240 241 } 241 242 242 243 // Sources returns a slice of all login sources found in DB. 243 - func Sources() ([]*Source, error) { 244 + func Sources(ctx context.Context) ([]*Source, error) { 244 245 auths := make([]*Source, 0, 6) 245 - return auths, db.GetEngine(db.DefaultContext).Find(&auths) 246 + return auths, db.GetEngine(ctx).Find(&auths) 246 247 } 247 248 248 249 // SourcesByType returns all sources of the specified type 249 - func SourcesByType(loginType Type) ([]*Source, error) { 250 + func SourcesByType(ctx context.Context, loginType Type) ([]*Source, error) { 250 251 sources := make([]*Source, 0, 1) 251 - if err := db.GetEngine(db.DefaultContext).Where("type = ?", loginType).Find(&sources); err != nil { 252 + if err := db.GetEngine(ctx).Where("type = ?", loginType).Find(&sources); err != nil { 252 253 return nil, err 253 254 } 254 255 return sources, nil 255 256 } 256 257 257 258 // AllActiveSources returns all active sources 258 - func AllActiveSources() ([]*Source, error) { 259 + func AllActiveSources(ctx context.Context) ([]*Source, error) { 259 260 sources := make([]*Source, 0, 5) 260 - if err := db.GetEngine(db.DefaultContext).Where("is_active = ?", true).Find(&sources); err != nil { 261 + if err := db.GetEngine(ctx).Where("is_active = ?", true).Find(&sources); err != nil { 261 262 return nil, err 262 263 } 263 264 return sources, nil 264 265 } 265 266 266 267 // ActiveSources returns all active sources of the specified type 267 - func ActiveSources(tp Type) ([]*Source, error) { 268 + func ActiveSources(ctx context.Context, tp Type) ([]*Source, error) { 268 269 sources := make([]*Source, 0, 1) 269 - if err := db.GetEngine(db.DefaultContext).Where("is_active = ? and type = ?", true, tp).Find(&sources); err != nil { 270 + if err := db.GetEngine(ctx).Where("is_active = ? and type = ?", true, tp).Find(&sources); err != nil { 270 271 return nil, err 271 272 } 272 273 return sources, nil ··· 274 275 275 276 // IsSSPIEnabled returns true if there is at least one activated login 276 277 // source of type LoginSSPI 277 - func IsSSPIEnabled() bool { 278 + func IsSSPIEnabled(ctx context.Context) bool { 278 279 if !db.HasEngine { 279 280 return false 280 281 } 281 - sources, err := ActiveSources(SSPI) 282 + sources, err := ActiveSources(ctx, SSPI) 282 283 if err != nil { 283 284 log.Error("ActiveSources: %v", err) 284 285 return false ··· 287 288 } 288 289 289 290 // GetSourceByID returns login source by given ID. 290 - func GetSourceByID(id int64) (*Source, error) { 291 + func GetSourceByID(ctx context.Context, id int64) (*Source, error) { 291 292 source := new(Source) 292 293 if id == 0 { 293 294 source.Cfg = registeredConfigs[NoType]() ··· 297 298 return source, nil 298 299 } 299 300 300 - has, err := db.GetEngine(db.DefaultContext).ID(id).Get(source) 301 + has, err := db.GetEngine(ctx).ID(id).Get(source) 301 302 if err != nil { 302 303 return nil, err 303 304 } else if !has { ··· 307 308 } 308 309 309 310 // UpdateSource updates a Source record in DB. 310 - func UpdateSource(source *Source) error { 311 + func UpdateSource(ctx context.Context, source *Source) error { 311 312 var originalSource *Source 312 313 if source.IsOAuth2() { 313 314 // keep track of the original values so we can restore in case of errors while registering OAuth2 providers 314 315 var err error 315 - if originalSource, err = GetSourceByID(source.ID); err != nil { 316 + if originalSource, err = GetSourceByID(ctx, source.ID); err != nil { 316 317 return err 317 318 } 318 319 } 319 320 320 - has, err := db.GetEngine(db.DefaultContext).Where("name=? AND id!=?", source.Name, source.ID).Exist(new(Source)) 321 + has, err := db.GetEngine(ctx).Where("name=? AND id!=?", source.Name, source.ID).Exist(new(Source)) 321 322 if err != nil { 322 323 return err 323 324 } else if has { 324 325 return ErrSourceAlreadyExist{source.Name} 325 326 } 326 327 327 - _, err = db.GetEngine(db.DefaultContext).ID(source.ID).AllCols().Update(source) 328 + _, err = db.GetEngine(ctx).ID(source.ID).AllCols().Update(source) 328 329 if err != nil { 329 330 return err 330 331 } ··· 345 346 err = registerableSource.RegisterSource() 346 347 if err != nil { 347 348 // restore original values since we cannot update the provider it self 348 - if _, err := db.GetEngine(db.DefaultContext).ID(source.ID).AllCols().Update(originalSource); err != nil { 349 + if _, err := db.GetEngine(ctx).ID(source.ID).AllCols().Update(originalSource); err != nil { 349 350 log.Error("UpdateSource: Error while wrapOpenIDConnectInitializeError: %v", err) 350 351 } 351 352 } ··· 353 354 } 354 355 355 356 // CountSources returns number of login sources. 356 - func CountSources() int64 { 357 - count, _ := db.GetEngine(db.DefaultContext).Count(new(Source)) 357 + func CountSources(ctx context.Context) int64 { 358 + count, _ := db.GetEngine(ctx).Count(new(Source)) 358 359 return count 359 360 } 360 361
+1 -1
models/auth/source_test.go
··· 42 42 43 43 auth_model.RegisterTypeConfig(auth_model.OAuth2, new(TestSource)) 44 44 45 - auth_model.CreateSource(&auth_model.Source{ 45 + auth_model.CreateSource(db.DefaultContext, &auth_model.Source{ 46 46 Type: auth_model.OAuth2, 47 47 Name: "TestSource", 48 48 IsActive: false,
+1 -1
models/issues/comment_code.go
··· 111 111 if comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 112 112 Ctx: ctx, 113 113 URLPrefix: issue.Repo.Link(), 114 - Metas: issue.Repo.ComposeMetas(), 114 + Metas: issue.Repo.ComposeMetas(ctx), 115 115 }, comment.Content); err != nil { 116 116 return nil, err 117 117 }
+4 -4
models/issues/dependency.go
··· 127 127 ) 128 128 129 129 // CreateIssueDependency creates a new dependency for an issue 130 - func CreateIssueDependency(user *user_model.User, issue, dep *Issue) error { 131 - ctx, committer, err := db.TxContext(db.DefaultContext) 130 + func CreateIssueDependency(ctx context.Context, user *user_model.User, issue, dep *Issue) error { 131 + ctx, committer, err := db.TxContext(ctx) 132 132 if err != nil { 133 133 return err 134 134 } ··· 168 168 } 169 169 170 170 // RemoveIssueDependency removes a dependency from an issue 171 - func RemoveIssueDependency(user *user_model.User, issue, dep *Issue, depType DependencyType) (err error) { 172 - ctx, committer, err := db.TxContext(db.DefaultContext) 171 + func RemoveIssueDependency(ctx context.Context, user *user_model.User, issue, dep *Issue, depType DependencyType) (err error) { 172 + ctx, committer, err := db.TxContext(ctx) 173 173 if err != nil { 174 174 return err 175 175 }
+4 -4
models/issues/dependency_test.go
··· 28 28 assert.NoError(t, err) 29 29 30 30 // Create a dependency and check if it was successful 31 - err = issues_model.CreateIssueDependency(user1, issue1, issue2) 31 + err = issues_model.CreateIssueDependency(db.DefaultContext, user1, issue1, issue2) 32 32 assert.NoError(t, err) 33 33 34 34 // Do it again to see if it will check if the dependency already exists 35 - err = issues_model.CreateIssueDependency(user1, issue1, issue2) 35 + err = issues_model.CreateIssueDependency(db.DefaultContext, user1, issue1, issue2) 36 36 assert.Error(t, err) 37 37 assert.True(t, issues_model.IsErrDependencyExists(err)) 38 38 39 39 // Check for circular dependencies 40 - err = issues_model.CreateIssueDependency(user1, issue2, issue1) 40 + err = issues_model.CreateIssueDependency(db.DefaultContext, user1, issue2, issue1) 41 41 assert.Error(t, err) 42 42 assert.True(t, issues_model.IsErrCircularDependency(err)) 43 43 ··· 57 57 assert.True(t, left) 58 58 59 59 // Test removing the dependency 60 - err = issues_model.RemoveIssueDependency(user1, issue1, issue2, issues_model.DependencyTypeBlockedBy) 60 + err = issues_model.RemoveIssueDependency(db.DefaultContext, user1, issue1, issue2, issues_model.DependencyTypeBlockedBy) 61 61 assert.NoError(t, err) 62 62 }
+9 -9
models/issues/issue_label.go
··· 83 83 } 84 84 85 85 // NewIssueLabel creates a new issue-label relation. 86 - func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error) { 87 - if HasIssueLabel(db.DefaultContext, issue.ID, label.ID) { 86 + func NewIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *user_model.User) (err error) { 87 + if HasIssueLabel(ctx, issue.ID, label.ID) { 88 88 return nil 89 89 } 90 90 91 - ctx, committer, err := db.TxContext(db.DefaultContext) 91 + ctx, committer, err := db.TxContext(ctx) 92 92 if err != nil { 93 93 return err 94 94 } ··· 149 149 } 150 150 151 151 // NewIssueLabels creates a list of issue-label relations. 152 - func NewIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) { 153 - ctx, committer, err := db.TxContext(db.DefaultContext) 152 + func NewIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *user_model.User) (err error) { 153 + ctx, committer, err := db.TxContext(ctx) 154 154 if err != nil { 155 155 return err 156 156 } ··· 359 359 360 360 // ClearIssueLabels removes all issue labels as the given user. 361 361 // Triggers appropriate WebHooks, if any. 362 - func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) { 363 - ctx, committer, err := db.TxContext(db.DefaultContext) 362 + func ClearIssueLabels(ctx context.Context, issue *Issue, doer *user_model.User) (err error) { 363 + ctx, committer, err := db.TxContext(ctx) 364 364 if err != nil { 365 365 return err 366 366 } ··· 432 432 433 433 // ReplaceIssueLabels removes all current labels and add new labels to the issue. 434 434 // Triggers appropriate WebHooks, if any. 435 - func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) { 436 - ctx, committer, err := db.TxContext(db.DefaultContext) 435 + func ReplaceIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *user_model.User) (err error) { 436 + ctx, committer, err := db.TxContext(ctx) 437 437 if err != nil { 438 438 return err 439 439 }
+2 -1
models/issues/issue_label_test.go
··· 6 6 import ( 7 7 "testing" 8 8 9 + "code.gitea.io/gitea/models/db" 9 10 issues_model "code.gitea.io/gitea/models/issues" 10 11 "code.gitea.io/gitea/models/unittest" 11 12 user_model "code.gitea.io/gitea/models/user" ··· 21 22 label2 := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 8}) 22 23 doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 23 24 24 - assert.NoError(t, issues_model.NewIssueLabels(issue, []*issues_model.Label{label1, label2}, doer)) 25 + assert.NoError(t, issues_model.NewIssueLabels(db.DefaultContext, issue, []*issues_model.Label{label1, label2}, doer)) 25 26 26 27 assert.Len(t, issue.Labels, 1) 27 28 assert.Equal(t, label2.ID, issue.Labels[0].ID)
+8 -6
models/issues/issue_lock.go
··· 4 4 package issues 5 5 6 6 import ( 7 + "context" 8 + 7 9 "code.gitea.io/gitea/models/db" 8 10 user_model "code.gitea.io/gitea/models/user" 9 11 ) ··· 17 19 18 20 // LockIssue locks an issue. This would limit commenting abilities to 19 21 // users with write access to the repo 20 - func LockIssue(opts *IssueLockOptions) error { 21 - return updateIssueLock(opts, true) 22 + func LockIssue(ctx context.Context, opts *IssueLockOptions) error { 23 + return updateIssueLock(ctx, opts, true) 22 24 } 23 25 24 26 // UnlockIssue unlocks a previously locked issue. 25 - func UnlockIssue(opts *IssueLockOptions) error { 26 - return updateIssueLock(opts, false) 27 + func UnlockIssue(ctx context.Context, opts *IssueLockOptions) error { 28 + return updateIssueLock(ctx, opts, false) 27 29 } 28 30 29 - func updateIssueLock(opts *IssueLockOptions, lock bool) error { 31 + func updateIssueLock(ctx context.Context, opts *IssueLockOptions, lock bool) error { 30 32 if opts.Issue.IsLocked == lock { 31 33 return nil 32 34 } ··· 39 41 commentType = CommentTypeUnlock 40 42 } 41 43 42 - ctx, committer, err := db.TxContext(db.DefaultContext) 44 + ctx, committer, err := db.TxContext(ctx) 43 45 if err != nil { 44 46 return err 45 47 }
+5 -9
models/issues/issue_project.go
··· 38 38 } 39 39 40 40 // ProjectBoardID return project board id if issue was assigned to one 41 - func (issue *Issue) ProjectBoardID() int64 { 42 - return issue.projectBoardID(db.DefaultContext) 43 - } 44 - 45 - func (issue *Issue) projectBoardID(ctx context.Context) int64 { 41 + func (issue *Issue) ProjectBoardID(ctx context.Context) int64 { 46 42 var ip project_model.ProjectIssue 47 43 has, err := db.GetEngine(ctx).Where("issue_id=?", issue.ID).Get(&ip) 48 44 if err != nil || !has { ··· 100 96 } 101 97 102 98 // ChangeProjectAssign changes the project associated with an issue 103 - func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64) error { 104 - ctx, committer, err := db.TxContext(db.DefaultContext) 99 + func ChangeProjectAssign(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error { 100 + ctx, committer, err := db.TxContext(ctx) 105 101 if err != nil { 106 102 return err 107 103 } ··· 156 152 } 157 153 158 154 // MoveIssueAcrossProjectBoards move a card from one board to another 159 - func MoveIssueAcrossProjectBoards(issue *Issue, board *project_model.Board) error { 160 - ctx, committer, err := db.TxContext(db.DefaultContext) 155 + func MoveIssueAcrossProjectBoards(ctx context.Context, issue *Issue, board *project_model.Board) error { 156 + ctx, committer, err := db.TxContext(ctx) 161 157 if err != nil { 162 158 return err 163 159 }
+2 -2
models/issues/issue_search.go
··· 444 444 } 445 445 446 446 // GetRepoIDsForIssuesOptions find all repo ids for the given options 447 - func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]int64, error) { 447 + func GetRepoIDsForIssuesOptions(ctx context.Context, opts *IssuesOptions, user *user_model.User) ([]int64, error) { 448 448 repoIDs := make([]int64, 0, 5) 449 - e := db.GetEngine(db.DefaultContext) 449 + e := db.GetEngine(ctx) 450 450 451 451 sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id") 452 452
+3 -3
models/issues/issue_test.go
··· 34 34 for i, labelID := range labelIDs { 35 35 labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID, RepoID: repo.ID}) 36 36 } 37 - assert.NoError(t, issues_model.ReplaceIssueLabels(issue, labels, doer)) 37 + assert.NoError(t, issues_model.ReplaceIssueLabels(db.DefaultContext, issue, labels, doer)) 38 38 unittest.AssertCount(t, &issues_model.IssueLabel{IssueID: issueID}, len(expectedLabelIDs)) 39 39 for _, labelID := range expectedLabelIDs { 40 40 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issueID, LabelID: labelID}) ··· 122 122 assert.NoError(t, unittest.PrepareTestDatabase()) 123 123 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID}) 124 124 doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}) 125 - assert.NoError(t, issues_model.ClearIssueLabels(issue, doer)) 125 + assert.NoError(t, issues_model.ClearIssueLabels(db.DefaultContext, issue, doer)) 126 126 unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{IssueID: test.issueID}) 127 127 } 128 128 } ··· 230 230 []int64{1, 2}, 231 231 }, 232 232 } { 233 - repoIDs, err := issues_model.GetRepoIDsForIssuesOptions(&test.Opts, user) 233 + repoIDs, err := issues_model.GetRepoIDsForIssuesOptions(db.DefaultContext, &test.Opts, user) 234 234 assert.NoError(t, err) 235 235 if assert.Len(t, repoIDs, len(test.ExpectedRepoIDs)) { 236 236 for i, repoID := range repoIDs {
+8 -8
models/issues/label_test.go
··· 307 307 308 308 // add new IssueLabel 309 309 prevNumIssues := label.NumIssues 310 - assert.NoError(t, issues_model.NewIssueLabel(issue, label, doer)) 310 + assert.NoError(t, issues_model.NewIssueLabel(db.DefaultContext, issue, label, doer)) 311 311 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID}) 312 312 unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ 313 313 Type: issues_model.CommentTypeLabel, ··· 320 320 assert.EqualValues(t, prevNumIssues+1, label.NumIssues) 321 321 322 322 // re-add existing IssueLabel 323 - assert.NoError(t, issues_model.NewIssueLabel(issue, label, doer)) 323 + assert.NoError(t, issues_model.NewIssueLabel(db.DefaultContext, issue, label, doer)) 324 324 unittest.CheckConsistencyFor(t, &issues_model.Issue{}, &issues_model.Label{}) 325 325 } 326 326 ··· 334 334 exclusiveLabelB := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 8}) 335 335 336 336 // coexisting regular and exclusive label 337 - assert.NoError(t, issues_model.NewIssueLabel(issue, otherLabel, doer)) 338 - assert.NoError(t, issues_model.NewIssueLabel(issue, exclusiveLabelA, doer)) 337 + assert.NoError(t, issues_model.NewIssueLabel(db.DefaultContext, issue, otherLabel, doer)) 338 + assert.NoError(t, issues_model.NewIssueLabel(db.DefaultContext, issue, exclusiveLabelA, doer)) 339 339 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: otherLabel.ID}) 340 340 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelA.ID}) 341 341 342 342 // exclusive label replaces existing one 343 - assert.NoError(t, issues_model.NewIssueLabel(issue, exclusiveLabelB, doer)) 343 + assert.NoError(t, issues_model.NewIssueLabel(db.DefaultContext, issue, exclusiveLabelB, doer)) 344 344 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: otherLabel.ID}) 345 345 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelB.ID}) 346 346 unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelA.ID}) 347 347 348 348 // exclusive label replaces existing one again 349 - assert.NoError(t, issues_model.NewIssueLabel(issue, exclusiveLabelA, doer)) 349 + assert.NoError(t, issues_model.NewIssueLabel(db.DefaultContext, issue, exclusiveLabelA, doer)) 350 350 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: otherLabel.ID}) 351 351 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelA.ID}) 352 352 unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelB.ID}) ··· 359 359 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 5}) 360 360 doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 361 361 362 - assert.NoError(t, issues_model.NewIssueLabels(issue, []*issues_model.Label{label1, label2}, doer)) 362 + assert.NoError(t, issues_model.NewIssueLabels(db.DefaultContext, issue, []*issues_model.Label{label1, label2}, doer)) 363 363 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label1.ID}) 364 364 unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ 365 365 Type: issues_model.CommentTypeLabel, ··· 377 377 assert.EqualValues(t, 1, label2.NumClosedIssues) 378 378 379 379 // corner case: test empty slice 380 - assert.NoError(t, issues_model.NewIssueLabels(issue, []*issues_model.Label{}, doer)) 380 + assert.NoError(t, issues_model.NewIssueLabels(db.DefaultContext, issue, []*issues_model.Label{}, doer)) 381 381 382 382 unittest.CheckConsistencyFor(t, &issues_model.Issue{}, &issues_model.Label{}) 383 383 }
+2 -2
models/issues/milestone_list.go
··· 58 58 } 59 59 60 60 // GetMilestones returns milestones filtered by GetMilestonesOption's 61 - func GetMilestones(opts GetMilestonesOption) (MilestoneList, int64, error) { 62 - sess := db.GetEngine(db.DefaultContext).Where(opts.toCond()) 61 + func GetMilestones(ctx context.Context, opts GetMilestonesOption) (MilestoneList, int64, error) { 62 + sess := db.GetEngine(ctx).Where(opts.toCond()) 63 63 64 64 if opts.Page != 0 { 65 65 sess = db.SetSessionPagination(sess, &opts)
+4 -4
models/issues/milestone_test.go
··· 40 40 assert.NoError(t, unittest.PrepareTestDatabase()) 41 41 test := func(repoID int64, state api.StateType) { 42 42 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) 43 - milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ 43 + milestones, _, err := issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{ 44 44 RepoID: repo.ID, 45 45 State: state, 46 46 }) ··· 77 77 test(3, api.StateClosed) 78 78 test(3, api.StateAll) 79 79 80 - milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ 80 + milestones, _, err := issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{ 81 81 RepoID: unittest.NonexistentID, 82 82 State: api.StateOpen, 83 83 }) ··· 90 90 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) 91 91 test := func(sortType string, sortCond func(*issues_model.Milestone) int) { 92 92 for _, page := range []int{0, 1} { 93 - milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ 93 + milestones, _, err := issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{ 94 94 ListOptions: db.ListOptions{ 95 95 Page: page, 96 96 PageSize: setting.UI.IssuePagingNum, ··· 107 107 } 108 108 assert.True(t, sort.IntsAreSorted(values)) 109 109 110 - milestones, _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{ 110 + milestones, _, err = issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{ 111 111 ListOptions: db.ListOptions{ 112 112 Page: page, 113 113 PageSize: setting.UI.IssuePagingNum,
+21 -21
models/issues/pull.go
··· 378 378 } 379 379 380 380 // GetApprovers returns the approvers of the pull request 381 - func (pr *PullRequest) GetApprovers() string { 381 + func (pr *PullRequest) GetApprovers(ctx context.Context) string { 382 382 stringBuilder := strings.Builder{} 383 - if err := pr.getReviewedByLines(&stringBuilder); err != nil { 383 + if err := pr.getReviewedByLines(ctx, &stringBuilder); err != nil { 384 384 log.Error("Unable to getReviewedByLines: Error: %v", err) 385 385 return "" 386 386 } ··· 388 388 return stringBuilder.String() 389 389 } 390 390 391 - func (pr *PullRequest) getReviewedByLines(writer io.Writer) error { 391 + func (pr *PullRequest) getReviewedByLines(ctx context.Context, writer io.Writer) error { 392 392 maxReviewers := setting.Repository.PullRequest.DefaultMergeMessageMaxApprovers 393 393 394 394 if maxReviewers == 0 { 395 395 return nil 396 396 } 397 397 398 - ctx, committer, err := db.TxContext(db.DefaultContext) 398 + ctx, committer, err := db.TxContext(ctx) 399 399 if err != nil { 400 400 return err 401 401 } ··· 594 594 595 595 // GetLatestPullRequestByHeadInfo returns the latest pull request (regardless of its status) 596 596 // by given head information (repo and branch). 597 - func GetLatestPullRequestByHeadInfo(repoID int64, branch string) (*PullRequest, error) { 597 + func GetLatestPullRequestByHeadInfo(ctx context.Context, repoID int64, branch string) (*PullRequest, error) { 598 598 pr := new(PullRequest) 599 - has, err := db.GetEngine(db.DefaultContext). 599 + has, err := db.GetEngine(ctx). 600 600 Where("head_repo_id = ? AND head_branch = ? AND flow = ?", repoID, branch, PullRequestFlowGithub). 601 601 OrderBy("id DESC"). 602 602 Get(pr) ··· 646 646 } 647 647 648 648 // GetPullRequestByIssueIDWithNoAttributes returns pull request with no attributes loaded by given issue ID. 649 - func GetPullRequestByIssueIDWithNoAttributes(issueID int64) (*PullRequest, error) { 649 + func GetPullRequestByIssueIDWithNoAttributes(ctx context.Context, issueID int64) (*PullRequest, error) { 650 650 var pr PullRequest 651 - has, err := db.GetEngine(db.DefaultContext).Where("issue_id = ?", issueID).Get(&pr) 651 + has, err := db.GetEngine(ctx).Where("issue_id = ?", issueID).Get(&pr) 652 652 if err != nil { 653 653 return nil, err 654 654 } ··· 687 687 } 688 688 689 689 // Update updates all fields of pull request. 690 - func (pr *PullRequest) Update() error { 691 - _, err := db.GetEngine(db.DefaultContext).ID(pr.ID).AllCols().Update(pr) 690 + func (pr *PullRequest) Update(ctx context.Context) error { 691 + _, err := db.GetEngine(ctx).ID(pr.ID).AllCols().Update(pr) 692 692 return err 693 693 } 694 694 695 695 // UpdateCols updates specific fields of pull request. 696 - func (pr *PullRequest) UpdateCols(cols ...string) error { 697 - _, err := db.GetEngine(db.DefaultContext).ID(pr.ID).Cols(cols...).Update(pr) 696 + func (pr *PullRequest) UpdateCols(ctx context.Context, cols ...string) error { 697 + _, err := db.GetEngine(ctx).ID(pr.ID).Cols(cols...).Update(pr) 698 698 return err 699 699 } 700 700 ··· 706 706 707 707 // IsWorkInProgress determine if the Pull Request is a Work In Progress by its title 708 708 // Issue must be set before this method can be called. 709 - func (pr *PullRequest) IsWorkInProgress() bool { 710 - if err := pr.LoadIssue(db.DefaultContext); err != nil { 709 + func (pr *PullRequest) IsWorkInProgress(ctx context.Context) bool { 710 + if err := pr.LoadIssue(ctx); err != nil { 711 711 log.Error("LoadIssue: %v", err) 712 712 return false 713 713 } ··· 774 774 } 775 775 776 776 // GetBaseBranchLink returns the relative URL of the base branch 777 - func (pr *PullRequest) GetBaseBranchLink() string { 778 - if err := pr.LoadBaseRepo(db.DefaultContext); err != nil { 777 + func (pr *PullRequest) GetBaseBranchLink(ctx context.Context) string { 778 + if err := pr.LoadBaseRepo(ctx); err != nil { 779 779 log.Error("LoadBaseRepo: %v", err) 780 780 return "" 781 781 } ··· 786 786 } 787 787 788 788 // GetHeadBranchLink returns the relative URL of the head branch 789 - func (pr *PullRequest) GetHeadBranchLink() string { 789 + func (pr *PullRequest) GetHeadBranchLink(ctx context.Context) string { 790 790 if pr.Flow == PullRequestFlowAGit { 791 791 return "" 792 792 } 793 793 794 - if err := pr.LoadHeadRepo(db.DefaultContext); err != nil { 794 + if err := pr.LoadHeadRepo(ctx); err != nil { 795 795 log.Error("LoadHeadRepo: %v", err) 796 796 return "" 797 797 } ··· 810 810 } 811 811 812 812 // Mergeable returns if the pullrequest is mergeable. 813 - func (pr *PullRequest) Mergeable() bool { 813 + func (pr *PullRequest) Mergeable(ctx context.Context) bool { 814 814 // If a pull request isn't mergable if it's: 815 815 // - Being conflict checked. 816 816 // - Has a conflict. 817 817 // - Received a error while being conflict checked. 818 818 // - Is a work-in-progress pull request. 819 819 return pr.Status != PullRequestStatusChecking && pr.Status != PullRequestStatusConflict && 820 - pr.Status != PullRequestStatusError && !pr.IsWorkInProgress() 820 + pr.Status != PullRequestStatusError && !pr.IsWorkInProgress(ctx) 821 821 } 822 822 823 823 // HasEnoughApprovals returns true if pr has enough granted approvals. ··· 890 890 func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullRequest) error { 891 891 files := []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"} 892 892 893 - if pr.IsWorkInProgress() { 893 + if pr.IsWorkInProgress(ctx) { 894 894 return nil 895 895 } 896 896
+6 -6
models/issues/pull_test.go
··· 213 213 pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}) 214 214 pr.BaseBranch = "baseBranch" 215 215 pr.HeadBranch = "headBranch" 216 - pr.Update() 216 + pr.Update(db.DefaultContext) 217 217 218 218 pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: pr.ID}) 219 219 assert.Equal(t, "baseBranch", pr.BaseBranch) ··· 228 228 BaseBranch: "baseBranch", 229 229 HeadBranch: "headBranch", 230 230 } 231 - assert.NoError(t, pr.UpdateCols("head_branch")) 231 + assert.NoError(t, pr.UpdateCols(db.DefaultContext, "head_branch")) 232 232 233 233 pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}) 234 234 assert.Equal(t, "master", pr.BaseBranch) ··· 260 260 pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}) 261 261 pr.LoadIssue(db.DefaultContext) 262 262 263 - assert.False(t, pr.IsWorkInProgress()) 263 + assert.False(t, pr.IsWorkInProgress(db.DefaultContext)) 264 264 265 265 pr.Issue.Title = "WIP: " + pr.Issue.Title 266 - assert.True(t, pr.IsWorkInProgress()) 266 + assert.True(t, pr.IsWorkInProgress(db.DefaultContext)) 267 267 268 268 pr.Issue.Title = "[wip]: " + pr.Issue.Title 269 - assert.True(t, pr.IsWorkInProgress()) 269 + assert.True(t, pr.IsWorkInProgress(db.DefaultContext)) 270 270 } 271 271 272 272 func TestPullRequest_GetWorkInProgressPrefixWorkInProgress(t *testing.T) { ··· 334 334 // Official reviews are already deduplicated. Allow unofficial reviews 335 335 // to assert that there are no duplicated approvers. 336 336 setting.Repository.PullRequest.DefaultMergeMessageOfficialApproversOnly = false 337 - approvers := pr.GetApprovers() 337 + approvers := pr.GetApprovers(db.DefaultContext) 338 338 expected := "Reviewed-by: User Five <user5@example.com>\nReviewed-by: Org Six <org6@example.com>\n" 339 339 assert.EqualValues(t, expected, approvers) 340 340 }
+5 -5
models/repo.go
··· 277 277 return nil 278 278 } 279 279 280 - func updateUserStarNumbers(users []user_model.User) error { 281 - ctx, committer, err := db.TxContext(db.DefaultContext) 280 + func updateUserStarNumbers(ctx context.Context, users []user_model.User) error { 281 + ctx, committer, err := db.TxContext(ctx) 282 282 if err != nil { 283 283 return err 284 284 } ··· 294 294 } 295 295 296 296 // DoctorUserStarNum recalculate Stars number for all user 297 - func DoctorUserStarNum() (err error) { 297 + func DoctorUserStarNum(ctx context.Context) (err error) { 298 298 const batchSize = 100 299 299 300 300 for start := 0; ; start += batchSize { 301 301 users := make([]user_model.User, 0, batchSize) 302 - if err = db.GetEngine(db.DefaultContext).Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil { 302 + if err = db.GetEngine(ctx).Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil { 303 303 return err 304 304 } 305 305 if len(users) == 0 { 306 306 break 307 307 } 308 308 309 - if err = updateUserStarNumbers(users); err != nil { 309 + if err = updateUserStarNumbers(ctx, users); err != nil { 310 310 return err 311 311 } 312 312 }
+2 -2
models/repo/avatar.go
··· 31 31 } 32 32 33 33 // RelAvatarLink returns a relative link to the repository's avatar. 34 - func (repo *Repository) RelAvatarLink() string { 35 - return repo.relAvatarLink(db.DefaultContext) 34 + func (repo *Repository) RelAvatarLink(ctx context.Context) string { 35 + return repo.relAvatarLink(ctx) 36 36 } 37 37 38 38 // generateRandomAvatar generates a random avatar for repository.
+6 -6
models/repo/language_stats.go
··· 108 108 } 109 109 110 110 // GetTopLanguageStats returns the top language statistics for a repository 111 - func GetTopLanguageStats(repo *Repository, limit int) (LanguageStatList, error) { 112 - stats, err := GetLanguageStats(db.DefaultContext, repo) 111 + func GetTopLanguageStats(ctx context.Context, repo *Repository, limit int) (LanguageStatList, error) { 112 + stats, err := GetLanguageStats(ctx, repo) 113 113 if err != nil { 114 114 return nil, err 115 115 } ··· 140 140 } 141 141 142 142 // UpdateLanguageStats updates the language statistics for repository 143 - func UpdateLanguageStats(repo *Repository, commitID string, stats map[string]int64) error { 144 - ctx, committer, err := db.TxContext(db.DefaultContext) 143 + func UpdateLanguageStats(ctx context.Context, repo *Repository, commitID string, stats map[string]int64) error { 144 + ctx, committer, err := db.TxContext(ctx) 145 145 if err != nil { 146 146 return err 147 147 } ··· 212 212 } 213 213 214 214 // CopyLanguageStat Copy originalRepo language stat information to destRepo (use for forked repo) 215 - func CopyLanguageStat(originalRepo, destRepo *Repository) error { 216 - ctx, committer, err := db.TxContext(db.DefaultContext) 215 + func CopyLanguageStat(ctx context.Context, originalRepo, destRepo *Repository) error { 216 + ctx, committer, err := db.TxContext(ctx) 217 217 if err != nil { 218 218 return err 219 219 }
+14 -14
models/repo/repo.go
··· 447 447 } 448 448 449 449 // ComposeMetas composes a map of metas for properly rendering issue links and external issue trackers. 450 - func (repo *Repository) ComposeMetas() map[string]string { 450 + func (repo *Repository) ComposeMetas(ctx context.Context) map[string]string { 451 451 if len(repo.RenderingMetas) == 0 { 452 452 metas := map[string]string{ 453 453 "user": repo.OwnerName, ··· 456 456 "mode": "comment", 457 457 } 458 458 459 - unit, err := repo.GetUnit(db.DefaultContext, unit.TypeExternalTracker) 459 + unit, err := repo.GetUnit(ctx, unit.TypeExternalTracker) 460 460 if err == nil { 461 461 metas["format"] = unit.ExternalTrackerConfig().ExternalTrackerFormat 462 462 switch unit.ExternalTrackerConfig().ExternalTrackerStyle { ··· 470 470 } 471 471 } 472 472 473 - repo.MustOwner(db.DefaultContext) 473 + repo.MustOwner(ctx) 474 474 if repo.Owner.IsOrganization() { 475 475 teams := make([]string, 0, 5) 476 - _ = db.GetEngine(db.DefaultContext).Table("team_repo"). 476 + _ = db.GetEngine(ctx).Table("team_repo"). 477 477 Join("INNER", "team", "team.id = team_repo.team_id"). 478 478 Where("team_repo.repo_id = ?", repo.ID). 479 479 Select("team.lower_name"). ··· 489 489 } 490 490 491 491 // ComposeDocumentMetas composes a map of metas for properly rendering documents 492 - func (repo *Repository) ComposeDocumentMetas() map[string]string { 492 + func (repo *Repository) ComposeDocumentMetas(ctx context.Context) map[string]string { 493 493 if len(repo.DocumentRenderingMetas) == 0 { 494 494 metas := map[string]string{} 495 - for k, v := range repo.ComposeMetas() { 495 + for k, v := range repo.ComposeMetas(ctx) { 496 496 metas[k] = v 497 497 } 498 498 metas["mode"] = "document" ··· 566 566 } 567 567 568 568 // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled. 569 - func (repo *Repository) AllowsPulls() bool { 570 - return repo.CanEnablePulls() && repo.UnitEnabled(db.DefaultContext, unit.TypePullRequests) 569 + func (repo *Repository) AllowsPulls(ctx context.Context) bool { 570 + return repo.CanEnablePulls() && repo.UnitEnabled(ctx, unit.TypePullRequests) 571 571 } 572 572 573 573 // CanEnableEditor returns true if repository meets the requirements of web editor. ··· 718 718 } 719 719 720 720 // GetRepositoryByName returns the repository by given name under user if exists. 721 - func GetRepositoryByName(ownerID int64, name string) (*Repository, error) { 721 + func GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*Repository, error) { 722 722 repo := &Repository{ 723 723 OwnerID: ownerID, 724 724 LowerName: strings.ToLower(name), 725 725 } 726 - has, err := db.GetEngine(db.DefaultContext).Get(repo) 726 + has, err := db.GetEngine(ctx).Get(repo) 727 727 if err != nil { 728 728 return nil, err 729 729 } else if !has { ··· 788 788 } 789 789 790 790 // GetRepositoriesMapByIDs returns the repositories by given id slice. 791 - func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error) { 791 + func GetRepositoriesMapByIDs(ctx context.Context, ids []int64) (map[int64]*Repository, error) { 792 792 repos := make(map[int64]*Repository, len(ids)) 793 - return repos, db.GetEngine(db.DefaultContext).In("id", ids).Find(&repos) 793 + return repos, db.GetEngine(ctx).In("id", ids).Find(&repos) 794 794 } 795 795 796 796 // IsRepositoryModelOrDirExist returns true if the repository with given name under user has already existed. ··· 822 822 } 823 823 824 824 // TemplateRepo returns the repository, which is template of this repository 825 - func (repo *Repository) TemplateRepo() *Repository { 826 - repo, err := GetTemplateRepo(db.DefaultContext, repo) 825 + func (repo *Repository) TemplateRepo(ctx context.Context) *Repository { 826 + repo, err := GetTemplateRepo(ctx, repo) 827 827 if err != nil { 828 828 log.Error("TemplateRepo: %v", err) 829 829 return nil
+2 -2
models/repo/repo_indexer.go
··· 36 36 } 37 37 38 38 // GetUnindexedRepos returns repos which do not have an indexer status 39 - func GetUnindexedRepos(indexerType RepoIndexerType, maxRepoID int64, page, pageSize int) ([]int64, error) { 39 + func GetUnindexedRepos(ctx context.Context, indexerType RepoIndexerType, maxRepoID int64, page, pageSize int) ([]int64, error) { 40 40 ids := make([]int64, 0, 50) 41 41 cond := builder.Cond(builder.IsNull{ 42 42 "repo_indexer_status.id", 43 43 }).And(builder.Eq{ 44 44 "repository.is_empty": false, 45 45 }) 46 - sess := db.GetEngine(db.DefaultContext).Table("repository").Join("LEFT OUTER", "repo_indexer_status", "repository.id = repo_indexer_status.repo_id AND repo_indexer_status.indexer_type = ?", indexerType) 46 + sess := db.GetEngine(ctx).Table("repository").Join("LEFT OUTER", "repo_indexer_status", "repository.id = repo_indexer_status.repo_id AND repo_indexer_status.indexer_type = ?", indexerType) 47 47 if maxRepoID > 0 { 48 48 cond = builder.And(cond, builder.Lte{ 49 49 "repository.id": maxRepoID,
+4 -4
models/repo/repo_list.go
··· 21 21 ) 22 22 23 23 // FindReposMapByIDs find repos as map 24 - func FindReposMapByIDs(repoIDs []int64, res map[int64]*Repository) error { 25 - return db.GetEngine(db.DefaultContext).In("id", repoIDs).Find(&res) 24 + func FindReposMapByIDs(ctx context.Context, repoIDs []int64, res map[int64]*Repository) error { 25 + return db.GetEngine(ctx).In("id", repoIDs).Find(&res) 26 26 } 27 27 28 28 // RepositoryListDefaultPageSize is the default number of repositories ··· 672 672 673 673 // SearchRepositoryIDs takes keyword and part of repository name to search, 674 674 // it returns results in given range and number of total results. 675 - func SearchRepositoryIDs(opts *SearchRepoOptions) ([]int64, int64, error) { 675 + func SearchRepositoryIDs(ctx context.Context, opts *SearchRepoOptions) ([]int64, int64, error) { 676 676 opts.IncludeDescription = false 677 677 678 678 cond := SearchRepositoryCondition(opts) 679 679 680 - sess, count, err := searchRepositoryByCondition(db.DefaultContext, opts, cond) 680 + sess, count, err := searchRepositoryByCondition(ctx, opts, cond) 681 681 if err != nil { 682 682 return nil, 0, err 683 683 }
+3 -3
models/repo/repo_test.go
··· 83 83 84 84 repo.Units = nil 85 85 86 - metas := repo.ComposeMetas() 86 + metas := repo.ComposeMetas(db.DefaultContext) 87 87 assert.Equal(t, "testRepo", metas["repo"]) 88 88 assert.Equal(t, "testOwner", metas["user"]) 89 89 ··· 97 97 testSuccess := func(expectedStyle string) { 98 98 repo.Units = []*repo_model.RepoUnit{&externalTracker} 99 99 repo.RenderingMetas = nil 100 - metas := repo.ComposeMetas() 100 + metas := repo.ComposeMetas(db.DefaultContext) 101 101 assert.Equal(t, expectedStyle, metas["style"]) 102 102 assert.Equal(t, "testRepo", metas["repo"]) 103 103 assert.Equal(t, "testOwner", metas["user"]) ··· 118 118 repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 3) 119 119 assert.NoError(t, err) 120 120 121 - metas = repo.ComposeMetas() 121 + metas = repo.ComposeMetas(db.DefaultContext) 122 122 assert.Contains(t, metas, "org") 123 123 assert.Contains(t, metas, "teams") 124 124 assert.Equal(t, "org3", metas["org"])
+1 -1
models/repo_test.go
··· 20 20 func TestDoctorUserStarNum(t *testing.T) { 21 21 assert.NoError(t, unittest.PrepareTestDatabase()) 22 22 23 - assert.NoError(t, DoctorUserStarNum()) 23 + assert.NoError(t, DoctorUserStarNum(db.DefaultContext)) 24 24 }
+3 -3
modules/context/repo.go
··· 495 495 } 496 496 497 497 // Get repository. 498 - repo, err := repo_model.GetRepositoryByName(owner.ID, repoName) 498 + repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, repoName) 499 499 if err != nil { 500 500 if repo_model.IsErrRepoNotExist(err) { 501 501 redirectRepoID, err := repo_model.LookupRedirect(owner.ID, repoName) ··· 711 711 712 712 // Pull request is allowed if this is a fork repository 713 713 // and base repository accepts pull requests. 714 - if repo.BaseRepo != nil && repo.BaseRepo.AllowsPulls() { 714 + if repo.BaseRepo != nil && repo.BaseRepo.AllowsPulls(ctx) { 715 715 canCompare = true 716 716 ctx.Data["BaseRepo"] = repo.BaseRepo 717 717 ctx.Repo.PullRequest.BaseRepo = repo.BaseRepo 718 718 ctx.Repo.PullRequest.Allowed = canPush 719 719 ctx.Repo.PullRequest.HeadInfoSubURL = url.PathEscape(ctx.Repo.Owner.Name) + ":" + util.PathEscapeSegments(ctx.Repo.BranchName) 720 - } else if repo.AllowsPulls() { 720 + } else if repo.AllowsPulls(ctx) { 721 721 // Or, this is repository accepts pull requests between branches. 722 722 canCompare = true 723 723 ctx.Data["BaseRepo"] = repo
+1 -1
modules/doctor/mergebase.go
··· 74 74 pr.MergeBase = strings.TrimSpace(pr.MergeBase) 75 75 if pr.MergeBase != oldMergeBase { 76 76 if autofix { 77 - if err := pr.UpdateCols("merge_base"); err != nil { 77 + if err := pr.UpdateCols(ctx, "merge_base"); err != nil { 78 78 logger.Critical("Failed to update merge_base. ERROR: %v", err) 79 79 return fmt.Errorf("Failed to update merge_base. ERROR: %w", err) 80 80 }
+1 -1
modules/doctor/misc.go
··· 74 74 75 75 func checkUserStarNum(ctx context.Context, logger log.Logger, autofix bool) error { 76 76 if autofix { 77 - if err := models.DoctorUserStarNum(); err != nil { 77 + if err := models.DoctorUserStarNum(ctx); err != nil { 78 78 logger.Critical("Unable update User Stars numbers") 79 79 return err 80 80 }
+1 -1
modules/indexer/code/indexer.go
··· 288 288 return 289 289 default: 290 290 } 291 - ids, err := repo_model.GetUnindexedRepos(repo_model.RepoIndexerTypeCode, maxRepoID, 0, 50) 291 + ids, err := repo_model.GetUnindexedRepos(ctx, repo_model.RepoIndexerTypeCode, maxRepoID, 0, 50) 292 292 if err != nil { 293 293 log.Error("populateRepoIndexer: %v", err) 294 294 return
+1 -1
modules/indexer/issues/util.go
··· 107 107 NoLabel: len(labels) == 0, 108 108 MilestoneID: issue.MilestoneID, 109 109 ProjectID: projectID, 110 - ProjectBoardID: issue.ProjectBoardID(), 110 + ProjectBoardID: issue.ProjectBoardID(ctx), 111 111 PosterID: issue.PosterID, 112 112 AssigneeID: issue.AssigneeID, 113 113 MentionIDs: mentionIDs,
+1 -1
modules/indexer/stats/db.go
··· 68 68 } 69 69 return err 70 70 } 71 - err = repo_model.UpdateLanguageStats(repo, commitID, stats) 71 + err = repo_model.UpdateLanguageStats(ctx, repo, commitID, stats) 72 72 if err != nil { 73 73 log.Error("Unable to update language stats for ID %s for default branch %s in %s. Error: %v", commitID, repo.DefaultBranch, repo.RepoPath(), err) 74 74 return err
+5 -3
modules/indexer/stats/indexer.go
··· 4 4 package stats 5 5 6 6 import ( 7 + "context" 8 + 7 9 "code.gitea.io/gitea/models/db" 8 10 repo_model "code.gitea.io/gitea/models/repo" 9 11 "code.gitea.io/gitea/modules/graceful" ··· 28 30 return err 29 31 } 30 32 31 - go populateRepoIndexer() 33 + go populateRepoIndexer(db.DefaultContext) 32 34 33 35 return nil 34 36 } 35 37 36 38 // populateRepoIndexer populate the repo indexer with pre-existing data. This 37 39 // should only be run when the indexer is created for the first time. 38 - func populateRepoIndexer() { 40 + func populateRepoIndexer(ctx context.Context) { 39 41 log.Info("Populating the repo stats indexer with existing repositories") 40 42 41 43 isShutdown := graceful.GetManager().IsShutdown() ··· 62 64 return 63 65 default: 64 66 } 65 - ids, err := repo_model.GetUnindexedRepos(repo_model.RepoIndexerTypeStats, maxRepoID, 0, 50) 67 + ids, err := repo_model.GetUnindexedRepos(ctx, repo_model.RepoIndexerTypeStats, maxRepoID, 0, 50) 66 68 if err != nil { 67 69 log.Error("populateRepoIndexer: %v", err) 68 70 return
+1 -1
modules/indexer/stats/indexer_test.go
··· 45 45 status, err := repo_model.GetIndexerStatus(db.DefaultContext, repo, repo_model.RepoIndexerTypeStats) 46 46 assert.NoError(t, err) 47 47 assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.CommitSha) 48 - langs, err := repo_model.GetTopLanguageStats(repo, 5) 48 + langs, err := repo_model.GetTopLanguageStats(db.DefaultContext, repo, 5) 49 49 assert.NoError(t, err) 50 50 assert.Empty(t, langs) 51 51 }
+1 -1
routers/api/v1/admin/user.go
··· 36 36 return 37 37 } 38 38 39 - source, err := auth.GetSourceByID(sourceID) 39 + source, err := auth.GetSourceByID(ctx, sourceID) 40 40 if err != nil { 41 41 if auth.IsErrSourceNotExist(err) { 42 42 ctx.Error(http.StatusUnprocessableEntity, "", err)
+3 -2
routers/api/v1/api.go
··· 70 70 71 71 actions_model "code.gitea.io/gitea/models/actions" 72 72 auth_model "code.gitea.io/gitea/models/auth" 73 + "code.gitea.io/gitea/models/db" 73 74 "code.gitea.io/gitea/models/organization" 74 75 "code.gitea.io/gitea/models/perm" 75 76 access_model "code.gitea.io/gitea/models/perm/access" ··· 165 166 ctx.ContextUser = owner 166 167 167 168 // Get repository. 168 - repo, err := repo_model.GetRepositoryByName(owner.ID, repoName) 169 + repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, repoName) 169 170 if err != nil { 170 171 if repo_model.IsErrRepoNotExist(err) { 171 172 redirectRepoID, err := repo_model.LookupRedirect(owner.ID, repoName) ··· 716 717 group.Add(&auth.ReverseProxy{}) 717 718 } 718 719 719 - if setting.IsWindows && auth_model.IsSSPIEnabled() { 720 + if setting.IsWindows && auth_model.IsSSPIEnabled(db.DefaultContext) { 720 721 group.Add(&auth.SSPI{}) // it MUST be the last, see the comment of SSPI 721 722 } 722 723
+2 -2
routers/api/v1/org/avatar.go
··· 43 43 return 44 44 } 45 45 46 - err = user_service.UploadAvatar(ctx.Org.Organization.AsUser(), content) 46 + err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content) 47 47 if err != nil { 48 48 ctx.Error(http.StatusInternalServerError, "UploadAvatar", err) 49 49 } ··· 69 69 // "$ref": "#/responses/empty" 70 70 // "404": 71 71 // "$ref": "#/responses/notFound" 72 - err := user_service.DeleteAvatar(ctx.Org.Organization.AsUser()) 72 + err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser()) 73 73 if err != nil { 74 74 ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err) 75 75 }
+1 -1
routers/api/v1/org/team.go
··· 638 638 639 639 // getRepositoryByParams get repository by a team's organization ID and repo name 640 640 func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository { 641 - repo, err := repo_model.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame")) 641 + repo, err := repo_model.GetRepositoryByName(ctx, ctx.Org.Team.OrgID, ctx.Params(":reponame")) 642 642 if err != nil { 643 643 if repo_model.IsErrRepoNotExist(err) { 644 644 ctx.NotFound()
+2 -2
routers/api/v1/repo/issue.go
··· 188 188 allPublic = true 189 189 opts.AllPublic = false // set it false to avoid returning too many repos, we could filter by indexer 190 190 } 191 - repoIDs, _, err = repo_model.SearchRepositoryIDs(opts) 191 + repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts) 192 192 if err != nil { 193 193 ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err) 194 194 return ··· 837 837 issue.MilestoneID != *form.Milestone { 838 838 oldMilestoneID := issue.MilestoneID 839 839 issue.MilestoneID = *form.Milestone 840 - if err = issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil { 840 + if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { 841 841 ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err) 842 842 return 843 843 }
+2 -2
routers/api/v1/repo/issue_dependency.go
··· 576 576 return 577 577 } 578 578 579 - err := issues_model.CreateIssueDependency(ctx.Doer, target, dependency) 579 + err := issues_model.CreateIssueDependency(ctx, ctx.Doer, target, dependency) 580 580 if err != nil { 581 581 ctx.Error(http.StatusInternalServerError, "CreateIssueDependency", err) 582 582 return ··· 602 602 return 603 603 } 604 604 605 - err := issues_model.RemoveIssueDependency(ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy) 605 + err := issues_model.RemoveIssueDependency(ctx, ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy) 606 606 if err != nil { 607 607 ctx.Error(http.StatusInternalServerError, "CreateIssueDependency", err) 608 608 return
+2 -2
routers/api/v1/repo/key.go
··· 105 105 apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) 106 106 apiKeys := make([]*api.DeployKey, len(keys)) 107 107 for i := range keys { 108 - if err := keys[i].GetContent(); err != nil { 108 + if err := keys[i].GetContent(ctx); err != nil { 109 109 ctx.Error(http.StatusInternalServerError, "GetContent", err) 110 110 return 111 111 } ··· 159 159 return 160 160 } 161 161 162 - if err = key.GetContent(); err != nil { 162 + if err = key.GetContent(ctx); err != nil { 163 163 ctx.Error(http.StatusInternalServerError, "GetContent", err) 164 164 return 165 165 }
+1 -1
routers/api/v1/repo/milestone.go
··· 58 58 // "404": 59 59 // "$ref": "#/responses/notFound" 60 60 61 - milestones, total, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ 61 + milestones, total, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ 62 62 ListOptions: utils.GetListOptions(ctx), 63 63 RepoID: ctx.Repo.Repository.ID, 64 64 State: api.StateType(ctx.FormString("state")),
+2 -2
routers/api/v1/repo/pull.go
··· 555 555 issue.MilestoneID != form.Milestone { 556 556 oldMilestoneID := issue.MilestoneID 557 557 issue.MilestoneID = form.Milestone 558 - if err = issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil { 558 + if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { 559 559 ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err) 560 560 return 561 561 } ··· 578 578 labels = append(labels, orgLabels...) 579 579 } 580 580 581 - if err = issues_model.ReplaceIssueLabels(issue, labels, ctx.Doer); err != nil { 581 + if err = issues_model.ReplaceIssueLabels(ctx, issue, labels, ctx.Doer); err != nil { 582 582 ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err) 583 583 return 584 584 }
+2 -2
routers/api/v1/user/avatar.go
··· 36 36 return 37 37 } 38 38 39 - err = user_service.UploadAvatar(ctx.Doer, content) 39 + err = user_service.UploadAvatar(ctx, ctx.Doer, content) 40 40 if err != nil { 41 41 ctx.Error(http.StatusInternalServerError, "UploadAvatar", err) 42 42 } ··· 54 54 // responses: 55 55 // "204": 56 56 // "$ref": "#/responses/empty" 57 - err := user_service.DeleteAvatar(ctx.Doer) 57 + err := user_service.DeleteAvatar(ctx, ctx.Doer) 58 58 if err != nil { 59 59 ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err) 60 60 }
+7 -7
routers/api/v1/user/key.go
··· 59 59 // Querying not just listing 60 60 if username != "" { 61 61 // Restrict to provided uid 62 - keys, err = asymkey_model.SearchPublicKey(user.ID, fingerprint) 62 + keys, err = asymkey_model.SearchPublicKey(ctx, user.ID, fingerprint) 63 63 } else { 64 64 // Unrestricted 65 - keys, err = asymkey_model.SearchPublicKey(0, fingerprint) 65 + keys, err = asymkey_model.SearchPublicKey(ctx, 0, fingerprint) 66 66 } 67 67 count = len(keys) 68 68 } else { 69 - total, err2 := asymkey_model.CountPublicKeys(user.ID) 69 + total, err2 := asymkey_model.CountPublicKeys(ctx, user.ID) 70 70 if err2 != nil { 71 71 ctx.InternalServerError(err) 72 72 return ··· 74 74 count = int(total) 75 75 76 76 // Use ListPublicKeys 77 - keys, err = asymkey_model.ListPublicKeys(user.ID, utils.GetListOptions(ctx)) 77 + keys, err = asymkey_model.ListPublicKeys(ctx, user.ID, utils.GetListOptions(ctx)) 78 78 } 79 79 80 80 if err != nil { ··· 176 176 // "404": 177 177 // "$ref": "#/responses/notFound" 178 178 179 - key, err := asymkey_model.GetPublicKeyByID(ctx.ParamsInt64(":id")) 179 + key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.ParamsInt64(":id")) 180 180 if err != nil { 181 181 if asymkey_model.IsErrKeyNotExist(err) { 182 182 ctx.NotFound() ··· 202 202 return 203 203 } 204 204 205 - key, err := asymkey_model.AddPublicKey(uid, form.Title, content, 0) 205 + key, err := asymkey_model.AddPublicKey(ctx, uid, form.Title, content, 0) 206 206 if err != nil { 207 207 repo.HandleAddKeyError(ctx, err) 208 208 return ··· 262 262 // "$ref": "#/responses/notFound" 263 263 264 264 id := ctx.ParamsInt64(":id") 265 - externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id) 265 + externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id) 266 266 if err != nil { 267 267 if asymkey_model.IsErrKeyNotExist(err) { 268 268 ctx.NotFound()
+2 -2
routers/common/markup.go
··· 65 65 meta := map[string]string{} 66 66 if repo != nil && repo.Repository != nil { 67 67 if mode == "comment" { 68 - meta = repo.Repository.ComposeMetas() 68 + meta = repo.Repository.ComposeMetas(ctx) 69 69 } else { 70 - meta = repo.Repository.ComposeDocumentMetas() 70 + meta = repo.Repository.ComposeDocumentMetas(ctx) 71 71 } 72 72 } 73 73 if mode != "comment" {
+1 -1
routers/init.go
··· 121 121 mustInit(cache.NewContext) 122 122 mustInit(feed_service.Init) 123 123 mustInit(uinotification.Init) 124 - mustInit(archiver.Init) 124 + mustInitCtx(ctx, archiver.Init) 125 125 126 126 highlight.NewContext() 127 127 external.RegisterRenderers()
+1 -1
routers/private/actions.go
··· 83 83 return ownerID, repoID, nil 84 84 } 85 85 86 - r, err := repo_model.GetRepositoryByName(u.ID, repoName) 86 + r, err := repo_model.GetRepositoryByName(ctx, u.ID, repoName) 87 87 if err != nil { 88 88 return ownerID, repoID, err 89 89 }
+5 -5
routers/private/hook_post_receive.go
··· 150 150 } 151 151 152 152 results = append(results, private.HookPostReceiveBranchResult{ 153 - Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), 153 + Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(ctx), 154 154 Create: false, 155 155 Branch: "", 156 156 URL: fmt.Sprintf("%s/pulls/%d", repo.HTMLURL(), pr.Index), ··· 179 179 }) 180 180 return 181 181 } 182 - if repo.BaseRepo.AllowsPulls() { 182 + if repo.BaseRepo.AllowsPulls(ctx) { 183 183 baseRepo = repo.BaseRepo 184 184 } 185 185 } 186 186 187 - if !baseRepo.AllowsPulls() { 187 + if !baseRepo.AllowsPulls(ctx) { 188 188 // We can stop there's no need to go any further 189 189 ctx.JSON(http.StatusOK, private.HookPostReceiveResult{ 190 190 RepoWasEmpty: wasEmpty, ··· 217 217 branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch) 218 218 } 219 219 results = append(results, private.HookPostReceiveBranchResult{ 220 - Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), 220 + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(ctx), 221 221 Create: true, 222 222 Branch: branch, 223 223 URL: fmt.Sprintf("%s/compare/%s...%s", baseRepo.HTMLURL(), util.PathEscapeSegments(baseRepo.DefaultBranch), util.PathEscapeSegments(branch)), 224 224 }) 225 225 } else { 226 226 results = append(results, private.HookPostReceiveBranchResult{ 227 - Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), 227 + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(ctx), 228 228 Create: false, 229 229 Branch: branch, 230 230 URL: fmt.Sprintf("%s/pulls/%d", baseRepo.HTMLURL(), pr.Index),
+1 -1
routers/private/key.go
··· 16 16 func UpdatePublicKeyInRepo(ctx *context.PrivateContext) { 17 17 keyID := ctx.ParamsInt64(":id") 18 18 repoID := ctx.ParamsInt64(":repoid") 19 - if err := asymkey_model.UpdatePublicKeyUpdated(keyID); err != nil { 19 + if err := asymkey_model.UpdatePublicKeyUpdated(ctx, keyID); err != nil { 20 20 ctx.JSON(http.StatusInternalServerError, private.Response{ 21 21 Err: err.Error(), 22 22 })
+3 -3
routers/private/serv.go
··· 33 33 } 34 34 results := private.KeyAndOwner{} 35 35 36 - key, err := asymkey_model.GetPublicKeyByID(keyID) 36 + key, err := asymkey_model.GetPublicKeyByID(ctx, keyID) 37 37 if err != nil { 38 38 if asymkey_model.IsErrKeyNotExist(err) { 39 39 ctx.JSON(http.StatusUnauthorized, private.Response{ ··· 132 132 133 133 // Now get the Repository and set the results section 134 134 repoExist := true 135 - repo, err := repo_model.GetRepositoryByName(owner.ID, results.RepoName) 135 + repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, results.RepoName) 136 136 if err != nil { 137 137 if repo_model.IsErrRepoNotExist(err) { 138 138 repoExist = false ··· 184 184 } 185 185 186 186 // Get the Public Key represented by the keyID 187 - key, err := asymkey_model.GetPublicKeyByID(keyID) 187 + key, err := asymkey_model.GetPublicKeyByID(ctx, keyID) 188 188 if err != nil { 189 189 if asymkey_model.IsErrKeyNotExist(err) { 190 190 ctx.JSON(http.StatusNotFound, private.Response{
+8 -8
routers/web/admin/auths.go
··· 48 48 ctx.Data["PageIsAdminAuthentications"] = true 49 49 50 50 var err error 51 - ctx.Data["Sources"], err = auth.Sources() 51 + ctx.Data["Sources"], err = auth.Sources(ctx) 52 52 if err != nil { 53 53 ctx.ServerError("auth.Sources", err) 54 54 return 55 55 } 56 56 57 - ctx.Data["Total"] = auth.CountSources() 57 + ctx.Data["Total"] = auth.CountSources(ctx) 58 58 ctx.HTML(http.StatusOK, tplAuths) 59 59 } 60 60 ··· 284 284 ctx.RenderWithErr(err.Error(), tplAuthNew, form) 285 285 return 286 286 } 287 - existing, err := auth.SourcesByType(auth.SSPI) 287 + existing, err := auth.SourcesByType(ctx, auth.SSPI) 288 288 if err != nil || len(existing) > 0 { 289 289 ctx.Data["Err_Type"] = true 290 290 ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_of_type_exist"), tplAuthNew, form) ··· 301 301 return 302 302 } 303 303 304 - if err := auth.CreateSource(&auth.Source{ 304 + if err := auth.CreateSource(ctx, &auth.Source{ 305 305 Type: auth.Type(form.Type), 306 306 Name: form.Name, 307 307 IsActive: form.IsActive, ··· 337 337 oauth2providers := oauth2.GetOAuth2Providers() 338 338 ctx.Data["OAuth2Providers"] = oauth2providers 339 339 340 - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) 340 + source, err := auth.GetSourceByID(ctx, ctx.ParamsInt64(":authid")) 341 341 if err != nil { 342 342 ctx.ServerError("auth.GetSourceByID", err) 343 343 return ··· 371 371 oauth2providers := oauth2.GetOAuth2Providers() 372 372 ctx.Data["OAuth2Providers"] = oauth2providers 373 373 374 - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) 374 + source, err := auth.GetSourceByID(ctx, ctx.ParamsInt64(":authid")) 375 375 if err != nil { 376 376 ctx.ServerError("auth.GetSourceByID", err) 377 377 return ··· 421 421 source.IsActive = form.IsActive 422 422 source.IsSyncEnabled = form.IsSyncEnabled 423 423 source.Cfg = config 424 - if err := auth.UpdateSource(source); err != nil { 424 + if err := auth.UpdateSource(ctx, source); err != nil { 425 425 if auth.IsErrSourceAlreadyExist(err) { 426 426 ctx.Data["Err_Name"] = true 427 427 ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(auth.ErrSourceAlreadyExist).Name), tplAuthEdit, form) ··· 442 442 443 443 // DeleteAuthSource response for deleting an auth source 444 444 func DeleteAuthSource(ctx *context.Context) { 445 - source, err := auth.GetSourceByID(ctx.ParamsInt64(":authid")) 445 + source, err := auth.GetSourceByID(ctx, ctx.ParamsInt64(":authid")) 446 446 if err != nil { 447 447 ctx.ServerError("auth.GetSourceByID", err) 448 448 return
+5 -5
routers/web/admin/users.go
··· 90 90 91 91 ctx.Data["login_type"] = "0-0" 92 92 93 - sources, err := auth.Sources() 93 + sources, err := auth.Sources(ctx) 94 94 if err != nil { 95 95 ctx.ServerError("auth.Sources", err) 96 96 return ··· 109 109 ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode 110 110 ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() 111 111 112 - sources, err := auth.Sources() 112 + sources, err := auth.Sources(ctx) 113 113 if err != nil { 114 114 ctx.ServerError("auth.Sources", err) 115 115 return ··· 221 221 ctx.Data["User"] = u 222 222 223 223 if u.LoginSource > 0 { 224 - ctx.Data["LoginSource"], err = auth.GetSourceByID(u.LoginSource) 224 + ctx.Data["LoginSource"], err = auth.GetSourceByID(ctx, u.LoginSource) 225 225 if err != nil { 226 226 ctx.ServerError("auth.GetSourceByID", err) 227 227 return nil ··· 230 230 ctx.Data["LoginSource"] = &auth.Source{} 231 231 } 232 232 233 - sources, err := auth.Sources() 233 + sources, err := auth.Sources(ctx) 234 234 if err != nil { 235 235 ctx.ServerError("auth.Sources", err) 236 236 return nil ··· 532 532 return 533 533 } 534 534 535 - if err := user_service.DeleteAvatar(u); err != nil { 535 + if err := user_service.DeleteAvatar(ctx, u); err != nil { 536 536 ctx.Flash.Error(err.Error()) 537 537 } 538 538
+2 -2
routers/web/auth/auth.go
··· 157 157 ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login" 158 158 ctx.Data["PageIsSignIn"] = true 159 159 ctx.Data["PageIsLogin"] = true 160 - ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled() 160 + ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled(ctx) 161 161 162 162 if setting.Service.EnableCaptcha && setting.Service.RequireCaptchaForLogin { 163 163 context.SetCaptchaData(ctx) ··· 181 181 ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login" 182 182 ctx.Data["PageIsSignIn"] = true 183 183 ctx.Data["PageIsLogin"] = true 184 - ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled() 184 + ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled(ctx) 185 185 186 186 if ctx.HasError() { 187 187 ctx.HTML(http.StatusOK, tplSignIn)
+1 -1
routers/web/auth/linkaccount.go
··· 152 152 } 153 153 154 154 func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, remember bool) { 155 - updateAvatarIfNeed(gothUser.AvatarURL, u) 155 + updateAvatarIfNeed(ctx, gothUser.AvatarURL, u) 156 156 157 157 // If this user is enrolled in 2FA, we can't sign the user in just yet. 158 158 // Instead, redirect them to the 2FA authentication page.
+3 -3
routers/web/auth/oauth.go
··· 1074 1074 ctx.Redirect(setting.AppSubURL + "/user/link_account") 1075 1075 } 1076 1076 1077 - func updateAvatarIfNeed(url string, u *user_model.User) { 1077 + func updateAvatarIfNeed(ctx *context.Context, url string, u *user_model.User) { 1078 1078 if setting.OAuth2Client.UpdateAvatar && len(url) > 0 { 1079 1079 resp, err := http.Get(url) 1080 1080 if err == nil { ··· 1086 1086 if err == nil && resp.StatusCode == http.StatusOK { 1087 1087 data, err := io.ReadAll(io.LimitReader(resp.Body, setting.Avatar.MaxFileSize+1)) 1088 1088 if err == nil && int64(len(data)) <= setting.Avatar.MaxFileSize { 1089 - _ = user_service.UploadAvatar(u, data) 1089 + _ = user_service.UploadAvatar(ctx, u, data) 1090 1090 } 1091 1091 } 1092 1092 } 1093 1093 } 1094 1094 1095 1095 func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model.User, gothUser goth.User) { 1096 - updateAvatarIfNeed(gothUser.AvatarURL, u) 1096 + updateAvatarIfNeed(ctx, gothUser.AvatarURL, u) 1097 1097 1098 1098 needs2FA := false 1099 1099 if !source.Cfg.(*oauth2.Source).SkipLocalTwoFA {
+1 -1
routers/web/explore/code.go
··· 102 102 } 103 103 } 104 104 105 - repoMaps, err := repo_model.GetRepositoriesMapByIDs(loadRepoIDs) 105 + repoMaps, err := repo_model.GetRepositoriesMapByIDs(ctx, loadRepoIDs) 106 106 if err != nil { 107 107 ctx.ServerError("GetRepositoriesMapByIDs", err) 108 108 return
+1 -1
routers/web/feed/convert.go
··· 290 290 content, err = markdown.RenderString(&markup.RenderContext{ 291 291 Ctx: ctx, 292 292 URLPrefix: rel.Repo.Link(), 293 - Metas: rel.Repo.ComposeMetas(), 293 + Metas: rel.Repo.ComposeMetas(ctx), 294 294 }, rel.Note) 295 295 296 296 if err != nil {
+1 -1
routers/web/org/projects.go
··· 468 468 } 469 469 } 470 470 471 - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { 471 + if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID); err != nil { 472 472 ctx.ServerError("ChangeProjectAssign", err) 473 473 return 474 474 }
+1 -1
routers/web/org/setting.go
··· 160 160 161 161 // SettingsDeleteAvatar response for delete avatar on settings page 162 162 func SettingsDeleteAvatar(ctx *context.Context) { 163 - if err := user_service.DeleteAvatar(ctx.Org.Organization.AsUser()); err != nil { 163 + if err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser()); err != nil { 164 164 ctx.Flash.Error(err.Error()) 165 165 } 166 166
+1 -1
routers/web/org/teams.go
··· 237 237 case "add": 238 238 repoName := path.Base(ctx.FormString("repo_name")) 239 239 var repo *repo_model.Repository 240 - repo, err = repo_model.GetRepositoryByName(ctx.Org.Organization.ID, repoName) 240 + repo, err = repo_model.GetRepositoryByName(ctx, ctx.Org.Organization.ID, repoName) 241 241 if err != nil { 242 242 if repo_model.IsErrRepoNotExist(err) { 243 243 ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo"))
+1 -1
routers/web/repo/branch.go
··· 37 37 func Branches(ctx *context.Context) { 38 38 ctx.Data["Title"] = "Branches" 39 39 ctx.Data["IsRepoToolbarBranches"] = true 40 - ctx.Data["AllowsPulls"] = ctx.Repo.Repository.AllowsPulls() 40 + ctx.Data["AllowsPulls"] = ctx.Repo.Repository.AllowsPulls(ctx) 41 41 ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode) 42 42 ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror 43 43 ctx.Data["CanPull"] = ctx.Repo.CanWrite(unit.TypeCode) ||
+1 -1
routers/web/repo/http.go
··· 105 105 } 106 106 107 107 repoExist := true 108 - repo, err := repo_model.GetRepositoryByName(owner.ID, reponame) 108 + repo, err := repo_model.GetRepositoryByName(ctx, owner.ID, reponame) 109 109 if err != nil { 110 110 if repo_model.IsErrRepoNotExist(err) { 111 111 if redirectRepoID, err := repo_model.LookupRedirect(owner.ID, reponame); err == nil {
+13 -13
routers/web/repo/issue.go
··· 495 495 496 496 func renderMilestones(ctx *context.Context) { 497 497 // Get milestones 498 - milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ 498 + milestones, _, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ 499 499 RepoID: ctx.Repo.Repository.ID, 500 500 State: api.StateAll, 501 501 }) ··· 519 519 // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository 520 520 func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.Repository) { 521 521 var err error 522 - ctx.Data["OpenMilestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{ 522 + ctx.Data["OpenMilestones"], _, err = issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ 523 523 RepoID: repo.ID, 524 524 State: api.StateOpen, 525 525 }) ··· 527 527 ctx.ServerError("GetMilestones", err) 528 528 return 529 529 } 530 - ctx.Data["ClosedMilestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{ 530 + ctx.Data["ClosedMilestones"], _, err = issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ 531 531 RepoID: repo.ID, 532 532 State: api.StateClosed, 533 533 }) ··· 1229 1229 ctx.Error(http.StatusBadRequest, "user hasn't permissions to read projects") 1230 1230 return 1231 1231 } 1232 - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { 1232 + if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID); err != nil { 1233 1233 ctx.ServerError("ChangeProjectAssign", err) 1234 1234 return 1235 1235 } ··· 1332 1332 extIssueUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit.TypeExternalTracker) 1333 1333 if err == nil && extIssueUnit != nil { 1334 1334 if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" { 1335 - metas := ctx.Repo.Repository.ComposeMetas() 1335 + metas := ctx.Repo.Repository.ComposeMetas(ctx) 1336 1336 metas["index"] = ctx.Params(":index") 1337 1337 res, err := vars.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas) 1338 1338 if err != nil { ··· 1425 1425 1426 1426 issue.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 1427 1427 URLPrefix: ctx.Repo.RepoLink, 1428 - Metas: ctx.Repo.Repository.ComposeMetas(), 1428 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 1429 1429 GitRepo: ctx.Repo.GitRepo, 1430 1430 Ctx: ctx, 1431 1431 }, issue.Content) ··· 1588 1588 1589 1589 comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 1590 1590 URLPrefix: ctx.Repo.RepoLink, 1591 - Metas: ctx.Repo.Repository.ComposeMetas(), 1591 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 1592 1592 GitRepo: ctx.Repo.GitRepo, 1593 1593 Ctx: ctx, 1594 1594 }, comment.Content) ··· 1665 1665 } else if comment.Type.HasContentSupport() { 1666 1666 comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 1667 1667 URLPrefix: ctx.Repo.RepoLink, 1668 - Metas: ctx.Repo.Repository.ComposeMetas(), 1668 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 1669 1669 GitRepo: ctx.Repo.GitRepo, 1670 1670 Ctx: ctx, 1671 1671 }, comment.Content) ··· 1909 1909 if pull.HasMerged || issue.IsClosed || !ctx.IsSigned { 1910 1910 return false 1911 1911 } 1912 - if pull.CanAutoMerge() || pull.IsWorkInProgress() || pull.IsChecking() { 1912 + if pull.CanAutoMerge() || pull.IsWorkInProgress(ctx) || pull.IsChecking() { 1913 1913 return false 1914 1914 } 1915 1915 if (ctx.Doer.IsAdmin || ctx.Repo.IsAdmin()) && prConfig.AllowManualMerge { ··· 2223 2223 2224 2224 content, err := markdown.RenderString(&markup.RenderContext{ 2225 2225 URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? 2226 - Metas: ctx.Repo.Repository.ComposeMetas(), 2226 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 2227 2227 GitRepo: ctx.Repo.GitRepo, 2228 2228 Ctx: ctx, 2229 2229 }, issue.Content) ··· 2286 2286 continue 2287 2287 } 2288 2288 issue.MilestoneID = milestoneID 2289 - if err := issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil { 2289 + if err := issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil { 2290 2290 ctx.ServerError("ChangeMilestoneAssign", err) 2291 2291 return 2292 2292 } ··· 2536 2536 allPublic = true 2537 2537 opts.AllPublic = false // set it false to avoid returning too many repos, we could filter by indexer 2538 2538 } 2539 - repoIDs, _, err = repo_model.SearchRepositoryIDs(opts) 2539 + repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts) 2540 2540 if err != nil { 2541 2541 ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err.Error()) 2542 2542 return ··· 3127 3127 3128 3128 content, err := markdown.RenderString(&markup.RenderContext{ 3129 3129 URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? 3130 - Metas: ctx.Repo.Repository.ComposeMetas(), 3130 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 3131 3131 GitRepo: ctx.Repo.GitRepo, 3132 3132 Ctx: ctx, 3133 3133 }, comment.Content)
+2 -2
routers/web/repo/issue_dependency.go
··· 72 72 return 73 73 } 74 74 75 - err = issues_model.CreateIssueDependency(ctx.Doer, issue, dep) 75 + err = issues_model.CreateIssueDependency(ctx, ctx.Doer, issue, dep) 76 76 if err != nil { 77 77 if issues_model.IsErrDependencyExists(err) { 78 78 ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists")) ··· 131 131 return 132 132 } 133 133 134 - if err = issues_model.RemoveIssueDependency(ctx.Doer, issue, dep, depType); err != nil { 134 + if err = issues_model.RemoveIssueDependency(ctx, ctx.Doer, issue, dep, depType); err != nil { 135 135 if issues_model.IsErrDependencyNotExists(err) { 136 136 ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist")) 137 137 return
+2 -2
routers/web/repo/issue_lock.go
··· 29 29 return 30 30 } 31 31 32 - if err := issues_model.LockIssue(&issues_model.IssueLockOptions{ 32 + if err := issues_model.LockIssue(ctx, &issues_model.IssueLockOptions{ 33 33 Doer: ctx.Doer, 34 34 Issue: issue, 35 35 Reason: form.Reason, ··· 53 53 return 54 54 } 55 55 56 - if err := issues_model.UnlockIssue(&issues_model.IssueLockOptions{ 56 + if err := issues_model.UnlockIssue(ctx, &issues_model.IssueLockOptions{ 57 57 Doer: ctx.Doer, 58 58 Issue: issue, 59 59 }); err != nil {
+3 -3
routers/web/repo/milestone.go
··· 50 50 state = structs.StateClosed 51 51 } 52 52 53 - miles, total, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ 53 + miles, total, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{ 54 54 ListOptions: db.ListOptions{ 55 55 Page: page, 56 56 PageSize: setting.UI.IssuePagingNum, ··· 82 82 for _, m := range miles { 83 83 m.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 84 84 URLPrefix: ctx.Repo.RepoLink, 85 - Metas: ctx.Repo.Repository.ComposeMetas(), 85 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 86 86 GitRepo: ctx.Repo.GitRepo, 87 87 Ctx: ctx, 88 88 }, m.Content) ··· 275 275 276 276 milestone.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 277 277 URLPrefix: ctx.Repo.RepoLink, 278 - Metas: ctx.Repo.Repository.ComposeMetas(), 278 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 279 279 GitRepo: ctx.Repo.GitRepo, 280 280 Ctx: ctx, 281 281 }, milestone.Content)
+3 -3
routers/web/repo/projects.go
··· 87 87 for i := range projects { 88 88 projects[i].RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 89 89 URLPrefix: ctx.Repo.RepoLink, 90 - Metas: ctx.Repo.Repository.ComposeMetas(), 90 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 91 91 GitRepo: ctx.Repo.GitRepo, 92 92 Ctx: ctx, 93 93 }, projects[i].Description) ··· 353 353 354 354 project.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 355 355 URLPrefix: ctx.Repo.RepoLink, 356 - Metas: ctx.Repo.Repository.ComposeMetas(), 356 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 357 357 GitRepo: ctx.Repo.GitRepo, 358 358 Ctx: ctx, 359 359 }, project.Description) ··· 391 391 } 392 392 } 393 393 394 - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { 394 + if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID); err != nil { 395 395 ctx.ServerError("ChangeProjectAssign", err) 396 396 return 397 397 }
+3 -3
routers/web/repo/pull.go
··· 371 371 ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch 372 372 } 373 373 ctx.Data["BaseTarget"] = pull.BaseBranch 374 - ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink() 375 - ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink() 374 + ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx) 375 + ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx) 376 376 } 377 377 378 378 // GetPullDiffStats get Pull Requests diff stats ··· 696 696 ctx.Data["IsNothingToCompare"] = true 697 697 } 698 698 699 - if pull.IsWorkInProgress() { 699 + if pull.IsWorkInProgress(ctx) { 700 700 ctx.Data["IsPullWorkInProgress"] = true 701 701 ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix(ctx) 702 702 }
+2 -2
routers/web/repo/release.go
··· 136 136 137 137 r.Note, err = markdown.RenderString(&markup.RenderContext{ 138 138 URLPrefix: ctx.Repo.RepoLink, 139 - Metas: ctx.Repo.Repository.ComposeMetas(), 139 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 140 140 GitRepo: ctx.Repo.GitRepo, 141 141 Ctx: ctx, 142 142 }, r.Note) ··· 285 285 } 286 286 release.Note, err = markdown.RenderString(&markup.RenderContext{ 287 287 URLPrefix: ctx.Repo.RepoLink, 288 - Metas: ctx.Repo.Repository.ComposeMetas(), 288 + Metas: ctx.Repo.Repository.ComposeMetas(ctx), 289 289 GitRepo: ctx.Repo.GitRepo, 290 290 Ctx: ctx, 291 291 }, release.Note)
+1 -1
routers/web/repo/render.go
··· 67 67 Ctx: ctx, 68 68 RelativePath: ctx.Repo.TreePath, 69 69 URLPrefix: path.Dir(treeLink), 70 - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), 70 + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), 71 71 GitRepo: ctx.Repo.GitRepo, 72 72 InStandalonePage: true, 73 73 }, rd, ctx.Resp)
+4 -4
routers/web/repo/view.go
··· 312 312 Ctx: ctx, 313 313 RelativePath: path.Join(ctx.Repo.TreePath, readmeFile.Name()), // ctx.Repo.TreePath is the directory not the Readme so we must append the Readme filename (and path). 314 314 URLPrefix: path.Join(readmeTreelink, subfolder), 315 - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), 315 + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), 316 316 GitRepo: ctx.Repo.GitRepo, 317 317 }, rd) 318 318 if err != nil { ··· 469 469 if !detected { 470 470 markupType = "" 471 471 } 472 - metas := ctx.Repo.Repository.ComposeDocumentMetas() 472 + metas := ctx.Repo.Repository.ComposeDocumentMetas(ctx) 473 473 metas["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL() 474 474 ctx.Data["EscapeStatus"], ctx.Data["FileContent"], err = markupRender(ctx, &markup.RenderContext{ 475 475 Ctx: ctx, ··· 582 582 Ctx: ctx, 583 583 RelativePath: ctx.Repo.TreePath, 584 584 URLPrefix: path.Dir(treeLink), 585 - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), 585 + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), 586 586 GitRepo: ctx.Repo.GitRepo, 587 587 }, rd) 588 588 if err != nil { ··· 879 879 } 880 880 881 881 func renderLanguageStats(ctx *context.Context) { 882 - langs, err := repo_model.GetTopLanguageStats(ctx.Repo.Repository, 5) 882 + langs, err := repo_model.GetTopLanguageStats(ctx, ctx.Repo.Repository, 5) 883 883 if err != nil { 884 884 ctx.ServerError("Repo.GetTopLanguageStats", err) 885 885 return
+1 -1
routers/web/repo/wiki.go
··· 240 240 rctx := &markup.RenderContext{ 241 241 Ctx: ctx, 242 242 URLPrefix: ctx.Repo.RepoLink, 243 - Metas: ctx.Repo.Repository.ComposeDocumentMetas(), 243 + Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx), 244 244 IsWiki: true, 245 245 } 246 246 buf := &strings.Builder{}
+1 -1
routers/web/shared/user/header.go
··· 85 85 } 86 86 87 87 func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) { 88 - profileDbRepo, err := repo_model.GetRepositoryByName(ctx.ContextUser.ID, ".profile") 88 + profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ".profile") 89 89 if err == nil && !profileDbRepo.IsEmpty && !profileDbRepo.IsPrivate { 90 90 if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil { 91 91 log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
+1 -1
routers/web/user/code.go
··· 100 100 } 101 101 } 102 102 103 - repoMaps, err := repo_model.GetRepositoriesMapByIDs(loadRepoIDs) 103 + repoMaps, err := repo_model.GetRepositoriesMapByIDs(ctx, loadRepoIDs) 104 104 if err != nil { 105 105 ctx.ServerError("GetRepositoriesMapByIDs", err) 106 106 return
+7 -7
routers/web/user/home.go
··· 247 247 248 248 milestones[i].RenderedContent, err = markdown.RenderString(&markup.RenderContext{ 249 249 URLPrefix: milestones[i].Repo.Link(), 250 - Metas: milestones[i].Repo.ComposeMetas(), 250 + Metas: milestones[i].Repo.ComposeMetas(ctx), 251 251 Ctx: ctx, 252 252 }, milestones[i].Content) 253 253 if err != nil { ··· 463 463 } 464 464 accessibleRepos := container.Set[int64]{} 465 465 { 466 - ids, _, err := repo_model.SearchRepositoryIDs(repoOpts) 466 + ids, _, err := repo_model.SearchRepositoryIDs(ctx, repoOpts) 467 467 if err != nil { 468 468 ctx.ServerError("SearchRepositoryIDs", err) 469 469 return ··· 576 576 } 577 577 578 578 // showReposMap maps repository IDs to their Repository pointers. 579 - showReposMap, err := loadRepoByIDs(ctxUser, issueCountByRepo, unitType) 579 + showReposMap, err := loadRepoByIDs(ctx, ctxUser, issueCountByRepo, unitType) 580 580 if err != nil { 581 581 if repo_model.IsErrRepoNotExist(err) { 582 582 ctx.NotFound("GetRepositoryByID", err) ··· 734 734 return repoIDs 735 735 } 736 736 737 - func loadRepoByIDs(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*repo_model.Repository, error) { 737 + func loadRepoByIDs(ctx *context.Context, ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*repo_model.Repository, error) { 738 738 totalRes := make(map[int64]*repo_model.Repository, len(issueCountByRepo)) 739 739 repoIDs := make([]int64, 0, 500) 740 740 for id := range issueCountByRepo { ··· 743 743 } 744 744 repoIDs = append(repoIDs, id) 745 745 if len(repoIDs) == 500 { 746 - if err := repo_model.FindReposMapByIDs(repoIDs, totalRes); err != nil { 746 + if err := repo_model.FindReposMapByIDs(ctx, repoIDs, totalRes); err != nil { 747 747 return nil, err 748 748 } 749 749 repoIDs = repoIDs[:0] 750 750 } 751 751 } 752 752 if len(repoIDs) > 0 { 753 - if err := repo_model.FindReposMapByIDs(repoIDs, totalRes); err != nil { 753 + if err := repo_model.FindReposMapByIDs(ctx, repoIDs, totalRes); err != nil { 754 754 return nil, err 755 755 } 756 756 } ··· 759 759 760 760 // ShowSSHKeys output all the ssh keys of user by uid 761 761 func ShowSSHKeys(ctx *context.Context) { 762 - keys, err := asymkey_model.ListPublicKeys(ctx.ContextUser.ID, db.ListOptions{}) 762 + keys, err := asymkey_model.ListPublicKeys(ctx, ctx.ContextUser.ID, db.ListOptions{}) 763 763 if err != nil { 764 764 ctx.ServerError("ListPublicKeys", err) 765 765 return
+4 -4
routers/web/user/setting/keys.go
··· 168 168 return 169 169 } 170 170 171 - if _, err = asymkey_model.AddPublicKey(ctx.Doer.ID, form.Title, content, 0); err != nil { 171 + if _, err = asymkey_model.AddPublicKey(ctx, ctx.Doer.ID, form.Title, content, 0); err != nil { 172 172 ctx.Data["HasSSHError"] = true 173 173 switch { 174 174 case asymkey_model.IsErrKeyAlreadyExist(err): ··· 231 231 } 232 232 case "ssh": 233 233 keyID := ctx.FormInt64("id") 234 - external, err := asymkey_model.PublicKeyIsExternallyManaged(keyID) 234 + external, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, keyID) 235 235 if err != nil { 236 236 ctx.ServerError("sshKeysExternalManaged", err) 237 237 return ··· 260 260 } 261 261 262 262 func loadKeysData(ctx *context.Context) { 263 - keys, err := asymkey_model.ListPublicKeys(ctx.Doer.ID, db.ListOptions{}) 263 + keys, err := asymkey_model.ListPublicKeys(ctx, ctx.Doer.ID, db.ListOptions{}) 264 264 if err != nil { 265 265 ctx.ServerError("ListPublicKeys", err) 266 266 return 267 267 } 268 268 ctx.Data["Keys"] = keys 269 269 270 - externalKeys, err := asymkey_model.PublicKeysAreExternallyManaged(keys) 270 + externalKeys, err := asymkey_model.PublicKeysAreExternallyManaged(ctx, keys) 271 271 if err != nil { 272 272 ctx.ServerError("ListPublicKeys", err) 273 273 return
+2 -2
routers/web/user/setting/profile.go
··· 157 157 if !(st.IsImage() && !st.IsSvgImage()) { 158 158 return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) 159 159 } 160 - if err = user_service.UploadAvatar(ctxUser, data); err != nil { 160 + if err = user_service.UploadAvatar(ctx, ctxUser, data); err != nil { 161 161 return fmt.Errorf("UploadAvatar: %w", err) 162 162 } 163 163 } else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" { ··· 189 189 190 190 // DeleteAvatar render delete avatar page 191 191 func DeleteAvatar(ctx *context.Context) { 192 - if err := user_service.DeleteAvatar(ctx.Doer); err != nil { 192 + if err := user_service.DeleteAvatar(ctx, ctx.Doer); err != nil { 193 193 ctx.Flash.Error(err.Error()) 194 194 } 195 195
+1 -1
routers/web/user/setting/security/security.go
··· 82 82 // map the provider display name with the AuthSource 83 83 sources := make(map[*auth_model.Source]string) 84 84 for _, externalAccount := range accountLinks { 85 - if authSource, err := auth_model.GetSourceByID(externalAccount.LoginSourceID); err == nil { 85 + if authSource, err := auth_model.GetSourceByID(ctx, externalAccount.LoginSourceID); err == nil { 86 86 var providerDisplayName string 87 87 88 88 type DisplayNamed interface {
+2 -1
routers/web/web.go
··· 9 9 "strings" 10 10 11 11 auth_model "code.gitea.io/gitea/models/auth" 12 + "code.gitea.io/gitea/models/db" 12 13 "code.gitea.io/gitea/models/perm" 13 14 "code.gitea.io/gitea/models/unit" 14 15 "code.gitea.io/gitea/modules/context" ··· 94 95 group.Add(&auth_service.ReverseProxy{}) 95 96 } 96 97 97 - if setting.IsWindows && auth_model.IsSSPIEnabled() { 98 + if setting.IsWindows && auth_model.IsSSPIEnabled(db.DefaultContext) { 98 99 group.Add(&auth_service.SSPI{}) // it MUST be the last, see the comment of SSPI 99 100 } 100 101
+1 -1
services/actions/schedule_tasks.go
··· 45 45 return fmt.Errorf("find specs: %w", err) 46 46 } 47 47 48 - if err := specs.LoadRepos(); err != nil { 48 + if err := specs.LoadRepos(ctx); err != nil { 49 49 return fmt.Errorf("LoadRepos: %w", err) 50 50 } 51 51
+1 -1
services/agit/agit.go
··· 237 237 for _, pull := range pulls { 238 238 pull.HeadBranch = strings.TrimPrefix(pull.HeadBranch, user.LowerName+"/") 239 239 pull.HeadBranch = newName + "/" + pull.HeadBranch 240 - if err = pull.UpdateCols("head_branch"); err != nil { 240 + if err = pull.UpdateCols(ctx, "head_branch"); err != nil { 241 241 return err 242 242 } 243 243 }
+1 -1
services/asymkey/ssh_key.go
··· 13 13 14 14 // DeletePublicKey deletes SSH key information both in database and authorized_keys file. 15 15 func DeletePublicKey(ctx context.Context, doer *user_model.User, id int64) (err error) { 16 - key, err := asymkey_model.GetPublicKeyByID(id) 16 + key, err := asymkey_model.GetPublicKeyByID(ctx, id) 17 17 if err != nil { 18 18 return err 19 19 }
+2 -2
services/asymkey/ssh_key_test.go
··· 66 66 67 67 for i, kase := range testCases { 68 68 s.ID = int64(i) + 20 69 - asymkey_model.AddPublicKeysBySource(user, s, []string{kase.keyString}) 70 - keys, err := asymkey_model.ListPublicKeysBySource(user.ID, s.ID) 69 + asymkey_model.AddPublicKeysBySource(db.DefaultContext, user, s, []string{kase.keyString}) 70 + keys, err := asymkey_model.ListPublicKeysBySource(db.DefaultContext, user.ID, s.ID) 71 71 assert.NoError(t, err) 72 72 if err != nil { 73 73 continue
+1 -1
services/auth/httpsign.go
··· 92 92 93 93 keyID := verifier.KeyId() 94 94 95 - publicKeys, err := asymkey_model.SearchPublicKey(0, keyID) 95 + publicKeys, err := asymkey_model.SearchPublicKey(r.Context(), 0, keyID) 96 96 if err != nil { 97 97 return nil, err 98 98 }
+2 -2
services/auth/signin.go
··· 56 56 } 57 57 58 58 if hasUser { 59 - source, err := auth.GetSourceByID(user.LoginSource) 59 + source, err := auth.GetSourceByID(ctx, user.LoginSource) 60 60 if err != nil { 61 61 return nil, nil, err 62 62 } ··· 85 85 } 86 86 } 87 87 88 - sources, err := auth.AllActiveSources() 88 + sources, err := auth.AllActiveSources(ctx) 89 89 if err != nil { 90 90 return nil, nil, err 91 91 }
+3 -3
services/auth/source/ldap/source_authenticate.go
··· 70 70 } 71 71 72 72 if user != nil { 73 - if isAttributeSSHPublicKeySet && asymkey_model.SynchronizePublicKeys(user, source.authSource, sr.SSHPublicKey) { 73 + if isAttributeSSHPublicKeySet && asymkey_model.SynchronizePublicKeys(ctx, user, source.authSource, sr.SSHPublicKey) { 74 74 if err := asymkey_model.RewriteAllPublicKeys(ctx); err != nil { 75 75 return user, err 76 76 } ··· 96 96 return user, err 97 97 } 98 98 99 - if isAttributeSSHPublicKeySet && asymkey_model.AddPublicKeysBySource(user, source.authSource, sr.SSHPublicKey) { 99 + if isAttributeSSHPublicKeySet && asymkey_model.AddPublicKeysBySource(ctx, user, source.authSource, sr.SSHPublicKey) { 100 100 if err := asymkey_model.RewriteAllPublicKeys(ctx); err != nil { 101 101 return user, err 102 102 } 103 103 } 104 104 if len(source.AttributeAvatar) > 0 { 105 - if err := user_service.UploadAvatar(user, sr.Avatar); err != nil { 105 + if err := user_service.UploadAvatar(ctx, user, sr.Avatar); err != nil { 106 106 return user, err 107 107 } 108 108 }
+4 -4
services/auth/source/ldap/source_sync.go
··· 135 135 136 136 if err == nil && isAttributeSSHPublicKeySet { 137 137 log.Trace("SyncExternalUsers[%s]: Adding LDAP Public SSH Keys for user %s", source.authSource.Name, usr.Name) 138 - if asymkey_model.AddPublicKeysBySource(usr, source.authSource, su.SSHPublicKey) { 138 + if asymkey_model.AddPublicKeysBySource(ctx, usr, source.authSource, su.SSHPublicKey) { 139 139 sshKeysNeedUpdate = true 140 140 } 141 141 } 142 142 143 143 if err == nil && len(source.AttributeAvatar) > 0 { 144 - _ = user_service.UploadAvatar(usr, su.Avatar) 144 + _ = user_service.UploadAvatar(ctx, usr, su.Avatar) 145 145 } 146 146 } else if updateExisting { 147 147 // Synchronize SSH Public Key if that attribute is set 148 - if isAttributeSSHPublicKeySet && asymkey_model.SynchronizePublicKeys(usr, source.authSource, su.SSHPublicKey) { 148 + if isAttributeSSHPublicKeySet && asymkey_model.SynchronizePublicKeys(ctx, usr, source.authSource, su.SSHPublicKey) { 149 149 sshKeysNeedUpdate = true 150 150 } 151 151 ··· 179 179 180 180 if usr.IsUploadAvatarChanged(su.Avatar) { 181 181 if err == nil && len(source.AttributeAvatar) > 0 { 182 - _ = user_service.UploadAvatar(usr, su.Avatar) 182 + _ = user_service.UploadAvatar(ctx, usr, su.Avatar) 183 183 } 184 184 } 185 185 }
+3 -3
services/auth/sspi.go
··· 67 67 return nil, nil 68 68 } 69 69 70 - cfg, err := s.getConfig() 70 + cfg, err := s.getConfig(req.Context()) 71 71 if err != nil { 72 72 log.Error("could not get SSPI config: %v", err) 73 73 return nil, err ··· 129 129 } 130 130 131 131 // getConfig retrieves the SSPI configuration from login sources 132 - func (s *SSPI) getConfig() (*sspi.Source, error) { 133 - sources, err := auth.ActiveSources(auth.SSPI) 132 + func (s *SSPI) getConfig(ctx context.Context) (*sspi.Source, error) { 133 + sources, err := auth.ActiveSources(ctx, auth.SSPI) 134 134 if err != nil { 135 135 return nil, err 136 136 }
+1 -1
services/auth/sync.go
··· 15 15 func SyncExternalUsers(ctx context.Context, updateExisting bool) error { 16 16 log.Trace("Doing: SyncExternalUsers") 17 17 18 - ls, err := auth.Sources() 18 + ls, err := auth.Sources(ctx) 19 19 if err != nil { 20 20 log.Error("SyncExternalUsers: %v", err) 21 21 return err
+1 -1
services/convert/pull.go
··· 68 68 PatchURL: pr.Issue.PatchURL(), 69 69 HasMerged: pr.HasMerged, 70 70 MergeBase: pr.MergeBase, 71 - Mergeable: pr.Mergeable(), 71 + Mergeable: pr.Mergeable(ctx), 72 72 Deadline: apiIssue.Deadline, 73 73 Created: pr.Issue.CreatedUnix.AsTimePtr(), 74 74 Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
+1 -1
services/issue/issue_test.go
··· 72 72 assert.NoError(t, err) 73 73 issue2, err := issues_model.GetIssueByID(db.DefaultContext, 2) 74 74 assert.NoError(t, err) 75 - err = issues_model.CreateIssueDependency(user, issue1, issue2) 75 + err = issues_model.CreateIssueDependency(db.DefaultContext, user, issue1, issue2) 76 76 assert.NoError(t, err) 77 77 left, err := issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1) 78 78 assert.NoError(t, err)
+4 -4
services/issue/label.go
··· 15 15 16 16 // ClearLabels clears all of an issue's labels 17 17 func ClearLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User) error { 18 - if err := issues_model.ClearIssueLabels(issue, doer); err != nil { 18 + if err := issues_model.ClearIssueLabels(ctx, issue, doer); err != nil { 19 19 return err 20 20 } 21 21 ··· 26 26 27 27 // AddLabel adds a new label to the issue. 28 28 func AddLabel(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error { 29 - if err := issues_model.NewIssueLabel(issue, label, doer); err != nil { 29 + if err := issues_model.NewIssueLabel(ctx, issue, label, doer); err != nil { 30 30 return err 31 31 } 32 32 ··· 36 36 37 37 // AddLabels adds a list of new labels to the issue. 38 38 func AddLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error { 39 - if err := issues_model.NewIssueLabels(issue, labels, doer); err != nil { 39 + if err := issues_model.NewIssueLabels(ctx, issue, labels, doer); err != nil { 40 40 return err 41 41 } 42 42 ··· 86 86 return err 87 87 } 88 88 89 - if err := issues_model.ReplaceIssueLabels(issue, labels, doer); err != nil { 89 + if err := issues_model.ReplaceIssueLabels(ctx, issue, labels, doer); err != nil { 90 90 return err 91 91 } 92 92
+4 -4
services/issue/milestone.go
··· 63 63 } 64 64 65 65 // ChangeMilestoneAssign changes assignment of milestone for issue. 66 - func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, oldMilestoneID int64) (err error) { 67 - ctx, committer, err := db.TxContext(db.DefaultContext) 66 + func ChangeMilestoneAssign(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, oldMilestoneID int64) (err error) { 67 + dbCtx, committer, err := db.TxContext(ctx) 68 68 if err != nil { 69 69 return err 70 70 } 71 71 defer committer.Close() 72 72 73 - if err = changeMilestoneAssign(ctx, doer, issue, oldMilestoneID); err != nil { 73 + if err = changeMilestoneAssign(dbCtx, doer, issue, oldMilestoneID); err != nil { 74 74 return err 75 75 } 76 76 ··· 78 78 return fmt.Errorf("Commit: %w", err) 79 79 } 80 80 81 - notify_service.IssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID) 81 + notify_service.IssueChangeMilestone(ctx, doer, issue, oldMilestoneID) 82 82 83 83 return nil 84 84 }
+2 -1
services/issue/milestone_test.go
··· 6 6 import ( 7 7 "testing" 8 8 9 + "code.gitea.io/gitea/models/db" 9 10 issues_model "code.gitea.io/gitea/models/issues" 10 11 "code.gitea.io/gitea/models/unittest" 11 12 user_model "code.gitea.io/gitea/models/user" ··· 22 23 23 24 oldMilestoneID := issue.MilestoneID 24 25 issue.MilestoneID = 2 25 - assert.NoError(t, ChangeMilestoneAssign(issue, doer, oldMilestoneID)) 26 + assert.NoError(t, ChangeMilestoneAssign(db.DefaultContext, issue, doer, oldMilestoneID)) 26 27 unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ 27 28 IssueID: issue.ID, 28 29 Type: issues_model.CommentTypeMilestone,
+1 -1
services/mailer/mail.go
··· 235 235 body, err := markdown.RenderString(&markup.RenderContext{ 236 236 Ctx: ctx, 237 237 URLPrefix: ctx.Issue.Repo.HTMLURL(), 238 - Metas: ctx.Issue.Repo.ComposeMetas(), 238 + Metas: ctx.Issue.Repo.ComposeMetas(ctx), 239 239 }, ctx.Content) 240 240 if err != nil { 241 241 return nil, err
+1 -1
services/mailer/mail_issue.go
··· 82 82 83 83 // =========== Repo watchers =========== 84 84 // Make repo watchers last, since it's likely the list with the most users 85 - if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress() && ctx.ActionType != activities_model.ActionCreatePullRequest) { 85 + if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress(ctx) && ctx.ActionType != activities_model.ActionCreatePullRequest) { 86 86 ids, err = repo_model.GetRepoWatchersIDs(ctx, ctx.Issue.RepoID) 87 87 if err != nil { 88 88 return fmt.Errorf("GetRepoWatchersIDs(%d): %w", ctx.Issue.RepoID, err)
+1 -1
services/mailer/mail_release.go
··· 60 60 rel.RenderedNote, err = markdown.RenderString(&markup.RenderContext{ 61 61 Ctx: ctx, 62 62 URLPrefix: rel.Repo.Link(), 63 - Metas: rel.Repo.ComposeMetas(), 63 + Metas: rel.Repo.ComposeMetas(ctx), 64 64 }, rel.Note) 65 65 if err != nil { 66 66 log.Error("markdown.RenderString(%d): %v", rel.RepoID, err)
+1 -1
services/mailer/notify.go
··· 79 79 log.Error("issue.LoadPullRequest: %v", err) 80 80 return 81 81 } 82 - if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress() { 82 + if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress(ctx) { 83 83 if err := MailParticipants(ctx, issue, doer, activities_model.ActionPullRequestReadyForReview, nil); err != nil { 84 84 log.Error("MailParticipants: %v", err) 85 85 }
+1 -1
services/migrations/gitea_uploader.go
··· 840 840 pr, ok := g.prCache[issue.ID] 841 841 if !ok { 842 842 var err error 843 - pr, err = issues_model.GetPullRequestByIssueIDWithNoAttributes(issue.ID) 843 + pr, err = issues_model.GetPullRequestByIssueIDWithNoAttributes(g.ctx, issue.ID) 844 844 if err != nil { 845 845 return err 846 846 }
+2 -2
services/migrations/gitea_uploader_test.go
··· 65 65 assert.True(t, repo.HasWiki()) 66 66 assert.EqualValues(t, repo_model.RepositoryReady, repo.Status) 67 67 68 - milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ 68 + milestones, _, err := issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{ 69 69 RepoID: repo.ID, 70 70 State: structs.StateOpen, 71 71 }) 72 72 assert.NoError(t, err) 73 73 assert.Len(t, milestones, 1) 74 74 75 - milestones, _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{ 75 + milestones, _, err = issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{ 76 76 RepoID: repo.ID, 77 77 State: structs.StateClosed, 78 78 })
+2 -2
services/pull/check.go
··· 91 91 return nil 92 92 } 93 93 94 - if pr.IsWorkInProgress() { 94 + if pr.IsWorkInProgress(ctx) { 95 95 return ErrIsWorkInProgress 96 96 } 97 97 ··· 360 360 if err := TestPatch(pr); err != nil { 361 361 log.Error("testPatch[%-v]: %v", pr, err) 362 362 pr.Status = issues_model.PullRequestStatusError 363 - if err := pr.UpdateCols("status"); err != nil { 363 + if err := pr.UpdateCols(ctx, "status"); err != nil { 364 364 log.Error("update pr [%-v] status to PullRequestStatusError failed: %v", pr, err) 365 365 } 366 366 return
+1 -1
services/pull/pull.go
··· 125 125 return err 126 126 } 127 127 128 - if !pr.IsWorkInProgress() { 128 + if !pr.IsWorkInProgress(ctx) { 129 129 if err := issues_model.PullRequestCodeOwnersReview(ctx, issue, pr); err != nil { 130 130 return err 131 131 }
+6 -6
services/repository/archiver/archiver.go
··· 172 172 } 173 173 } 174 174 175 - func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) { 176 - txCtx, committer, err := db.TxContext(db.DefaultContext) 175 + func doArchive(ctx context.Context, r *ArchiveRequest) (*repo_model.RepoArchiver, error) { 176 + txCtx, committer, err := db.TxContext(ctx) 177 177 if err != nil { 178 178 return nil, err 179 179 } ··· 291 291 // anything. In all cases, the caller should be examining the *ArchiveRequest 292 292 // being returned for completion, as it may be different than the one they passed 293 293 // in. 294 - func ArchiveRepository(request *ArchiveRequest) (*repo_model.RepoArchiver, error) { 295 - return doArchive(request) 294 + func ArchiveRepository(ctx context.Context, request *ArchiveRequest) (*repo_model.RepoArchiver, error) { 295 + return doArchive(ctx, request) 296 296 } 297 297 298 298 var archiverQueue *queue.WorkerPoolQueue[*ArchiveRequest] 299 299 300 300 // Init initializes archiver 301 - func Init() error { 301 + func Init(ctx context.Context) error { 302 302 handler := func(items ...*ArchiveRequest) []*ArchiveRequest { 303 303 for _, archiveReq := range items { 304 304 log.Trace("ArchiverData Process: %#v", archiveReq) 305 - if _, err := doArchive(archiveReq); err != nil { 305 + if _, err := doArchive(ctx, archiveReq); err != nil { 306 306 log.Error("Archive %v failed: %v", archiveReq, err) 307 307 } 308 308 }
+7 -6
services/repository/archiver/archiver_test.go
··· 8 8 "testing" 9 9 "time" 10 10 11 + "code.gitea.io/gitea/models/db" 11 12 "code.gitea.io/gitea/models/unittest" 12 13 "code.gitea.io/gitea/modules/contexttest" 13 14 ··· 79 80 inFlight[1] = tgzReq 80 81 inFlight[2] = secondReq 81 82 82 - ArchiveRepository(zipReq) 83 - ArchiveRepository(tgzReq) 84 - ArchiveRepository(secondReq) 83 + ArchiveRepository(db.DefaultContext, zipReq) 84 + ArchiveRepository(db.DefaultContext, tgzReq) 85 + ArchiveRepository(db.DefaultContext, secondReq) 85 86 86 87 // Make sure sending an unprocessed request through doesn't affect the queue 87 88 // count. 88 - ArchiveRepository(zipReq) 89 + ArchiveRepository(db.DefaultContext, zipReq) 89 90 90 91 // Sleep two seconds to make sure the queue doesn't change. 91 92 time.Sleep(2 * time.Second) ··· 100 101 // We still have the other three stalled at completion, waiting to remove 101 102 // from archiveInProgress. Try to submit this new one before its 102 103 // predecessor has cleared out of the queue. 103 - ArchiveRepository(zipReq2) 104 + ArchiveRepository(db.DefaultContext, zipReq2) 104 105 105 106 // Now we'll submit a request and TimedWaitForCompletion twice, before and 106 107 // after we release it. We should trigger both the timeout and non-timeout ··· 108 109 timedReq, err := NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, secondCommit+".tar.gz") 109 110 assert.NoError(t, err) 110 111 assert.NotNil(t, timedReq) 111 - ArchiveRepository(timedReq) 112 + ArchiveRepository(db.DefaultContext, timedReq) 112 113 113 114 zipReq2, err = NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip") 114 115 assert.NoError(t, err)
+1 -1
services/repository/branch.go
··· 161 161 } 162 162 } 163 163 164 - pr, err := issues_model.GetLatestPullRequestByHeadInfo(repo.ID, branchName) 164 + pr, err := issues_model.GetLatestPullRequestByHeadInfo(ctx, repo.ID, branchName) 165 165 if err != nil { 166 166 return nil, fmt.Errorf("GetLatestPullRequestByHeadInfo: %v", err) 167 167 }
+1 -1
services/repository/fork.go
··· 185 185 if err := repo_module.UpdateRepoSize(ctx, repo); err != nil { 186 186 log.Error("Failed to update size for repository: %v", err) 187 187 } 188 - if err := repo_model.CopyLanguageStat(opts.BaseRepo, repo); err != nil { 188 + if err := repo_model.CopyLanguageStat(ctx, opts.BaseRepo, repo); err != nil { 189 189 log.Error("Copy language stat from oldRepo failed: %v", err) 190 190 } 191 191
+1 -1
services/uinotification/notify.go
··· 114 114 log.Error("issue.LoadPullRequest: %v", err) 115 115 return 116 116 } 117 - if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress() { 117 + if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress(ctx) { 118 118 _ = ns.issueQueue.Push(issueNotificationOpts{ 119 119 IssueID: issue.ID, 120 120 NotificationAuthorID: doer.ID,
+5 -4
services/user/avatar.go
··· 4 4 package user 5 5 6 6 import ( 7 + "context" 7 8 "fmt" 8 9 "io" 9 10 ··· 15 16 ) 16 17 17 18 // UploadAvatar saves custom avatar for user. 18 - func UploadAvatar(u *user_model.User, data []byte) error { 19 + func UploadAvatar(ctx context.Context, u *user_model.User, data []byte) error { 19 20 avatarData, err := avatar.ProcessAvatarImage(data) 20 21 if err != nil { 21 22 return err 22 23 } 23 24 24 - ctx, committer, err := db.TxContext(db.DefaultContext) 25 + ctx, committer, err := db.TxContext(ctx) 25 26 if err != nil { 26 27 return err 27 28 } ··· 44 45 } 45 46 46 47 // DeleteAvatar deletes the user's custom avatar. 47 - func DeleteAvatar(u *user_model.User) error { 48 + func DeleteAvatar(ctx context.Context, u *user_model.User) error { 48 49 aPath := u.CustomAvatarRelativePath() 49 50 log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath) 50 51 if len(u.Avatar) > 0 { ··· 55 56 56 57 u.UseCustomAvatar = false 57 58 u.Avatar = "" 58 - if _, err := db.GetEngine(db.DefaultContext).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil { 59 + if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil { 59 60 return fmt.Errorf("UpdateUser: %w", err) 60 61 } 61 62 return nil
+1 -1
services/user/user.go
··· 223 223 } 224 224 } 225 225 226 - ctx, committer, err := db.TxContext(db.DefaultContext) 226 + ctx, committer, err := db.TxContext(ctx) 227 227 if err != nil { 228 228 return err 229 229 }
+2 -2
templates/repo/branch/list.tmpl
··· 25 25 <button class="btn interact-fg gt-px-2" data-clipboard-text="{{.DefaultBranchBranch.DBBranch.Name}}">{{svg "octicon-copy" 14}}</button> 26 26 {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DefaultBranchBranch.DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DefaultBranchBranch.DBBranch.CommitID)}} 27 27 </div> 28 - <p class="info gt-df gt-ac gt-my-2">{{svg "octicon-git-commit" 16 "gt-mr-2"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.DBBranch.CommitID}}">{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage .RepoLink .Repository.ComposeMetas}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DefaultBranchBranch.DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DefaultBranchBranch.DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p> 28 + <p class="info gt-df gt-ac gt-my-2">{{svg "octicon-git-commit" 16 "gt-mr-2"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.DBBranch.CommitID}}">{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage .RepoLink (.Repository.ComposeMetas ctx)}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DefaultBranchBranch.DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DefaultBranchBranch.DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p> 29 29 </td> 30 30 <td class="right aligned middle aligned overflow-visible"> 31 31 {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} ··· 101 101 <button class="btn interact-fg gt-px-2" data-clipboard-text="{{.DBBranch.Name}}">{{svg "octicon-copy" 14}}</button> 102 102 {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DBBranch.CommitID)}} 103 103 </div> 104 - <p class="info gt-df gt-ac gt-my-2">{{svg "octicon-git-commit" 16 "gt-mr-2"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .DBBranch.CommitID}}">{{ShortSha .DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DBBranch.CommitMessage $.RepoLink $.Repository.ComposeMetas}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}} &nbsp;{{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}</p> 104 + <p class="info gt-df gt-ac gt-my-2">{{svg "octicon-git-commit" 16 "gt-mr-2"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .DBBranch.CommitID}}">{{ShortSha .DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DBBranch.CommitMessage $.RepoLink ($.Repository.ComposeMetas ctx)}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}} &nbsp;{{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}</p> 105 105 {{end}} 106 106 </td> 107 107 <td class="two wide ui">
+3 -3
templates/repo/commit_page.tmpl
··· 19 19 {{end}} 20 20 <div class="ui top attached header clearing segment gt-relative commit-header {{$class}}"> 21 21 <div class="gt-df gt-mb-4 gt-fw"> 22 - <h3 class="gt-mb-0 gt-f1"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage $.Context .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "root" $}}</h3> 22 + <h3 class="gt-mb-0 gt-f1"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage $.Context .Commit.Message $.RepoLink ($.Repository.ComposeMetas ctx)}}</span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "root" $}}</h3> 23 23 {{if not $.PageIsWiki}} 24 24 <div> 25 25 <a class="ui primary tiny button" href="{{.SourcePath}}"> ··· 135 135 {{end}} 136 136 </div> 137 137 {{if IsMultilineCommitMessage .Commit.Message}} 138 - <pre class="commit-body">{{RenderCommitBody $.Context .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</pre> 138 + <pre class="commit-body">{{RenderCommitBody $.Context .Commit.Message $.RepoLink ($.Repository.ComposeMetas ctx)}}</pre> 139 139 {{end}} 140 140 {{template "repo/commit_load_branches_and_tags" .}} 141 141 </div> ··· 276 276 <span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When ctx.Locale}}</span> 277 277 </div> 278 278 <div class="ui bottom attached info segment git-notes"> 279 - <pre class="commit-body">{{RenderNote $.Context .Note $.RepoLink $.Repository.ComposeMetas}}</pre> 279 + <pre class="commit-body">{{RenderNote $.Context .Note $.RepoLink ($.Repository.ComposeMetas ctx)}}</pre> 280 280 </div> 281 281 {{end}} 282 282 {{template "repo/diff/box" .}}
+2 -2
templates/repo/commits_list.tmpl
··· 60 60 <span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{.Summary | RenderEmoji $.Context}}</span> 61 61 {{else}} 62 62 {{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape .ID.String)}} 63 - <span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.Context .Message $commitRepoLink $commitLink $.Repository.ComposeMetas}}</span> 63 + <span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.Context .Message $commitRepoLink $commitLink ($.Repository.ComposeMetas ctx)}}</span> 64 64 {{end}} 65 65 </span> 66 66 {{if IsMultilineCommitMessage .Message}} ··· 68 68 {{end}} 69 69 {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}} 70 70 {{if IsMultilineCommitMessage .Message}} 71 - <pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink $.Repository.ComposeMetas}}</pre> 71 + <pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink ($.Repository.ComposeMetas ctx)}}</pre> 72 72 {{end}} 73 73 </td> 74 74 {{if .Committer}}
+2 -2
templates/repo/commits_list_small.tmpl
··· 38 38 </a> 39 39 </span> 40 40 41 - <span class="gt-mono commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $commitLink $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}}</span> 41 + <span class="gt-mono commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $commitLink ($.comment.Issue.PullRequest.BaseRepo.ComposeMetas ctx)}}</span> 42 42 {{if IsMultilineCommitMessage .Message}} 43 43 <button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false">...</button> 44 44 {{end}} 45 45 {{if IsMultilineCommitMessage .Message}} 46 - <pre class="commit-body gt-hidden">{{RenderCommitBody $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}}</pre> 46 + <pre class="commit-body gt-hidden">{{RenderCommitBody $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) ($.comment.Issue.PullRequest.BaseRepo.ComposeMetas ctx)}}</pre> 47 47 {{end}} 48 48 </div> 49 49 {{end}}
+2 -2
templates/repo/diff/compare.tmpl
··· 77 77 <div class="item" data-url="{{$.OwnForkRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$OwnForkCompareName}}:{{.}}</div> 78 78 {{end}} 79 79 {{end}} 80 - {{if and .RootRepo .RootRepo.AllowsPulls}} 80 + {{if and .RootRepo (.RootRepo.AllowsPulls ctx)}} 81 81 {{range .RootRepoBranches}} 82 82 <div class="item" data-url="{{$.RootRepo.Link}}/compare/{{PathEscapeSegments .}}{{$.CompareSeparator}}{{PathEscape $.HeadUser.Name}}/{{PathEscape $.HeadRepo.Name}}:{{PathEscapeSegments $.HeadBranch}}">{{$RootRepoCompareName}}:{{.}}</div> 83 83 {{end}} ··· 194 194 <div class="twelve wide column issue-title"> 195 195 {{ctx.Locale.Tr "repo.pulls.has_pull_request" (print (Escape $.RepoLink) "/pulls/" .PullRequest.Issue.Index) (Escape $.RepoRelPath) .PullRequest.Index | Safe}} 196 196 <h1> 197 - <span id="issue-title">{{RenderIssueTitle $.Context .PullRequest.Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span> 197 + <span id="issue-title">{{RenderIssueTitle $.Context .PullRequest.Issue.Title $.RepoLink ($.Repository.ComposeMetas ctx)}}</span> 198 198 <span class="index">#{{.PullRequest.Issue.Index}}</span> 199 199 </h1> 200 200 </div>
+1 -1
templates/repo/graph/commits.tmpl
··· 29 29 </a> 30 30 </span> 31 31 <span class="message gt-dib gt-ellipsis gt-mr-3"> 32 - <span>{{RenderCommitMessage $.Context $commit.Subject $.RepoLink $.Repository.ComposeMetas}}</span> 32 + <span>{{RenderCommitMessage $.Context $commit.Subject $.RepoLink ($.Repository.ComposeMetas ctx)}}</span> 33 33 </span> 34 34 <span class="commit-refs gt-df gt-ac gt-mr-2"> 35 35 {{range $commit.Refs}}
+1 -1
templates/repo/header.tmpl
··· 40 40 <div class="fork-flag">{{ctx.Locale.Tr "repo.mirror_from"}} <a target="_blank" rel="noopener noreferrer" href="{{$.PullMirror.RemoteAddress}}">{{$.PullMirror.RemoteAddress}}</a></div> 41 41 {{end}} 42 42 {{if .IsFork}}<div class="fork-flag">{{ctx.Locale.Tr "repo.forked_from"}} <a href="{{.BaseRepo.Link}}">{{.BaseRepo.FullName}}</a></div>{{end}} 43 - {{if .IsGenerated}}<div class="fork-flag">{{ctx.Locale.Tr "repo.generated_from"}} <a href="{{.TemplateRepo.Link}}">{{.TemplateRepo.FullName}}</a></div>{{end}} 43 + {{if .IsGenerated}}<div class="fork-flag">{{ctx.Locale.Tr "repo.generated_from"}} <a href="{{(.TemplateRepo ctx).Link}}">{{(.TemplateRepo ctx).FullName}}</a></div>{{end}} 44 44 </div> 45 45 {{if not (or .IsBeingCreated .IsBroken)}} 46 46 <div class="repo-buttons">
+1 -1
templates/repo/icon.tmpl
··· 1 - {{$avatarLink := .RelAvatarLink}} 1 + {{$avatarLink := (.RelAvatarLink ctx)}} 2 2 {{if $avatarLink}} 3 3 <img class="ui avatar gt-vm" src="{{$avatarLink}}" width="32" height="32" alt="{{.FullName}}"> 4 4 {{else if $.IsTemplate}}
+1 -1
templates/repo/issue/view_content/pull.tmpl
··· 189 189 190 190 {{if .AllowMerge}} {{/* user is allowed to merge */}} 191 191 {{$prUnit := .Repository.MustGetUnit $.Context $.UnitTypePullRequests}} 192 - {{$approvers := .Issue.PullRequest.GetApprovers}} 192 + {{$approvers := (.Issue.PullRequest.GetApprovers ctx)}} 193 193 {{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash}} 194 194 {{$hasPendingPullRequestMergeTip := ""}} 195 195 {{if .HasPendingPullRequestMerge}}
+1 -1
templates/repo/issue/view_title.tmpl
··· 6 6 <div class="issue-title-header"> 7 7 <div class="issue-title" id="issue-title-wrapper"> 8 8 <h1 class="gt-word-break"> 9 - <span id="issue-title">{{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas | RenderCodeBlock}} <span class="index">#{{.Issue.Index}}</span> 9 + <span id="issue-title">{{RenderIssueTitle $.Context .Issue.Title $.RepoLink ($.Repository.ComposeMetas ctx) | RenderCodeBlock}} <span class="index">#{{.Issue.Index}}</span> 10 10 </span> 11 11 <div id="edit-title-input" class="ui input gt-f1 gt-hidden"> 12 12 <input value="{{.Issue.Title}}" maxlength="255" autocomplete="off">
+3 -3
templates/repo/view_list.tmpl
··· 26 26 </a> 27 27 {{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses "root" $}} 28 28 {{$commitLink:= printf "%s/commit/%s" .RepoLink (PathEscape .LatestCommit.ID.String)}} 29 - <span class="grey commit-summary" title="{{.LatestCommit.Summary}}"><span class="message-wrapper">{{RenderCommitMessageLinkSubject $.Context .LatestCommit.Message $.RepoLink $commitLink $.Repository.ComposeMetas}}</span> 29 + <span class="grey commit-summary" title="{{.LatestCommit.Summary}}"><span class="message-wrapper">{{RenderCommitMessageLinkSubject $.Context .LatestCommit.Message $.RepoLink $commitLink ($.Repository.ComposeMetas ctx)}}</span> 30 30 {{if IsMultilineCommitMessage .LatestCommit.Message}} 31 31 <button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false">...</button> 32 - <pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .LatestCommit.Message $.RepoLink $.Repository.ComposeMetas}}</pre> 32 + <pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .LatestCommit.Message $.RepoLink ($.Repository.ComposeMetas ctx)}}</pre> 33 33 {{end}} 34 34 </span> 35 35 {{end}} ··· 83 83 <span class="truncate"> 84 84 {{if $commit}} 85 85 {{$commitLink := printf "%s/commit/%s" $.RepoLink (PathEscape $commit.ID.String)}} 86 - {{RenderCommitMessageLinkSubject $.Context $commit.Message $.RepoLink $commitLink $.Repository.ComposeMetas}} 86 + {{RenderCommitMessageLinkSubject $.Context $commit.Message $.RepoLink $commitLink ($.Repository.ComposeMetas ctx)}} 87 87 {{else}} 88 88 <div class="ui active tiny slow centered inline">…</div> 89 89 {{end}}
+2 -2
templates/shared/issueicon.tmpl
··· 7 7 {{if .IsClosed}} 8 8 {{svg "octicon-git-pull-request" 16 "text red"}} 9 9 {{else}} 10 - {{if and .PullRequest .PullRequest.IsWorkInProgress}} 10 + {{if and .PullRequest (.PullRequest.IsWorkInProgress ctx)}} 11 11 {{svg "octicon-git-pull-request-draft" 16 "text grey"}} 12 - {{else if and (.GetPullRequest ctx) (.GetPullRequest ctx).IsWorkInProgress}} 12 + {{else if and (.GetPullRequest ctx) ((.GetPullRequest ctx).IsWorkInProgress ctx)}} 13 13 {{svg "octicon-git-pull-request-draft" 16 "text grey"}} 14 14 {{else}} 15 15 {{svg "octicon-git-pull-request" 16 "text green"}}
+1 -1
templates/user/dashboard/feeds.tmpl
··· 90 90 <img class="ui avatar" src="{{$push.AvatarLink $.Context .AuthorEmail}}" title="{{.AuthorName}}" width="16" height="16"> 91 91 <a class="ui sha label" href="{{$commitLink}}">{{ShortSha .Sha1}}</a> 92 92 <span class="text truncate"> 93 - {{RenderCommitMessage $.Context .Message $repoLink $.ComposeMetas}} 93 + {{RenderCommitMessage $.Context .Message $repoLink ($.ComposeMetas ctx)}} 94 94 </span> 95 95 </div> 96 96 {{end}}
+1 -1
tests/integration/auth_ldap_test.go
··· 332 332 }) 333 333 ldapConfig := ldapSource.Cfg.(*ldap.Source) 334 334 ldapConfig.GroupFilter = "(cn=ship_crew)" 335 - auth_model.UpdateSource(ldapSource) 335 + auth_model.UpdateSource(db.DefaultContext, ldapSource) 336 336 337 337 auth.SyncExternalUsers(context.Background(), true) 338 338
+1 -1
tests/integration/pull_merge_test.go
··· 425 425 // Check if status is correct. 426 426 assert.Equal(t, issues_model.PullRequestStatusConflict, conflictingPR.Status) 427 427 // Ensure that mergeable returns false 428 - assert.False(t, conflictingPR.Mergeable()) 428 + assert.False(t, conflictingPR.Mergeable(db.DefaultContext)) 429 429 }) 430 430 }