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.

Even more `db.DefaultContext` refactor (#27352)

Part of #27065

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>

authored by

JakobDev
Lunny Xiao
delvh
and committed by
GitHub
cc5df266 08507e27

+298 -294
+1 -1
models/activities/action.go
··· 524 524 } 525 525 526 526 if opts.RequestedTeam != nil { 527 - env := organization.OrgFromUser(opts.RequestedUser).AccessibleTeamReposEnv(opts.RequestedTeam) 527 + env := organization.OrgFromUser(opts.RequestedUser).AccessibleTeamReposEnv(ctx, opts.RequestedTeam) 528 528 teamRepoIDs, err := env.RepoIDs(1, opts.RequestedUser.NumRepos) 529 529 if err != nil { 530 530 return nil, fmt.Errorf("GetTeamRepositories: %w", err)
+1 -1
models/activities/statistic.go
··· 52 52 func GetStatistic(ctx context.Context) (stats Statistic) { 53 53 e := db.GetEngine(ctx) 54 54 stats.Counter.User = user_model.CountUsers(ctx, nil) 55 - stats.Counter.Org, _ = organization.CountOrgs(organization.FindOrgOptions{IncludePrivate: true}) 55 + stats.Counter.Org, _ = organization.CountOrgs(ctx, organization.FindOrgOptions{IncludePrivate: true}) 56 56 stats.Counter.PublicKey, _ = e.Count(new(asymkey_model.PublicKey)) 57 57 stats.Counter.Repo, _ = repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{}) 58 58 stats.Counter.Watch, _ = e.Count(new(repo_model.Watch))
+1 -1
models/issues/assignees_test.go
··· 18 18 assert.NoError(t, unittest.PrepareTestDatabase()) 19 19 20 20 // Fake issue with assignees 21 - issue, err := issues_model.GetIssueWithAttrsByID(1) 21 + issue, err := issues_model.GetIssueWithAttrsByID(db.DefaultContext, 1) 22 22 assert.NoError(t, err) 23 23 24 24 // Assign multiple users
+2 -2
models/issues/comment.go
··· 655 655 } 656 656 657 657 // LoadTime loads the associated time for a CommentTypeAddTimeManual 658 - func (c *Comment) LoadTime() error { 658 + func (c *Comment) LoadTime(ctx context.Context) error { 659 659 if c.Time != nil || c.TimeID == 0 { 660 660 return nil 661 661 } 662 662 var err error 663 - c.Time, err = GetTrackedTimeByID(c.TimeID) 663 + c.Time, err = GetTrackedTimeByID(ctx, c.TimeID) 664 664 return err 665 665 } 666 666
+15 -15
models/issues/issue.go
··· 201 201 } 202 202 203 203 // GetPullRequest returns the issue pull request 204 - func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) { 204 + func (issue *Issue) GetPullRequest(ctx context.Context) (pr *PullRequest, err error) { 205 205 if !issue.IsPull { 206 206 return nil, fmt.Errorf("Issue is not a pull request") 207 207 } 208 208 209 - pr, err = GetPullRequestByIssueID(db.DefaultContext, issue.ID) 209 + pr, err = GetPullRequestByIssueID(ctx, issue.ID) 210 210 if err != nil { 211 211 return nil, err 212 212 } ··· 369 369 } 370 370 371 371 // GetIsRead load the `IsRead` field of the issue 372 - func (issue *Issue) GetIsRead(userID int64) error { 372 + func (issue *Issue) GetIsRead(ctx context.Context, userID int64) error { 373 373 issueUser := &IssueUser{IssueID: issue.ID, UID: userID} 374 - if has, err := db.GetEngine(db.DefaultContext).Get(issueUser); err != nil { 374 + if has, err := db.GetEngine(ctx).Get(issueUser); err != nil { 375 375 return err 376 376 } else if !has { 377 377 issue.IsRead = false ··· 382 382 } 383 383 384 384 // APIURL returns the absolute APIURL to this issue. 385 - func (issue *Issue) APIURL() string { 385 + func (issue *Issue) APIURL(ctx context.Context) string { 386 386 if issue.Repo == nil { 387 - err := issue.LoadRepo(db.DefaultContext) 387 + err := issue.LoadRepo(ctx) 388 388 if err != nil { 389 389 log.Error("Issue[%d].APIURL(): %v", issue.ID, err) 390 390 return "" ··· 479 479 } 480 480 481 481 // GetLastComment return last comment for the current issue. 482 - func (issue *Issue) GetLastComment() (*Comment, error) { 482 + func (issue *Issue) GetLastComment(ctx context.Context) (*Comment, error) { 483 483 var c Comment 484 - exist, err := db.GetEngine(db.DefaultContext).Where("type = ?", CommentTypeComment). 484 + exist, err := db.GetEngine(ctx).Where("type = ?", CommentTypeComment). 485 485 And("issue_id = ?", issue.ID).Desc("created_unix").Get(&c) 486 486 if err != nil { 487 487 return nil, err ··· 543 543 } 544 544 545 545 // GetIssueWithAttrsByID returns an issue with attributes by given ID. 546 - func GetIssueWithAttrsByID(id int64) (*Issue, error) { 547 - issue, err := GetIssueByID(db.DefaultContext, id) 546 + func GetIssueWithAttrsByID(ctx context.Context, id int64) (*Issue, error) { 547 + issue, err := GetIssueByID(ctx, id) 548 548 if err != nil { 549 549 return nil, err 550 550 } 551 - return issue, issue.LoadAttributes(db.DefaultContext) 551 + return issue, issue.LoadAttributes(ctx) 552 552 } 553 553 554 554 // GetIssuesByIDs return issues with the given IDs. ··· 600 600 } 601 601 602 602 // IsUserParticipantsOfIssue return true if user is participants of an issue 603 - func IsUserParticipantsOfIssue(user *user_model.User, issue *Issue) bool { 604 - userIDs, err := issue.GetParticipantIDsByIssue(db.DefaultContext) 603 + func IsUserParticipantsOfIssue(ctx context.Context, user *user_model.User, issue *Issue) bool { 604 + userIDs, err := issue.GetParticipantIDsByIssue(ctx) 605 605 if err != nil { 606 606 log.Error(err.Error()) 607 607 return false ··· 894 894 } 895 895 896 896 // InsertIssues insert issues to database 897 - func InsertIssues(issues ...*Issue) error { 898 - ctx, committer, err := db.TxContext(db.DefaultContext) 897 + func InsertIssues(ctx context.Context, issues ...*Issue) error { 898 + ctx, committer, err := db.TxContext(ctx) 899 899 if err != nil { 900 900 return err 901 901 }
+2 -2
models/issues/issue_test.go
··· 65 65 err := issue.LoadAttributes(db.DefaultContext) 66 66 67 67 assert.NoError(t, err) 68 - assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL()) 68 + assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL(db.DefaultContext)) 69 69 } 70 70 71 71 func TestGetIssuesByIDs(t *testing.T) { ··· 477 477 Labels: []*issues_model.Label{label}, 478 478 Reactions: []*issues_model.Reaction{reaction}, 479 479 } 480 - err := issues_model.InsertIssues(is) 480 + err := issues_model.InsertIssues(db.DefaultContext, is) 481 481 assert.NoError(t, err) 482 482 483 483 i := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{Title: title})
+1 -1
models/issues/issue_watch.go
··· 81 81 if err != nil { 82 82 return false, err 83 83 } 84 - return repo_model.IsWatchMode(w.Mode) || IsUserParticipantsOfIssue(user, issue), nil 84 + return repo_model.IsWatchMode(w.Mode) || IsUserParticipantsOfIssue(ctx, user, issue), nil 85 85 } 86 86 87 87 // GetIssueWatchersIDs returns IDs of subscribers or explicit unsubscribers to a given issue id
+1 -1
models/issues/pull.go
··· 1040 1040 warnings = append(warnings, fmt.Sprintf("incorrect codeowner organization: %s", user)) 1041 1041 continue 1042 1042 } 1043 - teams, err := org.LoadTeams() 1043 + teams, err := org.LoadTeams(ctx) 1044 1044 if err != nil { 1045 1045 warnings = append(warnings, fmt.Sprintf("incorrect codeowner team: %s", user)) 1046 1046 continue
+9 -9
models/issues/tracked_time.go
··· 199 199 } 200 200 201 201 // TotalTimesForEachUser returns the spent time in seconds for each user by an issue 202 - func TotalTimesForEachUser(options *FindTrackedTimesOptions) (map[*user_model.User]int64, error) { 203 - trackedTimes, err := GetTrackedTimes(db.DefaultContext, options) 202 + func TotalTimesForEachUser(ctx context.Context, options *FindTrackedTimesOptions) (map[*user_model.User]int64, error) { 203 + trackedTimes, err := GetTrackedTimes(ctx, options) 204 204 if err != nil { 205 205 return nil, err 206 206 } ··· 213 213 totalTimes := make(map[*user_model.User]int64) 214 214 // Fetching User and making time human readable 215 215 for userID, total := range totalTimesByUser { 216 - user, err := user_model.GetUserByID(db.DefaultContext, userID) 216 + user, err := user_model.GetUserByID(ctx, userID) 217 217 if err != nil { 218 218 if user_model.IsErrUserNotExist(err) { 219 219 continue ··· 226 226 } 227 227 228 228 // DeleteIssueUserTimes deletes times for issue 229 - func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { 230 - ctx, committer, err := db.TxContext(db.DefaultContext) 229 + func DeleteIssueUserTimes(ctx context.Context, issue *Issue, user *user_model.User) error { 230 + ctx, committer, err := db.TxContext(ctx) 231 231 if err != nil { 232 232 return err 233 233 } ··· 265 265 } 266 266 267 267 // DeleteTime delete a specific Time 268 - func DeleteTime(t *TrackedTime) error { 269 - ctx, committer, err := db.TxContext(db.DefaultContext) 268 + func DeleteTime(ctx context.Context, t *TrackedTime) error { 269 + ctx, committer, err := db.TxContext(ctx) 270 270 if err != nil { 271 271 return err 272 272 } ··· 315 315 } 316 316 317 317 // GetTrackedTimeByID returns raw TrackedTime without loading attributes by id 318 - func GetTrackedTimeByID(id int64) (*TrackedTime, error) { 318 + func GetTrackedTimeByID(ctx context.Context, id int64) (*TrackedTime, error) { 319 319 time := new(TrackedTime) 320 - has, err := db.GetEngine(db.DefaultContext).ID(id).Get(time) 320 + has, err := db.GetEngine(ctx).ID(id).Get(time) 321 321 if err != nil { 322 322 return nil, err 323 323 } else if !has {
+4 -4
models/issues/tracked_time_test.go
··· 82 82 func TestTotalTimesForEachUser(t *testing.T) { 83 83 assert.NoError(t, unittest.PrepareTestDatabase()) 84 84 85 - total, err := issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 1}) 85 + total, err := issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 1}) 86 86 assert.NoError(t, err) 87 87 assert.Len(t, total, 1) 88 88 for user, time := range total { ··· 90 90 assert.EqualValues(t, 400, time) 91 91 } 92 92 93 - total, err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 2}) 93 + total, err = issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 2}) 94 94 assert.NoError(t, err) 95 95 assert.Len(t, total, 2) 96 96 for user, time := range total { ··· 103 103 } 104 104 } 105 105 106 - total, err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 5}) 106 + total, err = issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 5}) 107 107 assert.NoError(t, err) 108 108 assert.Len(t, total, 1) 109 109 for user, time := range total { ··· 111 111 assert.EqualValues(t, 1, time) 112 112 } 113 113 114 - total, err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: 4}) 114 + total, err = issues_model.TotalTimesForEachUser(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 4}) 115 115 assert.NoError(t, err) 116 116 assert.Len(t, total, 2) 117 117 }
+1 -1
models/org_team.go
··· 362 362 return err 363 363 } 364 364 365 - if err := organization.AddOrgUser(team.OrgID, userID); err != nil { 365 + if err := organization.AddOrgUser(ctx, team.OrgID, userID); err != nil { 366 366 return err 367 367 } 368 368
+39 -39
models/organization/org.go
··· 96 96 } 97 97 98 98 // IsOwnedBy returns true if given user is in the owner team. 99 - func (org *Organization) IsOwnedBy(uid int64) (bool, error) { 100 - return IsOrganizationOwner(db.DefaultContext, org.ID, uid) 99 + func (org *Organization) IsOwnedBy(ctx context.Context, uid int64) (bool, error) { 100 + return IsOrganizationOwner(ctx, org.ID, uid) 101 101 } 102 102 103 103 // IsOrgAdmin returns true if given user is in the owner team or an admin team. 104 - func (org *Organization) IsOrgAdmin(uid int64) (bool, error) { 105 - return IsOrganizationAdmin(db.DefaultContext, org.ID, uid) 104 + func (org *Organization) IsOrgAdmin(ctx context.Context, uid int64) (bool, error) { 105 + return IsOrganizationAdmin(ctx, org.ID, uid) 106 106 } 107 107 108 108 // IsOrgMember returns true if given user is member of organization. 109 - func (org *Organization) IsOrgMember(uid int64) (bool, error) { 110 - return IsOrganizationMember(db.DefaultContext, org.ID, uid) 109 + func (org *Organization) IsOrgMember(ctx context.Context, uid int64) (bool, error) { 110 + return IsOrganizationMember(ctx, org.ID, uid) 111 111 } 112 112 113 113 // CanCreateOrgRepo returns true if given user can create repo in organization 114 - func (org *Organization) CanCreateOrgRepo(uid int64) (bool, error) { 115 - return CanCreateOrgRepo(db.DefaultContext, org.ID, uid) 114 + func (org *Organization) CanCreateOrgRepo(ctx context.Context, uid int64) (bool, error) { 115 + return CanCreateOrgRepo(ctx, org.ID, uid) 116 116 } 117 117 118 118 // GetTeam returns named team of organization. ··· 135 135 } 136 136 137 137 // LoadTeams load teams if not loaded. 138 - func (org *Organization) LoadTeams() ([]*Team, error) { 139 - return FindOrgTeams(db.DefaultContext, org.ID) 138 + func (org *Organization) LoadTeams(ctx context.Context) ([]*Team, error) { 139 + return FindOrgTeams(ctx, org.ID) 140 140 } 141 141 142 142 // GetMembers returns all members of organization. ··· 147 147 } 148 148 149 149 // HasMemberWithUserID returns true if user with userID is part of the u organisation. 150 - func (org *Organization) HasMemberWithUserID(userID int64) bool { 151 - return org.hasMemberWithUserID(db.DefaultContext, userID) 150 + func (org *Organization) HasMemberWithUserID(ctx context.Context, userID int64) bool { 151 + return org.hasMemberWithUserID(ctx, userID) 152 152 } 153 153 154 154 func (org *Organization) hasMemberWithUserID(ctx context.Context, userID int64) bool { ··· 199 199 } 200 200 201 201 // CountOrgMembers counts the organization's members 202 - func CountOrgMembers(opts *FindOrgMembersOpts) (int64, error) { 203 - sess := db.GetEngine(db.DefaultContext).Where("org_id=?", opts.OrgID) 202 + func CountOrgMembers(ctx context.Context, opts *FindOrgMembersOpts) (int64, error) { 203 + sess := db.GetEngine(ctx).Where("org_id=?", opts.OrgID) 204 204 if opts.PublicOnly { 205 205 sess.And("is_public = ?", true) 206 206 } ··· 271 271 } 272 272 273 273 // CreateOrganization creates record of a new organization. 274 - func CreateOrganization(org *Organization, owner *user_model.User) (err error) { 274 + func CreateOrganization(ctx context.Context, org *Organization, owner *user_model.User) (err error) { 275 275 if !owner.CanCreateOrganization() { 276 276 return ErrUserNotAllowedCreateOrg{} 277 277 } ··· 280 280 return err 281 281 } 282 282 283 - isExist, err := user_model.IsUserExist(db.DefaultContext, 0, org.Name) 283 + isExist, err := user_model.IsUserExist(ctx, 0, org.Name) 284 284 if err != nil { 285 285 return err 286 286 } else if isExist { ··· 300 300 org.NumMembers = 1 301 301 org.Type = user_model.UserTypeOrganization 302 302 303 - ctx, committer, err := db.TxContext(db.DefaultContext) 303 + ctx, committer, err := db.TxContext(ctx) 304 304 if err != nil { 305 305 return err 306 306 } ··· 412 412 } 413 413 414 414 // GetOrgUserMaxAuthorizeLevel returns highest authorize level of user in an organization 415 - func (org *Organization) GetOrgUserMaxAuthorizeLevel(uid int64) (perm.AccessMode, error) { 415 + func (org *Organization) GetOrgUserMaxAuthorizeLevel(ctx context.Context, uid int64) (perm.AccessMode, error) { 416 416 var authorize perm.AccessMode 417 - _, err := db.GetEngine(db.DefaultContext). 417 + _, err := db.GetEngine(ctx). 418 418 Select("max(team.authorize)"). 419 419 Table("team"). 420 420 Join("INNER", "team_user", "team_user.team_id = team.id"). ··· 468 468 } 469 469 470 470 // FindOrgs returns a list of organizations according given conditions 471 - func FindOrgs(opts FindOrgOptions) ([]*Organization, error) { 471 + func FindOrgs(ctx context.Context, opts FindOrgOptions) ([]*Organization, error) { 472 472 orgs := make([]*Organization, 0, 10) 473 - sess := db.GetEngine(db.DefaultContext). 473 + sess := db.GetEngine(ctx). 474 474 Where(opts.toConds()). 475 475 Asc("`user`.name") 476 476 if opts.Page > 0 && opts.PageSize > 0 { ··· 480 480 } 481 481 482 482 // CountOrgs returns total count organizations according options 483 - func CountOrgs(opts FindOrgOptions) (int64, error) { 484 - return db.GetEngine(db.DefaultContext). 483 + func CountOrgs(ctx context.Context, opts FindOrgOptions) (int64, error) { 484 + return db.GetEngine(ctx). 485 485 Where(opts.toConds()). 486 486 Count(new(Organization)) 487 487 } ··· 505 505 } 506 506 507 507 // HasOrgsVisible tells if the given user can see at least one of the orgs provided 508 - func HasOrgsVisible(orgs []*Organization, user *user_model.User) bool { 508 + func HasOrgsVisible(ctx context.Context, orgs []*Organization, user *user_model.User) bool { 509 509 if len(orgs) == 0 { 510 510 return false 511 511 } 512 512 513 513 for _, org := range orgs { 514 - if HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), user) { 514 + if HasOrgOrUserVisible(ctx, org.AsUser(), user) { 515 515 return true 516 516 } 517 517 } ··· 550 550 } 551 551 552 552 // ChangeOrgUserStatus changes public or private membership status. 553 - func ChangeOrgUserStatus(orgID, uid int64, public bool) error { 553 + func ChangeOrgUserStatus(ctx context.Context, orgID, uid int64, public bool) error { 554 554 ou := new(OrgUser) 555 - has, err := db.GetEngine(db.DefaultContext). 555 + has, err := db.GetEngine(ctx). 556 556 Where("uid=?", uid). 557 557 And("org_id=?", orgID). 558 558 Get(ou) ··· 563 563 } 564 564 565 565 ou.IsPublic = public 566 - _, err = db.GetEngine(db.DefaultContext).ID(ou.ID).Cols("is_public").Update(ou) 566 + _, err = db.GetEngine(ctx).ID(ou.ID).Cols("is_public").Update(ou) 567 567 return err 568 568 } 569 569 570 570 // AddOrgUser adds new user to given organization. 571 - func AddOrgUser(orgID, uid int64) error { 572 - isAlreadyMember, err := IsOrganizationMember(db.DefaultContext, orgID, uid) 571 + func AddOrgUser(ctx context.Context, orgID, uid int64) error { 572 + isAlreadyMember, err := IsOrganizationMember(ctx, orgID, uid) 573 573 if err != nil || isAlreadyMember { 574 574 return err 575 575 } 576 576 577 - ctx, committer, err := db.TxContext(db.DefaultContext) 577 + ctx, committer, err := db.TxContext(ctx) 578 578 if err != nil { 579 579 return err 580 580 } ··· 669 669 } 670 670 671 671 // TeamsWithAccessToRepo returns all teams that have given access level to the repository. 672 - func (org *Organization) TeamsWithAccessToRepo(repoID int64, mode perm.AccessMode) ([]*Team, error) { 673 - return GetTeamsWithAccessToRepo(db.DefaultContext, org.ID, repoID, mode) 672 + func (org *Organization) TeamsWithAccessToRepo(ctx context.Context, repoID int64, mode perm.AccessMode) ([]*Team, error) { 673 + return GetTeamsWithAccessToRepo(ctx, org.ID, repoID, mode) 674 674 } 675 675 676 676 // GetUserTeamIDs returns of all team IDs of the organization that user is member of. 677 - func (org *Organization) GetUserTeamIDs(userID int64) ([]int64, error) { 678 - return org.getUserTeamIDs(db.DefaultContext, userID) 677 + func (org *Organization) GetUserTeamIDs(ctx context.Context, userID int64) ([]int64, error) { 678 + return org.getUserTeamIDs(ctx, userID) 679 679 } 680 680 681 681 // GetUserTeams returns all teams that belong to user, 682 682 // and that the user has joined. 683 - func (org *Organization) GetUserTeams(userID int64) ([]*Team, error) { 684 - return org.getUserTeams(db.DefaultContext, userID) 683 + func (org *Organization) GetUserTeams(ctx context.Context, userID int64) ([]*Team, error) { 684 + return org.getUserTeams(ctx, userID) 685 685 } 686 686 687 687 // AccessibleReposEnvironment operations involving the repositories that are ··· 733 733 734 734 // AccessibleTeamReposEnv an AccessibleReposEnvironment for the repositories in `org` 735 735 // that are accessible to the specified team. 736 - func (org *Organization) AccessibleTeamReposEnv(team *Team) AccessibleReposEnvironment { 736 + func (org *Organization) AccessibleTeamReposEnv(ctx context.Context, team *Team) AccessibleReposEnvironment { 737 737 return &accessibleReposEnv{ 738 738 org: org, 739 739 team: team, 740 - ctx: db.DefaultContext, 740 + ctx: ctx, 741 741 orderBy: db.SearchOrderByRecentUpdated, 742 742 } 743 743 }
+18 -18
models/organization/org_test.go
··· 31 31 {2, 3, false}, 32 32 } { 33 33 org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: testCase.OrgID}) 34 - isOwner, err := org.IsOwnedBy(testCase.UserID) 34 + isOwner, err := org.IsOwnedBy(db.DefaultContext, testCase.UserID) 35 35 assert.NoError(t, err) 36 36 assert.Equal(t, testCase.ExpectedOwner, isOwner) 37 37 } ··· 52 52 {2, 3, false}, 53 53 } { 54 54 org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: testCase.OrgID}) 55 - isMember, err := org.IsOrgMember(testCase.UserID) 55 + isMember, err := org.IsOrgMember(db.DefaultContext, testCase.UserID) 56 56 assert.NoError(t, err) 57 57 assert.Equal(t, testCase.ExpectedMember, isMember) 58 58 } ··· 89 89 func TestUser_GetTeams(t *testing.T) { 90 90 assert.NoError(t, unittest.PrepareTestDatabase()) 91 91 org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) 92 - teams, err := org.LoadTeams() 92 + teams, err := org.LoadTeams(db.DefaultContext) 93 93 assert.NoError(t, err) 94 94 if assert.Len(t, teams, 5) { 95 95 assert.Equal(t, int64(1), teams[0].ID) ··· 131 131 assert.NoError(t, unittest.PrepareTestDatabase()) 132 132 expected, err := db.GetEngine(db.DefaultContext).Where("type=?", user_model.UserTypeOrganization).Count(&organization.Organization{}) 133 133 assert.NoError(t, err) 134 - cnt, err := organization.CountOrgs(organization.FindOrgOptions{IncludePrivate: true}) 134 + cnt, err := organization.CountOrgs(db.DefaultContext, organization.FindOrgOptions{IncludePrivate: true}) 135 135 assert.NoError(t, err) 136 136 assert.Equal(t, expected, cnt) 137 137 } ··· 168 168 func TestIsPublicMembership(t *testing.T) { 169 169 assert.NoError(t, unittest.PrepareTestDatabase()) 170 170 test := func(orgID, userID int64, expected bool) { 171 - isMember, err := organization.IsPublicMembership(orgID, userID) 171 + isMember, err := organization.IsPublicMembership(db.DefaultContext, orgID, userID) 172 172 assert.NoError(t, err) 173 173 assert.EqualValues(t, expected, isMember) 174 174 } ··· 183 183 func TestFindOrgs(t *testing.T) { 184 184 assert.NoError(t, unittest.PrepareTestDatabase()) 185 185 186 - orgs, err := organization.FindOrgs(organization.FindOrgOptions{ 186 + orgs, err := organization.FindOrgs(db.DefaultContext, organization.FindOrgOptions{ 187 187 UserID: 4, 188 188 IncludePrivate: true, 189 189 }) ··· 192 192 assert.EqualValues(t, 3, orgs[0].ID) 193 193 } 194 194 195 - orgs, err = organization.FindOrgs(organization.FindOrgOptions{ 195 + orgs, err = organization.FindOrgs(db.DefaultContext, organization.FindOrgOptions{ 196 196 UserID: 4, 197 197 IncludePrivate: false, 198 198 }) 199 199 assert.NoError(t, err) 200 200 assert.Len(t, orgs, 0) 201 201 202 - total, err := organization.CountOrgs(organization.FindOrgOptions{ 202 + total, err := organization.CountOrgs(db.DefaultContext, organization.FindOrgOptions{ 203 203 UserID: 4, 204 204 IncludePrivate: true, 205 205 }) ··· 250 250 assert.NoError(t, unittest.PrepareTestDatabase()) 251 251 252 252 testSuccess := func(orgID, userID int64, public bool) { 253 - assert.NoError(t, organization.ChangeOrgUserStatus(orgID, userID, public)) 253 + assert.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, orgID, userID, public)) 254 254 orgUser := unittest.AssertExistsAndLoadBean(t, &organization.OrgUser{OrgID: orgID, UID: userID}) 255 255 assert.Equal(t, public, orgUser.IsPublic) 256 256 } ··· 258 258 testSuccess(3, 2, false) 259 259 testSuccess(3, 2, false) 260 260 testSuccess(3, 4, true) 261 - assert.NoError(t, organization.ChangeOrgUserStatus(unittest.NonexistentID, unittest.NonexistentID, true)) 261 + assert.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID, true)) 262 262 } 263 263 264 264 func TestUser_GetUserTeamIDs(t *testing.T) { 265 265 assert.NoError(t, unittest.PrepareTestDatabase()) 266 266 org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) 267 267 testSuccess := func(userID int64, expected []int64) { 268 - teamIDs, err := org.GetUserTeamIDs(userID) 268 + teamIDs, err := org.GetUserTeamIDs(db.DefaultContext, userID) 269 269 assert.NoError(t, err) 270 270 assert.Equal(t, expected, teamIDs) 271 271 } ··· 352 352 } 353 353 354 354 unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization}) 355 - assert.NoError(t, organization.CreateOrganization(org, owner)) 355 + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) 356 356 org = unittest.AssertExistsAndLoadBean(t, 357 357 &organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization}) 358 358 test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner) ··· 375 375 } 376 376 377 377 unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization}) 378 - assert.NoError(t, organization.CreateOrganization(org, owner)) 378 + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) 379 379 org = unittest.AssertExistsAndLoadBean(t, 380 380 &organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization}) 381 381 test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner) ··· 398 398 } 399 399 400 400 unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization}) 401 - assert.NoError(t, organization.CreateOrganization(org, owner)) 401 + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) 402 402 org = unittest.AssertExistsAndLoadBean(t, 403 403 &organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization}) 404 404 test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner) ··· 461 461 } 462 462 463 463 unittest.AssertNotExistsBean(t, &user_model.User{Name: newOrgName, Type: user_model.UserTypeOrganization}) 464 - assert.NoError(t, organization.CreateOrganization(org, owner)) 464 + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner)) 465 465 org = unittest.AssertExistsAndLoadBean(t, 466 466 &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) 467 467 ownerTeam := unittest.AssertExistsAndLoadBean(t, ··· 481 481 } 482 482 483 483 unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) 484 - err := organization.CreateOrganization(org, owner) 484 + err := organization.CreateOrganization(db.DefaultContext, org, owner) 485 485 assert.Error(t, err) 486 486 assert.True(t, organization.IsErrUserNotAllowedCreateOrg(err)) 487 487 unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) ··· 495 495 owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 496 496 org := &organization.Organization{Name: "org3"} // should already exist 497 497 unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: org.Name}) // sanity check 498 - err := organization.CreateOrganization(org, owner) 498 + err := organization.CreateOrganization(db.DefaultContext, org, owner) 499 499 assert.Error(t, err) 500 500 assert.True(t, user_model.IsErrUserAlreadyExist(err)) 501 501 unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{}) ··· 506 506 assert.NoError(t, unittest.PrepareTestDatabase()) 507 507 508 508 owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 509 - err := organization.CreateOrganization(&organization.Organization{Name: "assets"}, owner) 509 + err := organization.CreateOrganization(db.DefaultContext, &organization.Organization{Name: "assets"}, owner) 510 510 assert.Error(t, err) 511 511 assert.True(t, db.IsErrNameReserved(err)) 512 512 unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{})
+4 -4
models/organization/org_user.go
··· 78 78 } 79 79 80 80 // IsPublicMembership returns true if the given user's membership of given org is public. 81 - func IsPublicMembership(orgID, uid int64) (bool, error) { 82 - return db.GetEngine(db.DefaultContext). 81 + func IsPublicMembership(ctx context.Context, orgID, uid int64) (bool, error) { 82 + return db.GetEngine(ctx). 83 83 Where("uid=?", uid). 84 84 And("org_id=?", orgID). 85 85 And("is_public=?", true). ··· 98 98 } 99 99 100 100 // IsUserOrgOwner returns true if user is in the owner team of given organization. 101 - func IsUserOrgOwner(users user_model.UserList, orgID int64) map[int64]bool { 101 + func IsUserOrgOwner(ctx context.Context, users user_model.UserList, orgID int64) map[int64]bool { 102 102 results := make(map[int64]bool, len(users)) 103 103 for _, user := range users { 104 104 results[user.ID] = false // Set default to false 105 105 } 106 - ownerMaps, err := loadOrganizationOwners(db.DefaultContext, users, orgID) 106 + ownerMaps, err := loadOrganizationOwners(ctx, users, orgID) 107 107 if err == nil { 108 108 for _, owner := range ownerMaps { 109 109 results[owner.UID] = true
+3 -3
models/organization/org_user_test.go
··· 39 39 func testUserIsPublicMember(t *testing.T, uid, orgID int64, expected bool) { 40 40 user, err := user_model.GetUserByID(db.DefaultContext, uid) 41 41 assert.NoError(t, err) 42 - is, err := organization.IsPublicMembership(orgID, user.ID) 42 + is, err := organization.IsPublicMembership(db.DefaultContext, orgID, user.ID) 43 43 assert.NoError(t, err) 44 44 assert.Equal(t, expected, is) 45 45 } ··· 123 123 assert.NoError(t, err) 124 124 members, _, err := org.GetMembers(db.DefaultContext) 125 125 assert.NoError(t, err) 126 - assert.Equal(t, expected, organization.IsUserOrgOwner(members, orgID)) 126 + assert.Equal(t, expected, organization.IsUserOrgOwner(db.DefaultContext, members, orgID)) 127 127 } 128 128 129 129 func TestAddOrgUser(t *testing.T) { ··· 134 134 if !unittest.BeanExists(t, &organization.OrgUser{OrgID: orgID, UID: userID}) { 135 135 expectedNumMembers++ 136 136 } 137 - assert.NoError(t, organization.AddOrgUser(orgID, userID)) 137 + assert.NoError(t, organization.AddOrgUser(db.DefaultContext, orgID, userID)) 138 138 ou := &organization.OrgUser{OrgID: orgID, UID: userID} 139 139 unittest.AssertExistsAndLoadBean(t, ou) 140 140 assert.Equal(t, isPublic, ou.IsPublic)
+6 -6
models/organization/team.go
··· 144 144 } 145 145 146 146 // IsMember returns true if given user is a member of team. 147 - func (t *Team) IsMember(userID int64) bool { 148 - isMember, err := IsTeamMember(db.DefaultContext, t.OrgID, t.ID, userID) 147 + func (t *Team) IsMember(ctx context.Context, userID int64) bool { 148 + isMember, err := IsTeamMember(ctx, t.OrgID, t.ID, userID) 149 149 if err != nil { 150 150 log.Error("IsMember: %v", err) 151 151 return false ··· 217 217 } 218 218 219 219 // GetTeamIDsByNames returns a slice of team ids corresponds to names. 220 - func GetTeamIDsByNames(orgID int64, names []string, ignoreNonExistent bool) ([]int64, error) { 220 + func GetTeamIDsByNames(ctx context.Context, orgID int64, names []string, ignoreNonExistent bool) ([]int64, error) { 221 221 ids := make([]int64, 0, len(names)) 222 222 for _, name := range names { 223 - u, err := GetTeam(db.DefaultContext, orgID, name) 223 + u, err := GetTeam(ctx, orgID, name) 224 224 if err != nil { 225 225 if ignoreNonExistent { 226 226 continue ··· 251 251 } 252 252 253 253 // GetTeamNamesByID returns team's lower name from a list of team ids. 254 - func GetTeamNamesByID(teamIDs []int64) ([]string, error) { 254 + func GetTeamNamesByID(ctx context.Context, teamIDs []int64) ([]string, error) { 255 255 if len(teamIDs) == 0 { 256 256 return []string{}, nil 257 257 } 258 258 259 259 var teamNames []string 260 - err := db.GetEngine(db.DefaultContext).Table("team"). 260 + err := db.GetEngine(ctx).Table("team"). 261 261 Select("lower_name"). 262 262 In("id", teamIDs). 263 263 Asc("name").
+7 -7
models/organization/team_test.go
··· 27 27 assert.NoError(t, unittest.PrepareTestDatabase()) 28 28 29 29 team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1}) 30 - assert.True(t, team.IsMember(2)) 31 - assert.False(t, team.IsMember(4)) 32 - assert.False(t, team.IsMember(unittest.NonexistentID)) 30 + assert.True(t, team.IsMember(db.DefaultContext, 2)) 31 + assert.False(t, team.IsMember(db.DefaultContext, 4)) 32 + assert.False(t, team.IsMember(db.DefaultContext, unittest.NonexistentID)) 33 33 34 34 team = unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2}) 35 - assert.True(t, team.IsMember(2)) 36 - assert.True(t, team.IsMember(4)) 37 - assert.False(t, team.IsMember(unittest.NonexistentID)) 35 + assert.True(t, team.IsMember(db.DefaultContext, 2)) 36 + assert.True(t, team.IsMember(db.DefaultContext, 4)) 37 + assert.False(t, team.IsMember(db.DefaultContext, unittest.NonexistentID)) 38 38 } 39 39 40 40 func TestTeam_GetRepositories(t *testing.T) { ··· 188 188 assert.NoError(t, unittest.PrepareTestDatabase()) 189 189 190 190 test := func(teamIDs, userIDs []int64, expected int64) { 191 - count, err := organization.UsersInTeamsCount(teamIDs, userIDs) 191 + count, err := organization.UsersInTeamsCount(db.DefaultContext, teamIDs, userIDs) 192 192 assert.NoError(t, err) 193 193 assert.Equal(t, expected, count) 194 194 }
+2 -2
models/organization/team_unit.go
··· 30 30 } 31 31 32 32 // UpdateTeamUnits updates a teams's units 33 - func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) { 34 - ctx, committer, err := db.TxContext(db.DefaultContext) 33 + func UpdateTeamUnits(ctx context.Context, team *Team, units []TeamUnit) (err error) { 34 + ctx, committer, err := db.TxContext(ctx) 35 35 if err != nil { 36 36 return err 37 37 }
+2 -2
models/organization/team_user.go
··· 78 78 } 79 79 80 80 // UsersInTeamsCount counts the number of users which are in userIDs and teamIDs 81 - func UsersInTeamsCount(userIDs, teamIDs []int64) (int64, error) { 81 + func UsersInTeamsCount(ctx context.Context, userIDs, teamIDs []int64) (int64, error) { 82 82 var ids []int64 83 - if err := db.GetEngine(db.DefaultContext).In("uid", userIDs).In("team_id", teamIDs). 83 + if err := db.GetEngine(ctx).In("uid", userIDs).In("team_id", teamIDs). 84 84 Table("team_user"). 85 85 Cols("uid").GroupBy("uid").Find(&ids); err != nil { 86 86 return 0, err
+7 -7
models/perm/access/repo_permission.go
··· 261 261 } 262 262 263 263 // IsUserRealRepoAdmin check if this user is real repo admin 264 - func IsUserRealRepoAdmin(repo *repo_model.Repository, user *user_model.User) (bool, error) { 264 + func IsUserRealRepoAdmin(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (bool, error) { 265 265 if repo.OwnerID == user.ID { 266 266 return true, nil 267 267 } 268 268 269 - if err := repo.LoadOwner(db.DefaultContext); err != nil { 269 + if err := repo.LoadOwner(ctx); err != nil { 270 270 return false, err 271 271 } 272 272 273 - accessMode, err := accessLevel(db.DefaultContext, user, repo) 273 + accessMode, err := accessLevel(ctx, user, repo) 274 274 if err != nil { 275 275 return false, err 276 276 } ··· 394 394 } 395 395 396 396 // GetRepoReaders returns all users that have explicit read access or higher to the repository. 397 - func GetRepoReaders(repo *repo_model.Repository) (_ []*user_model.User, err error) { 398 - return getUsersWithAccessMode(db.DefaultContext, repo, perm_model.AccessModeRead) 397 + func GetRepoReaders(ctx context.Context, repo *repo_model.Repository) (_ []*user_model.User, err error) { 398 + return getUsersWithAccessMode(ctx, repo, perm_model.AccessModeRead) 399 399 } 400 400 401 401 // GetRepoWriters returns all users that have write access to the repository. 402 - func GetRepoWriters(repo *repo_model.Repository) (_ []*user_model.User, err error) { 403 - return getUsersWithAccessMode(db.DefaultContext, repo, perm_model.AccessModeWrite) 402 + func GetRepoWriters(ctx context.Context, repo *repo_model.Repository) (_ []*user_model.User, err error) { 403 + return getUsersWithAccessMode(ctx, repo, perm_model.AccessModeWrite) 404 404 } 405 405 406 406 // IsRepoReader returns true if user has explicit read access or higher to the repository.
+2 -2
models/repo/pushmirror.go
··· 58 58 } 59 59 60 60 // GetRepository returns the path of the repository. 61 - func (m *PushMirror) GetRepository() *Repository { 61 + func (m *PushMirror) GetRepository(ctx context.Context) *Repository { 62 62 if m.Repo != nil { 63 63 return m.Repo 64 64 } 65 65 var err error 66 - m.Repo, err = GetRepositoryByID(db.DefaultContext, m.RepoID) 66 + m.Repo, err = GetRepositoryByID(ctx, m.RepoID) 67 67 if err != nil { 68 68 log.Error("getRepositoryByID[%d]: %v", m.ID, err) 69 69 }
+4 -4
models/repo/repo_unit.go
··· 279 279 } 280 280 281 281 // UpdateRepoUnit updates the provided repo unit 282 - func UpdateRepoUnit(unit *RepoUnit) error { 283 - _, err := db.GetEngine(db.DefaultContext).ID(unit.ID).Update(unit) 282 + func UpdateRepoUnit(ctx context.Context, unit *RepoUnit) error { 283 + _, err := db.GetEngine(ctx).ID(unit.ID).Update(unit) 284 284 return err 285 285 } 286 286 287 287 // UpdateRepositoryUnits updates a repository's units 288 - func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes []unit.Type) (err error) { 289 - ctx, committer, err := db.TxContext(db.DefaultContext) 288 + func UpdateRepositoryUnits(ctx context.Context, repo *Repository, units []RepoUnit, deleteUnitTypes []unit.Type) (err error) { 289 + ctx, committer, err := db.TxContext(ctx) 290 290 if err != nil { 291 291 return err 292 292 }
+2 -2
models/system/notice.go
··· 88 88 } 89 89 90 90 // CountNotices returns number of notices. 91 - func CountNotices() int64 { 92 - count, _ := db.GetEngine(db.DefaultContext).Count(new(Notice)) 91 + func CountNotices(ctx context.Context) int64 { 92 + count, _ := db.GetEngine(ctx).Count(new(Notice)) 93 93 return count 94 94 } 95 95
+1 -1
models/system/notice_test.go
··· 49 49 50 50 func TestCountNotices(t *testing.T) { 51 51 assert.NoError(t, unittest.PrepareTestDatabase()) 52 - assert.Equal(t, int64(3), system.CountNotices()) 52 + assert.Equal(t, int64(3), system.CountNotices(db.DefaultContext)) 53 53 } 54 54 55 55 func TestNotices(t *testing.T) {
+8 -8
modules/context/org.go
··· 128 128 ctx.Org.IsTeamAdmin = true 129 129 ctx.Org.CanCreateOrgRepo = true 130 130 } else if ctx.IsSigned { 131 - ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID) 131 + ctx.Org.IsOwner, err = org.IsOwnedBy(ctx, ctx.Doer.ID) 132 132 if err != nil { 133 133 ctx.ServerError("IsOwnedBy", err) 134 134 return ··· 140 140 ctx.Org.IsTeamAdmin = true 141 141 ctx.Org.CanCreateOrgRepo = true 142 142 } else { 143 - ctx.Org.IsMember, err = org.IsOrgMember(ctx.Doer.ID) 143 + ctx.Org.IsMember, err = org.IsOrgMember(ctx, ctx.Doer.ID) 144 144 if err != nil { 145 145 ctx.ServerError("IsOrgMember", err) 146 146 return 147 147 } 148 - ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx.Doer.ID) 148 + ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx, ctx.Doer.ID) 149 149 if err != nil { 150 150 ctx.ServerError("CanCreateOrgRepo", err) 151 151 return ··· 165 165 ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled 166 166 ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled 167 167 ctx.Data["IsPublicMember"] = func(uid int64) bool { 168 - is, _ := organization.IsPublicMembership(ctx.Org.Organization.ID, uid) 168 + is, _ := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, uid) 169 169 return is 170 170 } 171 171 ctx.Data["CanCreateOrgRepo"] = ctx.Org.CanCreateOrgRepo ··· 179 179 OrgID: org.ID, 180 180 PublicOnly: ctx.Org.PublicMemberOnly, 181 181 } 182 - ctx.Data["NumMembers"], err = organization.CountOrgMembers(opts) 182 + ctx.Data["NumMembers"], err = organization.CountOrgMembers(ctx, opts) 183 183 if err != nil { 184 184 ctx.ServerError("CountOrgMembers", err) 185 185 return ··· 191 191 if ctx.Org.IsOwner { 192 192 shouldSeeAllTeams = true 193 193 } else { 194 - teams, err := org.GetUserTeams(ctx.Doer.ID) 194 + teams, err := org.GetUserTeams(ctx, ctx.Doer.ID) 195 195 if err != nil { 196 196 ctx.ServerError("GetUserTeams", err) 197 197 return ··· 204 204 } 205 205 } 206 206 if shouldSeeAllTeams { 207 - ctx.Org.Teams, err = org.LoadTeams() 207 + ctx.Org.Teams, err = org.LoadTeams(ctx) 208 208 if err != nil { 209 209 ctx.ServerError("LoadTeams", err) 210 210 return 211 211 } 212 212 } else { 213 - ctx.Org.Teams, err = org.GetUserTeams(ctx.Doer.ID) 213 + ctx.Org.Teams, err = org.GetUserTeams(ctx, ctx.Doer.ID) 214 214 if err != nil { 215 215 ctx.ServerError("GetUserTeams", err) 216 216 return
+1 -1
modules/context/package.go
··· 109 109 if doer != nil && !doer.IsGhost() { 110 110 // 1. If user is logged in, check all team packages permissions 111 111 var err error 112 - accessMode, err = org.GetOrgUserMaxAuthorizeLevel(doer.ID) 112 + accessMode, err = org.GetOrgUserMaxAuthorizeLevel(ctx, doer.ID) 113 113 if err != nil { 114 114 return accessMode, err 115 115 }
+1 -1
modules/doctor/fix16961.go
··· 290 290 return nil 291 291 } 292 292 293 - return repo_model.UpdateRepoUnit(repoUnit) 293 + return repo_model.UpdateRepoUnit(ctx, repoUnit) 294 294 }, 295 295 ) 296 296 if err != nil {
+1 -1
modules/repository/collaborator_test.go
··· 244 244 245 245 // update team information and then check permission 246 246 team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 5}) 247 - err = organization.UpdateTeamUnits(team, nil) 247 + err = organization.UpdateTeamUnits(db.DefaultContext, team, nil) 248 248 assert.NoError(t, err) 249 249 perm, err = access_model.GetUserRepoPermission(db.DefaultContext, repo, owner) 250 250 assert.NoError(t, err)
+1 -1
modules/repository/delete.go
··· 22 22 } 23 23 24 24 if repo.Owner.IsOrganization() { 25 - isAdmin, err := organization.OrgFromUser(repo.Owner).IsOrgAdmin(user.ID) 25 + isAdmin, err := organization.OrgFromUser(repo.Owner).IsOrgAdmin(ctx, user.ID) 26 26 if err != nil { 27 27 return false, err 28 28 }
+1 -1
routers/api/v1/admin/org.go
··· 62 62 Visibility: visibility, 63 63 } 64 64 65 - if err := organization.CreateOrganization(org, ctx.ContextUser); err != nil { 65 + if err := organization.CreateOrganization(ctx, org, ctx.ContextUser); err != nil { 66 66 if user_model.IsErrUserAlreadyExist(err) || 67 67 db.IsErrNameReserved(err) || 68 68 db.IsErrNameCharsNotAllowed(err) ||
+7 -7
routers/api/v1/org/member.go
··· 25 25 ListOptions: utils.GetListOptions(ctx), 26 26 } 27 27 28 - count, err := organization.CountOrgMembers(opts) 28 + count, err := organization.CountOrgMembers(ctx, opts) 29 29 if err != nil { 30 30 ctx.InternalServerError(err) 31 31 return ··· 75 75 76 76 publicOnly := true 77 77 if ctx.Doer != nil { 78 - isMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID) 78 + isMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID) 79 79 if err != nil { 80 80 ctx.Error(http.StatusInternalServerError, "IsOrgMember", err) 81 81 return ··· 144 144 return 145 145 } 146 146 if ctx.Doer != nil { 147 - userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID) 147 + userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID) 148 148 if err != nil { 149 149 ctx.Error(http.StatusInternalServerError, "IsOrgMember", err) 150 150 return 151 151 } else if userIsMember || ctx.Doer.IsAdmin { 152 - userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(userToCheck.ID) 152 + userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID) 153 153 if err != nil { 154 154 ctx.Error(http.StatusInternalServerError, "IsOrgMember", err) 155 155 } else if userToCheckIsMember { ··· 194 194 if ctx.Written() { 195 195 return 196 196 } 197 - is, err := organization.IsPublicMembership(ctx.Org.Organization.ID, userToCheck.ID) 197 + is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID) 198 198 if err != nil { 199 199 ctx.Error(http.StatusInternalServerError, "IsPublicMembership", err) 200 200 return ··· 240 240 ctx.Error(http.StatusForbidden, "", "Cannot publicize another member") 241 241 return 242 242 } 243 - err := organization.ChangeOrgUserStatus(ctx.Org.Organization.ID, userToPublicize.ID, true) 243 + err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true) 244 244 if err != nil { 245 245 ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err) 246 246 return ··· 282 282 ctx.Error(http.StatusForbidden, "", "Cannot conceal another member") 283 283 return 284 284 } 285 - err := organization.ChangeOrgUserStatus(ctx.Org.Organization.ID, userToConceal.ID, false) 285 + err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false) 286 286 if err != nil { 287 287 ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err) 288 288 return
+6 -6
routers/api/v1/org/org.go
··· 30 30 UserID: u.ID, 31 31 IncludePrivate: showPrivate, 32 32 } 33 - orgs, err := organization.FindOrgs(opts) 33 + orgs, err := organization.FindOrgs(ctx, opts) 34 34 if err != nil { 35 35 ctx.Error(http.StatusInternalServerError, "FindOrgs", err) 36 36 return 37 37 } 38 - maxResults, err := organization.CountOrgs(opts) 38 + maxResults, err := organization.CountOrgs(ctx, opts) 39 39 if err != nil { 40 40 ctx.Error(http.StatusInternalServerError, "CountOrgs", err) 41 41 return ··· 145 145 } 146 146 147 147 org := organization.OrgFromUser(o) 148 - authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx.ContextUser.ID) 148 + authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx, ctx.ContextUser.ID) 149 149 if err != nil { 150 150 ctx.Error(http.StatusInternalServerError, "GetOrgUserAuthorizeLevel", err) 151 151 return ··· 164 164 op.IsOwner = true 165 165 } 166 166 167 - op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx.ContextUser.ID) 167 + op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx, ctx.ContextUser.ID) 168 168 if err != nil { 169 169 ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err) 170 170 return ··· 268 268 Visibility: visibility, 269 269 RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess, 270 270 } 271 - if err := organization.CreateOrganization(org, ctx.Doer); err != nil { 271 + if err := organization.CreateOrganization(ctx, org, ctx.Doer); err != nil { 272 272 if user_model.IsErrUserAlreadyExist(err) || 273 273 db.IsErrNameReserved(err) || 274 274 db.IsErrNameCharsNotAllowed(err) || ··· 429 429 includePrivate = true 430 430 } else { 431 431 org := organization.OrgFromUser(ctx.ContextUser) 432 - isMember, err := org.IsOrgMember(ctx.Doer.ID) 432 + isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID) 433 433 if err != nil { 434 434 ctx.Error(http.StatusInternalServerError, "IsOrgMember", err) 435 435 return
+6 -6
routers/api/v1/repo/branch.go
··· 572 572 } 573 573 var whitelistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64 574 574 if repo.Owner.IsOrganization() { 575 - whitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false) 575 + whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false) 576 576 if err != nil { 577 577 if organization.IsErrTeamNotExist(err) { 578 578 ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) ··· 581 581 ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err) 582 582 return 583 583 } 584 - mergeWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false) 584 + mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false) 585 585 if err != nil { 586 586 if organization.IsErrTeamNotExist(err) { 587 587 ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) ··· 590 590 ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err) 591 591 return 592 592 } 593 - approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false) 593 + approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false) 594 594 if err != nil { 595 595 if organization.IsErrTeamNotExist(err) { 596 596 ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) ··· 848 848 var whitelistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64 849 849 if repo.Owner.IsOrganization() { 850 850 if form.PushWhitelistTeams != nil { 851 - whitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.PushWhitelistTeams, false) 851 + whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false) 852 852 if err != nil { 853 853 if organization.IsErrTeamNotExist(err) { 854 854 ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) ··· 861 861 whitelistTeams = protectBranch.WhitelistTeamIDs 862 862 } 863 863 if form.MergeWhitelistTeams != nil { 864 - mergeWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.MergeWhitelistTeams, false) 864 + mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false) 865 865 if err != nil { 866 866 if organization.IsErrTeamNotExist(err) { 867 867 ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err) ··· 874 874 mergeWhitelistTeams = protectBranch.MergeWhitelistTeamIDs 875 875 } 876 876 if form.ApprovalsWhitelistTeams != nil { 877 - approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(repo.OwnerID, form.ApprovalsWhitelistTeams, false) 877 + approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false) 878 878 if err != nil { 879 879 if organization.IsErrTeamNotExist(err) { 880 880 ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
+1 -1
routers/api/v1/repo/fork.go
··· 123 123 } 124 124 return 125 125 } 126 - isMember, err := org.IsOrgMember(ctx.Doer.ID) 126 + isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID) 127 127 if err != nil { 128 128 ctx.Error(http.StatusInternalServerError, "IsOrgMember", err) 129 129 return
+1 -1
routers/api/v1/repo/issue.go
··· 844 844 } 845 845 if form.State != nil { 846 846 if issue.IsPull { 847 - if pr, err := issue.GetPullRequest(); err != nil { 847 + if pr, err := issue.GetPullRequest(ctx); err != nil { 848 848 ctx.Error(http.StatusInternalServerError, "GetPullRequest", err) 849 849 return 850 850 } else if pr.HasMerged {
+1 -1
routers/api/v1/repo/issue_attachment.go
··· 178 178 filename = query 179 179 } 180 180 181 - attachment, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{ 181 + attachment, err := attachment.UploadAttachment(ctx, file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{ 182 182 Name: filename, 183 183 UploaderID: ctx.Doer.ID, 184 184 RepoID: ctx.Repo.Repository.ID,
+1 -1
routers/api/v1/repo/issue_comment_attachment.go
··· 182 182 filename = query 183 183 } 184 184 185 - attachment, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{ 185 + attachment, err := attachment.UploadAttachment(ctx, file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{ 186 186 Name: filename, 187 187 UploaderID: ctx.Doer.ID, 188 188 RepoID: ctx.Repo.Repository.ID,
+1 -1
routers/api/v1/repo/issue_pin.go
··· 241 241 242 242 apiPrs := make([]*api.PullRequest, len(issues)) 243 243 for i, currentIssue := range issues { 244 - pr, err := currentIssue.GetPullRequest() 244 + pr, err := currentIssue.GetPullRequest(ctx) 245 245 if err != nil { 246 246 ctx.Error(http.StatusInternalServerError, "GetPullRequest", err) 247 247 return
+1 -1
routers/api/v1/repo/issue_subscription.go
··· 206 206 Ignored: !watching, 207 207 Reason: nil, 208 208 CreatedAt: issue.CreatedUnix.AsTime(), 209 - URL: issue.APIURL() + "/subscriptions", 209 + URL: issue.APIURL(ctx) + "/subscriptions", 210 210 RepositoryURL: ctx.Repo.Repository.APIURL(), 211 211 }) 212 212 }
+3 -3
routers/api/v1/repo/issue_tracked_time.go
··· 283 283 return 284 284 } 285 285 286 - err = issues_model.DeleteIssueUserTimes(issue, ctx.Doer) 286 + err = issues_model.DeleteIssueUserTimes(ctx, issue, ctx.Doer) 287 287 if err != nil { 288 288 if db.IsErrNotExist(err) { 289 289 ctx.Error(http.StatusNotFound, "DeleteIssueUserTimes", err) ··· 356 356 return 357 357 } 358 358 359 - time, err := issues_model.GetTrackedTimeByID(ctx.ParamsInt64(":id")) 359 + time, err := issues_model.GetTrackedTimeByID(ctx, ctx.ParamsInt64(":id")) 360 360 if err != nil { 361 361 if db.IsErrNotExist(err) { 362 362 ctx.NotFound(err) ··· 376 376 return 377 377 } 378 378 379 - err = issues_model.DeleteTime(time) 379 + err = issues_model.DeleteTime(ctx, time) 380 380 if err != nil { 381 381 ctx.Error(http.StatusInternalServerError, "DeleteTime", err) 382 382 return
+1 -1
routers/api/v1/repo/migrate.go
··· 93 93 94 94 if repoOwner.IsOrganization() { 95 95 // Check ownership of organization. 96 - isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx.Doer.ID) 96 + isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx, ctx.Doer.ID) 97 97 if err != nil { 98 98 ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err) 99 99 return
+3 -3
routers/api/v1/repo/mirror.go
··· 176 176 177 177 responsePushMirrors := make([]*api.PushMirror, 0, len(pushMirrors)) 178 178 for _, mirror := range pushMirrors { 179 - m, err := convert.ToPushMirror(mirror) 179 + m, err := convert.ToPushMirror(ctx, mirror) 180 180 if err == nil { 181 181 responsePushMirrors = append(responsePushMirrors, m) 182 182 } ··· 232 232 ctx.Error(http.StatusNotFound, "GetPushMirrors", err) 233 233 return 234 234 } 235 - m, err := convert.ToPushMirror(pushMirror) 235 + m, err := convert.ToPushMirror(ctx, pushMirror) 236 236 if err != nil { 237 237 ctx.ServerError("GetPushMirrorByRemoteName", err) 238 238 return ··· 381 381 ctx.ServerError("AddPushMirrorRemote", err) 382 382 return 383 383 } 384 - m, err := convert.ToPushMirror(pushMirror) 384 + m, err := convert.ToPushMirror(ctx, pushMirror) 385 385 if err != nil { 386 386 ctx.ServerError("ToPushMirror", err) 387 387 return
+1 -1
routers/api/v1/repo/pull.go
··· 1442 1442 maxLines := setting.Git.MaxGitDiffLines 1443 1443 1444 1444 // FIXME: If there are too many files in the repo, may cause some unpredictable issues. 1445 - diff, err := gitdiff.GetDiff(baseGitRepo, 1445 + diff, err := gitdiff.GetDiff(ctx, baseGitRepo, 1446 1446 &gitdiff.DiffOptions{ 1447 1447 BeforeCommitID: startCommitID, 1448 1448 AfterCommitID: endCommitID,
+1 -1
routers/api/v1/repo/release_attachment.go
··· 200 200 } 201 201 202 202 // Create a new attachment and save the file 203 - attach, err := attachment.UploadAttachment(file, setting.Repository.Release.AllowedTypes, header.Size, &repo_model.Attachment{ 203 + attach, err := attachment.UploadAttachment(ctx, file, setting.Repository.Release.AllowedTypes, header.Size, &repo_model.Attachment{ 204 204 Name: filename, 205 205 UploaderID: ctx.Doer.ID, 206 206 RepoID: release.RepoID,
+3 -3
routers/api/v1/repo/repo.go
··· 396 396 } 397 397 398 398 if !ctx.Doer.IsAdmin { 399 - canCreate, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID) 399 + canCreate, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx, ctx.Doer.ID) 400 400 if err != nil { 401 401 ctx.ServerError("CanCreateOrgRepo", err) 402 402 return ··· 502 502 } 503 503 504 504 if !ctx.Doer.IsAdmin { 505 - canCreate, err := org.CanCreateOrgRepo(ctx.Doer.ID) 505 + canCreate, err := org.CanCreateOrgRepo(ctx, ctx.Doer.ID) 506 506 if err != nil { 507 507 ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err) 508 508 return ··· 982 982 } 983 983 984 984 if len(units)+len(deleteUnitTypes) > 0 { 985 - if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil { 985 + if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil { 986 986 ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err) 987 987 return err 988 988 }
+1 -1
routers/api/v1/repo/transfer.go
··· 68 68 } 69 69 70 70 if newOwner.Type == user_model.UserTypeOrganization { 71 - if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) { 71 + if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) { 72 72 // The user shouldn't know about this organization 73 73 ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found") 74 74 return
+1 -1
routers/web/admin/notice.go
··· 24 24 ctx.Data["Title"] = ctx.Tr("admin.notices") 25 25 ctx.Data["PageIsAdminNotices"] = true 26 26 27 - total := system_model.CountNotices() 27 + total := system_model.CountNotices(ctx) 28 28 page := ctx.FormInt("page") 29 29 if page <= 1 { 30 30 page = 1
+1 -1
routers/web/admin/users.go
··· 290 290 ctx.Data["Emails"] = emails 291 291 ctx.Data["EmailsTotal"] = len(emails) 292 292 293 - orgs, err := org_model.FindOrgs(org_model.FindOrgOptions{ 293 + orgs, err := org_model.FindOrgs(ctx, org_model.FindOrgOptions{ 294 294 ListOptions: db.ListOptions{ 295 295 ListAll: true, 296 296 },
+2 -2
routers/web/auth/oauth.go
··· 312 312 var groups []string 313 313 for _, org := range orgs { 314 314 groups = append(groups, org.Name) 315 - teams, err := org.LoadTeams() 315 + teams, err := org.LoadTeams(ctx) 316 316 if err != nil { 317 317 return nil, fmt.Errorf("LoadTeams: %w", err) 318 318 } 319 319 for _, team := range teams { 320 - if team.IsMember(user.ID) { 320 + if team.IsMember(ctx, user.ID) { 321 321 groups = append(groups, org.Name+":"+team.LowerName) 322 322 } 323 323 }
+5 -5
routers/web/org/members.go
··· 38 38 } 39 39 40 40 if ctx.Doer != nil { 41 - isMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID) 41 + isMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID) 42 42 if err != nil { 43 43 ctx.Error(http.StatusInternalServerError, "IsOrgMember") 44 44 return ··· 47 47 } 48 48 ctx.Data["PublicOnly"] = opts.PublicOnly 49 49 50 - total, err := organization.CountOrgMembers(opts) 50 + total, err := organization.CountOrgMembers(ctx, opts) 51 51 if err != nil { 52 52 ctx.Error(http.StatusInternalServerError, "CountOrgMembers") 53 53 return ··· 70 70 ctx.Data["Page"] = pager 71 71 ctx.Data["Members"] = members 72 72 ctx.Data["MembersIsPublicMember"] = membersIsPublic 73 - ctx.Data["MembersIsUserOrgOwner"] = organization.IsUserOrgOwner(members, org.ID) 73 + ctx.Data["MembersIsUserOrgOwner"] = organization.IsUserOrgOwner(ctx, members, org.ID) 74 74 ctx.Data["MembersTwoFaStatus"] = members.GetTwoFaStatus(ctx) 75 75 76 76 ctx.HTML(http.StatusOK, tplMembers) ··· 92 92 ctx.Error(http.StatusNotFound) 93 93 return 94 94 } 95 - err = organization.ChangeOrgUserStatus(org.ID, uid, false) 95 + err = organization.ChangeOrgUserStatus(ctx, org.ID, uid, false) 96 96 case "public": 97 97 if ctx.Doer.ID != uid && !ctx.Org.IsOwner { 98 98 ctx.Error(http.StatusNotFound) 99 99 return 100 100 } 101 - err = organization.ChangeOrgUserStatus(org.ID, uid, true) 101 + err = organization.ChangeOrgUserStatus(ctx, org.ID, uid, true) 102 102 case "remove": 103 103 if !ctx.Org.IsOwner { 104 104 ctx.Error(http.StatusNotFound)
+1 -1
routers/web/org/org.go
··· 58 58 RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess, 59 59 } 60 60 61 - if err := organization.CreateOrganization(org, ctx.Doer); err != nil { 61 + if err := organization.CreateOrganization(ctx, org, ctx.Doer); err != nil { 62 62 ctx.Data["Err_OrgName"] = true 63 63 switch { 64 64 case user_model.IsErrUserAlreadyExist(err):
+1 -1
routers/web/org/teams.go
··· 159 159 return 160 160 } 161 161 162 - if ctx.Org.Team.IsMember(u.ID) { 162 + if ctx.Org.Team.IsMember(ctx, u.ID) { 163 163 ctx.Flash.Error(ctx.Tr("org.teams.add_duplicate_users")) 164 164 } else { 165 165 err = models.AddTeamMember(ctx, ctx.Org.Team, u.ID)
+1 -1
routers/web/repo/actions/view.go
··· 608 608 cfg.DisableWorkflow(workflow) 609 609 } 610 610 611 - if err := repo_model.UpdateRepoUnit(cfgUnit); err != nil { 611 + if err := repo_model.UpdateRepoUnit(ctx, cfgUnit); err != nil { 612 612 ctx.ServerError("UpdateRepoUnit", err) 613 613 return 614 614 }
+1 -1
routers/web/repo/attachment.go
··· 45 45 } 46 46 defer file.Close() 47 47 48 - attach, err := attachment.UploadAttachment(file, allowedTypes, header.Size, &repo_model.Attachment{ 48 + attach, err := attachment.UploadAttachment(ctx, file, allowedTypes, header.Size, &repo_model.Attachment{ 49 49 Name: header.Filename, 50 50 UploaderID: ctx.Doer.ID, 51 51 RepoID: repoID,
+1 -1
routers/web/repo/commit.go
··· 305 305 maxLines, maxFiles = -1, -1 306 306 } 307 307 308 - diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{ 308 + diff, err := gitdiff.GetDiff(ctx, gitRepo, &gitdiff.DiffOptions{ 309 309 AfterCommitID: commitID, 310 310 SkipTo: ctx.FormString("skip-to"), 311 311 MaxLines: maxLines,
+1 -1
routers/web/repo/compare.go
··· 609 609 maxLines, maxFiles = -1, -1 610 610 } 611 611 612 - diff, err := gitdiff.GetDiff(ci.HeadGitRepo, 612 + diff, err := gitdiff.GetDiff(ctx, ci.HeadGitRepo, 613 613 &gitdiff.DiffOptions{ 614 614 BeforeCommitID: beforeCommitID, 615 615 AfterCommitID: headCommitID,
+7 -7
routers/web/repo/issue.go
··· 305 305 // Check read status 306 306 if !ctx.IsSigned { 307 307 issues[i].IsRead = true 308 - } else if err = issues[i].GetIsRead(ctx.Doer.ID); err != nil { 308 + } else if err = issues[i].GetIsRead(ctx, ctx.Doer.ID); err != nil { 309 309 ctx.ServerError("GetIsRead", err) 310 310 return 311 311 } ··· 1270 1270 } 1271 1271 1272 1272 // Otherwise check if poster is the real repo admin. 1273 - ok, err := access_model.IsUserRealRepoAdmin(repo, poster) 1273 + ok, err := access_model.IsUserRealRepoAdmin(ctx, repo, poster) 1274 1274 if err != nil { 1275 1275 return roleDescriptor, err 1276 1276 } ··· 1554 1554 } else { 1555 1555 ctx.Data["CanUseTimetracker"] = false 1556 1556 } 1557 - if ctx.Data["WorkingUsers"], err = issues_model.TotalTimesForEachUser(&issues_model.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil { 1557 + if ctx.Data["WorkingUsers"], err = issues_model.TotalTimesForEachUser(ctx, &issues_model.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil { 1558 1558 ctx.ServerError("TotalTimesForEachUser", err) 1559 1559 return 1560 1560 } ··· 1728 1728 comment.Type == issues_model.CommentTypeStopTracking || 1729 1729 comment.Type == issues_model.CommentTypeDeleteTimeManual { 1730 1730 // drop error since times could be pruned from DB.. 1731 - _ = comment.LoadTime() 1731 + _ = comment.LoadTime(ctx) 1732 1732 if comment.Content != "" { 1733 1733 // Content before v1.21 did store the formated string instead of seconds, 1734 1734 // so "|" is used as delimeter to mark the new format ··· 3579 3579 if ctx.Doer.IsAdmin { 3580 3580 isAdmin = true 3581 3581 } else { 3582 - isAdmin, err = org.IsOwnedBy(ctx.Doer.ID) 3582 + isAdmin, err = org.IsOwnedBy(ctx, ctx.Doer.ID) 3583 3583 if err != nil { 3584 3584 ctx.ServerError("IsOwnedBy", err) 3585 3585 return ··· 3587 3587 } 3588 3588 3589 3589 if isAdmin { 3590 - teams, err = org.LoadTeams() 3590 + teams, err = org.LoadTeams(ctx) 3591 3591 if err != nil { 3592 3592 ctx.ServerError("LoadTeams", err) 3593 3593 return 3594 3594 } 3595 3595 } else { 3596 - teams, err = org.GetUserTeams(ctx.Doer.ID) 3596 + teams, err = org.GetUserTeams(ctx, ctx.Doer.ID) 3597 3597 if err != nil { 3598 3598 ctx.ServerError("GetUserTeams", err) 3599 3599 return
+1 -1
routers/web/repo/issue_label.go
··· 85 85 return 86 86 } 87 87 if ctx.Doer != nil { 88 - ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID) 88 + ctx.Org.IsOwner, err = org.IsOwnedBy(ctx, ctx.Doer.ID) 89 89 if err != nil { 90 90 ctx.ServerError("org.IsOwnedBy", err) 91 91 return
+2 -2
routers/web/repo/issue_timetrack.go
··· 61 61 return 62 62 } 63 63 64 - t, err := issues_model.GetTrackedTimeByID(c.ParamsInt64(":timeid")) 64 + t, err := issues_model.GetTrackedTimeByID(c, c.ParamsInt64(":timeid")) 65 65 if err != nil { 66 66 if db.IsErrNotExist(err) { 67 67 c.NotFound("time not found", err) ··· 77 77 return 78 78 } 79 79 80 - if err = issues_model.DeleteTime(t); err != nil { 80 + if err = issues_model.DeleteTime(c, t); err != nil { 81 81 c.ServerError("DeleteTime", err) 82 82 return 83 83 }
+2 -2
routers/web/repo/pull.go
··· 265 265 266 266 // Check if user is allowed to create repo's on the organization. 267 267 if ctxUser.IsOrganization() { 268 - isAllowedToFork, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID) 268 + isAllowedToFork, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx, ctx.Doer.ID) 269 269 if err != nil { 270 270 ctx.ServerError("CanCreateOrgRepo", err) 271 271 return ··· 908 908 // as the viewed information is designed to be loaded only on latest PR 909 909 // diff and if you're signed in. 910 910 if !ctx.IsSigned || willShowSpecifiedCommit || willShowSpecifiedCommitRange { 911 - diff, err = gitdiff.GetDiff(gitRepo, diffOptions, files...) 911 + diff, err = gitdiff.GetDiff(ctx, gitRepo, diffOptions, files...) 912 912 methodWithError = "GetDiff" 913 913 } else { 914 914 diff, err = gitdiff.SyncAndGetUserSpecificDiff(ctx, ctx.Doer.ID, pull, gitRepo, diffOptions, files...)
+1 -1
routers/web/repo/repo.go
··· 119 119 return nil 120 120 } 121 121 if !ctx.Doer.IsAdmin { 122 - canCreate, err := organization.OrgFromUser(org).CanCreateOrgRepo(ctx.Doer.ID) 122 + canCreate, err := organization.OrgFromUser(org).CanCreateOrgRepo(ctx, ctx.Doer.ID) 123 123 if err != nil { 124 124 ctx.ServerError("CanCreateOrgRepo", err) 125 125 return nil
+2 -2
routers/web/repo/setting/protected_branch.go
··· 70 70 c.Data["PageIsSettingsBranches"] = true 71 71 c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + rule.RuleName 72 72 73 - users, err := access_model.GetRepoReaders(c.Repo.Repository) 73 + users, err := access_model.GetRepoReaders(c, c.Repo.Repository) 74 74 if err != nil { 75 75 c.ServerError("Repo.Repository.GetReaders", err) 76 76 return ··· 84 84 c.Data["recent_status_checks"] = contexts 85 85 86 86 if c.Repo.Owner.IsOrganization() { 87 - teams, err := organization.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c.Repo.Repository.ID, perm.AccessModeRead) 87 + teams, err := organization.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c, c.Repo.Repository.ID, perm.AccessModeRead) 88 88 if err != nil { 89 89 c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err) 90 90 return
+2 -2
routers/web/repo/setting/protected_tag.go
··· 147 147 } 148 148 ctx.Data["ProtectedTags"] = protectedTags 149 149 150 - users, err := access_model.GetRepoReaders(ctx.Repo.Repository) 150 + users, err := access_model.GetRepoReaders(ctx, ctx.Repo.Repository) 151 151 if err != nil { 152 152 ctx.ServerError("Repo.Repository.GetReaders", err) 153 153 return err ··· 155 155 ctx.Data["Users"] = users 156 156 157 157 if ctx.Repo.Owner.IsOrganization() { 158 - teams, err := organization.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx.Repo.Repository.ID, perm.AccessModeRead) 158 + teams, err := organization.OrgFromUser(ctx.Repo.Owner).TeamsWithAccessToRepo(ctx, ctx.Repo.Repository.ID, perm.AccessModeRead) 159 159 if err != nil { 160 160 ctx.ServerError("Repo.Owner.TeamsWithAccessToRepo", err) 161 161 return err
+2 -2
routers/web/repo/setting/setting.go
··· 594 594 return 595 595 } 596 596 597 - if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil { 597 + if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil { 598 598 ctx.ServerError("UpdateRepositoryUnits", err) 599 599 return 600 600 } ··· 761 761 } 762 762 763 763 if newOwner.Type == user_model.UserTypeOrganization { 764 - if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) { 764 + if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) { 765 765 // The user shouldn't know about this organization 766 766 ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil) 767 767 return
+2 -2
routers/web/shared/user/header.go
··· 57 57 } 58 58 59 59 showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID) 60 - orgs, err := organization.FindOrgs(organization.FindOrgOptions{ 60 + orgs, err := organization.FindOrgs(ctx, organization.FindOrgOptions{ 61 61 UserID: ctx.ContextUser.ID, 62 62 IncludePrivate: showPrivate, 63 63 }) ··· 66 66 return 67 67 } 68 68 ctx.Data["Orgs"] = orgs 69 - ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(orgs, ctx.Doer) 69 + ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(ctx, orgs, ctx.Doer) 70 70 71 71 badges, _, err := user_model.GetUserBadges(ctx, ctx.ContextUser) 72 72 if err != nil {
+2 -2
routers/web/user/setting/profile.go
··· 219 219 opts.Page = 1 220 220 } 221 221 222 - orgs, err := organization.FindOrgs(opts) 222 + orgs, err := organization.FindOrgs(ctx, opts) 223 223 if err != nil { 224 224 ctx.ServerError("FindOrgs", err) 225 225 return 226 226 } 227 - total, err := organization.CountOrgs(opts) 227 + total, err := organization.CountOrgs(ctx, opts) 228 228 if err != nil { 229 229 ctx.ServerError("CountOrgs", err) 230 230 return
+4 -4
services/attachment/attachment.go
··· 19 19 ) 20 20 21 21 // NewAttachment creates a new attachment object, but do not verify. 22 - func NewAttachment(attach *repo_model.Attachment, file io.Reader, size int64) (*repo_model.Attachment, error) { 22 + func NewAttachment(ctx context.Context, attach *repo_model.Attachment, file io.Reader, size int64) (*repo_model.Attachment, error) { 23 23 if attach.RepoID == 0 { 24 24 return nil, fmt.Errorf("attachment %s should belong to a repository", attach.Name) 25 25 } 26 26 27 - err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { 27 + err := db.WithTx(ctx, func(ctx context.Context) error { 28 28 attach.UUID = uuid.New().String() 29 29 size, err := storage.Attachments.Save(attach.RelativePath(), file, size) 30 30 if err != nil { ··· 39 39 } 40 40 41 41 // UploadAttachment upload new attachment into storage and update database 42 - func UploadAttachment(file io.Reader, allowedTypes string, fileSize int64, opts *repo_model.Attachment) (*repo_model.Attachment, error) { 42 + func UploadAttachment(ctx context.Context, file io.Reader, allowedTypes string, fileSize int64, opts *repo_model.Attachment) (*repo_model.Attachment, error) { 43 43 buf := make([]byte, 1024) 44 44 n, _ := util.ReadAtMost(file, buf) 45 45 buf = buf[:n] ··· 48 48 return nil, err 49 49 } 50 50 51 - return NewAttachment(opts, io.MultiReader(bytes.NewReader(buf), file), fileSize) 51 + return NewAttachment(ctx, opts, io.MultiReader(bytes.NewReader(buf), file), fileSize) 52 52 }
+1 -1
services/attachment/attachment_test.go
··· 32 32 assert.NoError(t, err) 33 33 defer f.Close() 34 34 35 - attach, err := NewAttachment(&repo_model.Attachment{ 35 + attach, err := NewAttachment(db.DefaultContext, &repo_model.Attachment{ 36 36 RepoID: 1, 37 37 UploaderID: user.ID, 38 38 Name: filepath.Base(fPath),
+3 -3
services/convert/convert.go
··· 119 119 if err != nil { 120 120 log.Error("GetUserNamesByIDs (ApprovalsWhitelistUserIDs): %v", err) 121 121 } 122 - pushWhitelistTeams, err := organization.GetTeamNamesByID(bp.WhitelistTeamIDs) 122 + pushWhitelistTeams, err := organization.GetTeamNamesByID(ctx, bp.WhitelistTeamIDs) 123 123 if err != nil { 124 124 log.Error("GetTeamNamesByID (WhitelistTeamIDs): %v", err) 125 125 } 126 - mergeWhitelistTeams, err := organization.GetTeamNamesByID(bp.MergeWhitelistTeamIDs) 126 + mergeWhitelistTeams, err := organization.GetTeamNamesByID(ctx, bp.MergeWhitelistTeamIDs) 127 127 if err != nil { 128 128 log.Error("GetTeamNamesByID (MergeWhitelistTeamIDs): %v", err) 129 129 } 130 - approvalsWhitelistTeams, err := organization.GetTeamNamesByID(bp.ApprovalsWhitelistTeamIDs) 130 + approvalsWhitelistTeams, err := organization.GetTeamNamesByID(ctx, bp.ApprovalsWhitelistTeamIDs) 131 131 if err != nil { 132 132 log.Error("GetTeamNamesByID (ApprovalsWhitelistTeamIDs): %v", err) 133 133 }
+1 -1
services/convert/git_commit.go
··· 210 210 211 211 // Get diff stats for commit 212 212 if opts.Stat { 213 - diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{ 213 + diff, err := gitdiff.GetDiff(ctx, gitRepo, &gitdiff.DiffOptions{ 214 214 AfterCommitID: commit.ID.String(), 215 215 }) 216 216 if err != nil {
+1 -1
services/convert/issue.go
··· 62 62 if err := issue.Repo.LoadOwner(ctx); err != nil { 63 63 return &api.Issue{} 64 64 } 65 - apiIssue.URL = issue.APIURL() 65 + apiIssue.URL = issue.APIURL(ctx) 66 66 apiIssue.HTMLURL = issue.HTMLURL() 67 67 apiIssue.Labels = ToLabelList(issue.Labels, issue.Repo, issue.Repo.Owner) 68 68 apiIssue.Repo = &api.RepositoryMeta{
+1 -1
services/convert/issue_comment.go
··· 55 55 return nil 56 56 } 57 57 58 - err = c.LoadTime() 58 + err = c.LoadTime(ctx) 59 59 if err != nil { 60 60 log.Error("LoadTime: %v", err) 61 61 return nil
+4 -2
services/convert/mirror.go
··· 4 4 package convert 5 5 6 6 import ( 7 + "context" 8 + 7 9 repo_model "code.gitea.io/gitea/models/repo" 8 10 api "code.gitea.io/gitea/modules/structs" 9 11 ) 10 12 11 13 // ToPushMirror convert from repo_model.PushMirror and remoteAddress to api.TopicResponse 12 - func ToPushMirror(pm *repo_model.PushMirror) (*api.PushMirror, error) { 13 - repo := pm.GetRepository() 14 + func ToPushMirror(ctx context.Context, pm *repo_model.PushMirror) (*api.PushMirror, error) { 15 + repo := pm.GetRepository(ctx) 14 16 return &api.PushMirror{ 15 17 RepoName: repo.Name, 16 18 RemoteName: pm.RemoteName,
+5 -5
services/convert/notification.go
··· 39 39 result.Subject = &api.NotificationSubject{Type: api.NotifySubjectIssue} 40 40 if n.Issue != nil { 41 41 result.Subject.Title = n.Issue.Title 42 - result.Subject.URL = n.Issue.APIURL() 42 + result.Subject.URL = n.Issue.APIURL(ctx) 43 43 result.Subject.HTMLURL = n.Issue.HTMLURL() 44 44 result.Subject.State = n.Issue.State() 45 - comment, err := n.Issue.GetLastComment() 45 + comment, err := n.Issue.GetLastComment(ctx) 46 46 if err == nil && comment != nil { 47 47 result.Subject.LatestCommentURL = comment.APIURL(ctx) 48 48 result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx) ··· 52 52 result.Subject = &api.NotificationSubject{Type: api.NotifySubjectPull} 53 53 if n.Issue != nil { 54 54 result.Subject.Title = n.Issue.Title 55 - result.Subject.URL = n.Issue.APIURL() 55 + result.Subject.URL = n.Issue.APIURL(ctx) 56 56 result.Subject.HTMLURL = n.Issue.HTMLURL() 57 57 result.Subject.State = n.Issue.State() 58 - comment, err := n.Issue.GetLastComment() 58 + comment, err := n.Issue.GetLastComment(ctx) 59 59 if err == nil && comment != nil { 60 60 result.Subject.LatestCommentURL = comment.APIURL(ctx) 61 61 result.Subject.LatestCommentHTMLURL = comment.HTMLURL(ctx) 62 62 } 63 63 64 - pr, _ := n.Issue.GetPullRequest() 64 + pr, _ := n.Issue.GetPullRequest(ctx) 65 65 if pr != nil && pr.HasMerged { 66 66 result.Subject.State = "merged" 67 67 }
+2 -1
services/gitdiff/csv_test.go
··· 8 8 "strings" 9 9 "testing" 10 10 11 + "code.gitea.io/gitea/models/db" 11 12 csv_module "code.gitea.io/gitea/modules/csv" 12 13 "code.gitea.io/gitea/modules/setting" 13 14 ··· 190 191 } 191 192 192 193 for n, c := range cases { 193 - diff, err := ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.diff), "") 194 + diff, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.diff), "") 194 195 if err != nil { 195 196 t.Errorf("ParsePatch failed: %s", err) 196 197 }
+11 -11
services/gitdiff/gitdiff.go
··· 494 494 const cmdDiffHead = "diff --git " 495 495 496 496 // ParsePatch builds a Diff object from a io.Reader and some parameters. 497 - func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader, skipToFile string) (*Diff, error) { 497 + func ParsePatch(ctx context.Context, maxLines, maxLineCharacters, maxFiles int, reader io.Reader, skipToFile string) (*Diff, error) { 498 498 log.Debug("ParsePatch(%d, %d, %d, ..., %s)", maxLines, maxLineCharacters, maxFiles, skipToFile) 499 499 var curFile *DiffFile 500 500 ··· 709 709 curFile.IsAmbiguous = false 710 710 } 711 711 // Otherwise do nothing with this line, but now switch to parsing hunks 712 - lineBytes, isFragment, err := parseHunks(curFile, maxLines, maxLineCharacters, input) 712 + lineBytes, isFragment, err := parseHunks(ctx, curFile, maxLines, maxLineCharacters, input) 713 713 diff.TotalAddition += curFile.Addition 714 714 diff.TotalDeletion += curFile.Deletion 715 715 if err != nil { ··· 818 818 return line, err 819 819 } 820 820 821 - func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio.Reader) (lineBytes []byte, isFragment bool, err error) { 821 + func parseHunks(ctx context.Context, curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio.Reader) (lineBytes []byte, isFragment bool, err error) { 822 822 sb := strings.Builder{} 823 823 824 824 var ( ··· 995 995 oid := strings.TrimPrefix(line[1:], lfs.MetaFileOidPrefix) 996 996 if len(oid) == 64 { 997 997 m := &git_model.LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}} 998 - count, err := db.CountByBean(db.DefaultContext, m) 998 + count, err := db.CountByBean(ctx, m) 999 999 1000 1000 if err == nil && count > 0 { 1001 1001 curFile.IsBin = true ··· 1106 1106 // GetDiff builds a Diff between two commits of a repository. 1107 1107 // Passing the empty string as beforeCommitID returns a diff from the parent commit. 1108 1108 // The whitespaceBehavior is either an empty string or a git flag 1109 - func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) { 1109 + func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) { 1110 1110 repoPath := gitRepo.Path 1111 1111 1112 1112 commit, err := gitRepo.GetCommit(opts.AfterCommitID) ··· 1165 1165 _ = writer.Close() 1166 1166 }() 1167 1167 1168 - diff, err := ParsePatch(opts.MaxLines, opts.MaxLineCharacters, opts.MaxFiles, reader, parsePatchSkipToFile) 1168 + diff, err := ParsePatch(ctx, opts.MaxLines, opts.MaxLineCharacters, opts.MaxFiles, reader, parsePatchSkipToFile) 1169 1169 if err != nil { 1170 1170 return nil, fmt.Errorf("unable to ParsePatch: %w", err) 1171 1171 } ··· 1280 1280 // SyncAndGetUserSpecificDiff is like GetDiff, except that user specific data such as which files the given user has already viewed on the given PR will also be set 1281 1281 // Additionally, the database asynchronously is updated if files have changed since the last review 1282 1282 func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.PullRequest, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) { 1283 - diff, err := GetDiff(gitRepo, opts, files...) 1283 + diff, err := GetDiff(ctx, gitRepo, opts, files...) 1284 1284 if err != nil { 1285 1285 return nil, err 1286 1286 } ··· 1347 1347 } 1348 1348 1349 1349 // CommentAsDiff returns c.Patch as *Diff 1350 - func CommentAsDiff(c *issues_model.Comment) (*Diff, error) { 1351 - diff, err := ParsePatch(setting.Git.MaxGitDiffLines, 1350 + func CommentAsDiff(ctx context.Context, c *issues_model.Comment) (*Diff, error) { 1351 + diff, err := ParsePatch(ctx, setting.Git.MaxGitDiffLines, 1352 1352 setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.Patch), "") 1353 1353 if err != nil { 1354 1354 log.Error("Unable to parse patch: %v", err) ··· 1365 1365 } 1366 1366 1367 1367 // CommentMustAsDiff executes AsDiff and logs the error instead of returning 1368 - func CommentMustAsDiff(c *issues_model.Comment) *Diff { 1368 + func CommentMustAsDiff(ctx context.Context, c *issues_model.Comment) *Diff { 1369 1369 if c == nil { 1370 1370 return nil 1371 1371 } ··· 1374 1374 log.Error("PANIC whilst retrieving diff for comment[%d] Error: %v\nStack: %s", c.ID, err, log.Stack(2)) 1375 1375 } 1376 1376 }() 1377 - diff, err := CommentAsDiff(c) 1377 + diff, err := CommentAsDiff(ctx, c) 1378 1378 if err != nil { 1379 1379 log.Warn("CommentMustAsDiff: %v", err) 1380 1380 }
+13 -13
services/gitdiff/gitdiff_test.go
··· 175 175 } 176 176 for _, testcase := range tests { 177 177 t.Run(testcase.name, func(t *testing.T) { 178 - got, err := ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), testcase.skipTo) 178 + got, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), testcase.skipTo) 179 179 if (err != nil) != testcase.wantErr { 180 180 t.Errorf("ParsePatch(%q) error = %v, wantErr %v", testcase.name, err, testcase.wantErr) 181 181 return ··· 400 400 401 401 for _, testcase := range tests { 402 402 t.Run(testcase.name, func(t *testing.T) { 403 - got, err := ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "") 403 + got, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "") 404 404 if (err != nil) != testcase.wantErr { 405 405 t.Errorf("ParsePatch(%q) error = %v, wantErr %v", testcase.name, err, testcase.wantErr) 406 406 return ··· 449 449 diffBuilder.WriteString("+line" + strconv.Itoa(i) + "\n") 450 450 } 451 451 diff = diffBuilder.String() 452 - result, err := ParsePatch(20, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 452 + result, err := ParsePatch(db.DefaultContext, 20, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 453 453 if err != nil { 454 454 t.Errorf("There should not be an error: %v", err) 455 455 } 456 456 if !result.Files[0].IsIncomplete { 457 457 t.Errorf("Files should be incomplete! %v", result.Files[0]) 458 458 } 459 - result, err = ParsePatch(40, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 459 + result, err = ParsePatch(db.DefaultContext, 40, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 460 460 if err != nil { 461 461 t.Errorf("There should not be an error: %v", err) 462 462 } 463 463 if result.Files[0].IsIncomplete { 464 464 t.Errorf("Files should not be incomplete! %v", result.Files[0]) 465 465 } 466 - result, err = ParsePatch(40, 5, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 466 + result, err = ParsePatch(db.DefaultContext, 40, 5, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 467 467 if err != nil { 468 468 t.Errorf("There should not be an error: %v", err) 469 469 } ··· 494 494 diffBuilder.WriteString("+line" + strconv.Itoa(35) + "\n") 495 495 diff = diffBuilder.String() 496 496 497 - result, err = ParsePatch(20, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 497 + result, err = ParsePatch(db.DefaultContext, 20, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 498 498 if err != nil { 499 499 t.Errorf("There should not be an error: %v", err) 500 500 } 501 501 if !result.Files[0].IsIncomplete { 502 502 t.Errorf("Files should be incomplete! %v", result.Files[0]) 503 503 } 504 - result, err = ParsePatch(40, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 504 + result, err = ParsePatch(db.DefaultContext, 40, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 505 505 if err != nil { 506 506 t.Errorf("There should not be an error: %v", err) 507 507 } ··· 520 520 Docker Pulls 521 521 + cut off 522 522 + cut off` 523 - _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 523 + _, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") 524 524 if err != nil { 525 525 t.Errorf("ParsePatch failed: %s", err) 526 526 } ··· 536 536 Docker Pulls 537 537 + cut off 538 538 + cut off` 539 - _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "") 539 + _, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "") 540 540 if err != nil { 541 541 t.Errorf("ParsePatch failed: %s", err) 542 542 } ··· 552 552 Docker Pulls 553 553 + cut off 554 554 + cut off` 555 - _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "") 555 + _, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "") 556 556 if err != nil { 557 557 t.Errorf("ParsePatch failed: %s", err) 558 558 } ··· 568 568 Docker Pulls 569 569 + cut off 570 570 + cut off` 571 - _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "") 571 + _, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "") 572 572 if err != nil { 573 573 t.Errorf("ParsePatch failed: %s", err) 574 574 } ··· 634 634 } 635 635 defer gitRepo.Close() 636 636 for _, behavior := range []git.TrustedCmdArgs{{"-w"}, {"--ignore-space-at-eol"}, {"-b"}, nil} { 637 - diffs, err := GetDiff(gitRepo, 637 + diffs, err := GetDiff(db.DefaultContext, gitRepo, 638 638 &DiffOptions{ 639 639 AfterCommitID: "bd7063cc7c04689c4d082183d32a604ed27a24f9", 640 640 BeforeCommitID: "559c156f8e0178b71cb44355428f24001b08fc68", ··· 665 665 } 666 666 for _, testcase := range tests { 667 667 // It shouldn't crash, so don't care about the output. 668 - ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "") 668 + ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "") 669 669 } 670 670 }
+1 -1
services/issue/assignee_test.go
··· 18 18 assert.NoError(t, unittest.PrepareTestDatabase()) 19 19 20 20 // Fake issue with assignees 21 - issue, err := issues_model.GetIssueWithAttrsByID(1) 21 + issue, err := issues_model.GetIssueWithAttrsByID(db.DefaultContext, 1) 22 22 assert.NoError(t, err) 23 23 assert.Len(t, issue.Assignees, 1) 24 24
+1 -1
services/mailer/incoming/incoming_handler.go
··· 87 87 attachmentIDs := make([]string, 0, len(content.Attachments)) 88 88 if setting.Attachment.Enabled { 89 89 for _, attachment := range content.Attachments { 90 - a, err := attachment_service.UploadAttachment(bytes.NewReader(attachment.Content), setting.Attachment.AllowedTypes, int64(len(attachment.Content)), &repo_model.Attachment{ 90 + a, err := attachment_service.UploadAttachment(ctx, bytes.NewReader(attachment.Content), setting.Attachment.AllowedTypes, int64(len(attachment.Content)), &repo_model.Attachment{ 91 91 Name: attachment.Name, 92 92 UploaderID: doer.ID, 93 93 RepoID: issue.Repo.ID,
+1 -1
services/migrations/gitea_uploader.go
··· 430 430 } 431 431 432 432 if len(iss) > 0 { 433 - if err := issues_model.InsertIssues(iss...); err != nil { 433 + if err := issues_model.InsertIssues(g.ctx, iss...); err != nil { 434 434 return err 435 435 } 436 436
+1 -1
services/mirror/mirror.go
··· 54 54 mirrorType = PullMirrorType 55 55 referenceID = m.RepoID 56 56 } else if m, ok := bean.(*repo_model.PushMirror); ok { 57 - if m.GetRepository() == nil { 57 + if m.GetRepository(ctx) == nil { 58 58 log.Error("Disconnected push-mirror found: %d", m.ID) 59 59 return nil 60 60 }
+3 -4
services/mirror/mirror_pull.go
··· 9 9 "strings" 10 10 "time" 11 11 12 - "code.gitea.io/gitea/models/db" 13 12 repo_model "code.gitea.io/gitea/models/repo" 14 13 system_model "code.gitea.io/gitea/models/system" 15 14 "code.gitea.io/gitea/modules/cache" ··· 461 460 } 462 461 defer gitRepo.Close() 463 462 464 - if ok := checkAndUpdateEmptyRepository(m, gitRepo, results); !ok { 463 + if ok := checkAndUpdateEmptyRepository(ctx, m, gitRepo, results); !ok { 465 464 return false 466 465 } 467 466 } ··· 550 549 return true 551 550 } 552 551 553 - func checkAndUpdateEmptyRepository(m *repo_model.Mirror, gitRepo *git.Repository, results []*mirrorSyncResult) bool { 552 + func checkAndUpdateEmptyRepository(ctx context.Context, m *repo_model.Mirror, gitRepo *git.Repository, results []*mirrorSyncResult) bool { 554 553 if !m.Repo.IsEmpty { 555 554 return true 556 555 } ··· 601 600 } 602 601 m.Repo.IsEmpty = false 603 602 // Update the is empty and default_branch columns 604 - if err := repo_model.UpdateRepositoryCols(db.DefaultContext, m.Repo, "default_branch", "is_empty"); err != nil { 603 + if err := repo_model.UpdateRepositoryCols(ctx, m.Repo, "default_branch", "is_empty"); err != nil { 605 604 log.Error("Failed to update default branch of repository %-v. Error: %v", m.Repo, err) 606 605 desc := fmt.Sprintf("Failed to update default branch of repository '%s': %v", m.Repo.RepoPath(), err) 607 606 if err = system_model.CreateRepositoryNotice(desc); err != nil {
+2 -2
services/mirror/mirror_push.go
··· 65 65 // RemovePushMirrorRemote removes the push mirror remote. 66 66 func RemovePushMirrorRemote(ctx context.Context, m *repo_model.PushMirror) error { 67 67 cmd := git.NewCommand(ctx, "remote", "rm").AddDynamicArguments(m.RemoteName) 68 - _ = m.GetRepository() 68 + _ = m.GetRepository(ctx) 69 69 70 70 if _, _, err := cmd.RunStdString(&git.RunOpts{Dir: m.Repo.RepoPath()}); err != nil { 71 71 return err ··· 99 99 return false 100 100 } 101 101 102 - _ = m.GetRepository() 102 + _ = m.GetRepository(ctx) 103 103 104 104 m.LastError = "" 105 105
+1 -1
services/pull/review.go
··· 264 264 265 265 // SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist 266 266 func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue, reviewType issues_model.ReviewType, content, commitID string, attachmentUUIDs []string) (*issues_model.Review, *issues_model.Comment, error) { 267 - pr, err := issue.GetPullRequest() 267 + pr, err := issue.GetPullRequest(ctx) 268 268 if err != nil { 269 269 return nil, nil, err 270 270 }
+2 -2
services/release/release_test.go
··· 107 107 108 108 testPlayload := "testtest" 109 109 110 - attach, err := attachment.NewAttachment(&repo_model.Attachment{ 110 + attach, err := attachment.NewAttachment(db.DefaultContext, &repo_model.Attachment{ 111 111 RepoID: repo.ID, 112 112 UploaderID: user.ID, 113 113 Name: "test.txt", ··· 241 241 242 242 // Add new attachments 243 243 samplePayload := "testtest" 244 - attach, err := attachment.NewAttachment(&repo_model.Attachment{ 244 + attach, err := attachment.NewAttachment(db.DefaultContext, &repo_model.Attachment{ 245 245 RepoID: repo.ID, 246 246 UploaderID: user.ID, 247 247 Name: "test.txt",
+1 -1
services/repository/create_test.go
··· 44 44 Type: user_model.UserTypeOrganization, 45 45 Visibility: structs.VisibleTypePublic, 46 46 } 47 - assert.NoError(t, organization.CreateOrganization(org, user), "CreateOrganization") 47 + assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, user), "CreateOrganization") 48 48 49 49 // Check Owner team. 50 50 ownerTeam, err := org.GetOwnerTeam(db.DefaultContext)
+1 -1
services/repository/files/temp_repo.go
··· 343 343 Stderr: stderr, 344 344 PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error { 345 345 _ = stdoutWriter.Close() 346 - diff, finalErr = gitdiff.ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, stdoutReader, "") 346 + diff, finalErr = gitdiff.ParsePatch(t.ctx, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, stdoutReader, "") 347 347 if finalErr != nil { 348 348 log.Error("ParsePatch: %v", finalErr) 349 349 cancel()
+1 -1
services/user/user.go
··· 189 189 // An alternative option here would be write a function which would delete all organizations but it seems 190 190 // but such a function would likely get out of date 191 191 for { 192 - orgs, err := organization.FindOrgs(organization.FindOrgOptions{ 192 + orgs, err := organization.FindOrgs(ctx, organization.FindOrgOptions{ 193 193 ListOptions: db.ListOptions{ 194 194 PageSize: repo_model.RepositoryListDefaultPageSize, 195 195 Page: 1,
+1 -1
services/wiki/wiki.go
··· 350 350 351 351 // DeleteWiki removes the actual and local copy of repository wiki. 352 352 func DeleteWiki(ctx context.Context, repo *repo_model.Repository) error { 353 - if err := repo_model.UpdateRepositoryUnits(repo, nil, []unit.Type{unit.TypeWiki}); err != nil { 353 + if err := repo_model.UpdateRepositoryUnits(ctx, repo, nil, []unit.Type{unit.TypeWiki}); err != nil { 354 354 return err 355 355 } 356 356
+1 -1
templates/org/team/sidebar.tmpl
··· 2 2 <h4 class="ui top attached header"> 3 3 <strong>{{.Team.Name}}</strong> 4 4 <div class="ui right"> 5 - {{if .Team.IsMember $.SignedUser.ID}} 5 + {{if .Team.IsMember ctx $.SignedUser.ID}} 6 6 <form> 7 7 <button class="ui red tiny button delete-button" data-modal-id="leave-team-sidebar" 8 8 data-url="{{.OrgLink}}/teams/{{.Team.LowerName | PathEscape}}/action/leave" data-datauid="{{$.SignedUser.ID}}"
+1 -1
templates/org/team/teams.tmpl
··· 16 16 <div class="ui top attached header"> 17 17 <a class="text black" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}"><strong>{{.Name}}</strong></a> 18 18 <div class="ui right"> 19 - {{if .IsMember $.SignedUser.ID}} 19 + {{if .IsMember ctx $.SignedUser.ID}} 20 20 <form> 21 21 <button class="ui red tiny button delete-button" data-modal-id="leave-team" 22 22 data-url="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}/action/leave" data-datauid="{{$.SignedUser.ID}}"
+2 -2
templates/shared/issueicon.tmpl
··· 1 1 {{if .IsPull}} 2 2 {{if and .PullRequest .PullRequest.HasMerged}} 3 3 {{svg "octicon-git-merge" 16 "text purple"}} 4 - {{else if and .GetPullRequest .GetPullRequest.HasMerged}} 4 + {{else if and (.GetPullRequest ctx) (.GetPullRequest ctx).HasMerged}} 5 5 {{svg "octicon-git-merge" 16 "text purple"}} 6 6 {{else}} 7 7 {{if .IsClosed}} ··· 9 9 {{else}} 10 10 {{if and .PullRequest .PullRequest.IsWorkInProgress}} 11 11 {{svg "octicon-git-pull-request-draft" 16 "text grey"}} 12 - {{else if and .GetPullRequest .GetPullRequest.IsWorkInProgress}} 12 + {{else if and (.GetPullRequest ctx) (.GetPullRequest ctx).IsWorkInProgress}} 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
tests/integration/actions_trigger_test.go
··· 45 45 assert.NotEmpty(t, baseRepo) 46 46 47 47 // enable actions 48 - err = repo_model.UpdateRepositoryUnits(baseRepo, []repo_model.RepoUnit{{ 48 + err = repo_model.UpdateRepositoryUnits(db.DefaultContext, baseRepo, []repo_model.RepoUnit{{ 49 49 RepoID: baseRepo.ID, 50 50 Type: unit_model.TypeActions, 51 51 }}, nil)
+2 -1
tests/integration/api_issue_subscription_test.go
··· 9 9 "testing" 10 10 11 11 auth_model "code.gitea.io/gitea/models/auth" 12 + "code.gitea.io/gitea/models/db" 12 13 issues_model "code.gitea.io/gitea/models/issues" 13 14 repo_model "code.gitea.io/gitea/models/repo" 14 15 "code.gitea.io/gitea/models/unittest" ··· 44 45 45 46 assert.EqualValues(t, isWatching, wi.Subscribed) 46 47 assert.EqualValues(t, !isWatching, wi.Ignored) 47 - assert.EqualValues(t, issue.APIURL()+"/subscriptions", wi.URL) 48 + assert.EqualValues(t, issue.APIURL(db.DefaultContext)+"/subscriptions", wi.URL) 48 49 assert.EqualValues(t, issue.CreatedUnix, wi.CreatedAt.Unix()) 49 50 assert.EqualValues(t, issueRepo.APIURL(), wi.RepositoryURL) 50 51 }
+1 -1
tests/integration/api_notification_test.go
··· 100 100 assert.True(t, apiN.Unread) 101 101 assert.EqualValues(t, "issue4", apiN.Subject.Title) 102 102 assert.EqualValues(t, "Issue", apiN.Subject.Type) 103 - assert.EqualValues(t, thread5.Issue.APIURL(), apiN.Subject.URL) 103 + assert.EqualValues(t, thread5.Issue.APIURL(db.DefaultContext), apiN.Subject.URL) 104 104 assert.EqualValues(t, thread5.Repository.HTMLURL(), apiN.Repository.HTMLURL) 105 105 106 106 MakeRequest(t, NewRequest(t, "GET", "/api/v1/notifications/new"), http.StatusUnauthorized)
+2 -2
tests/integration/auth_ldap_test.go
··· 414 414 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ 415 415 Name: gitLDAPUser.UserName, 416 416 }) 417 - usersOrgs, err := organization.FindOrgs(organization.FindOrgOptions{ 417 + usersOrgs, err := organization.FindOrgs(db.DefaultContext, organization.FindOrgOptions{ 418 418 UserID: user.ID, 419 419 IncludePrivate: true, 420 420 }) ··· 458 458 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ 459 459 Name: gitLDAPUsers[0].UserName, 460 460 }) 461 - err = organization.AddOrgUser(org.ID, user.ID) 461 + err = organization.AddOrgUser(db.DefaultContext, org.ID, user.ID) 462 462 assert.NoError(t, err) 463 463 err = models.AddTeamMember(db.DefaultContext, team, user.ID) 464 464 assert.NoError(t, err)
+2 -1
tests/integration/org_count_test.go
··· 9 9 "testing" 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/organization" 13 14 "code.gitea.io/gitea/models/unittest" 14 15 user_model "code.gitea.io/gitea/models/user" ··· 117 118 Name: username, 118 119 }) 119 120 120 - orgs, err := organization.FindOrgs(organization.FindOrgOptions{ 121 + orgs, err := organization.FindOrgs(db.DefaultContext, organization.FindOrgOptions{ 121 122 UserID: user.ID, 122 123 IncludePrivate: true, 123 124 })