aboutsummaryrefslogtreecommitdiffstats
path: root/modules/convert
diff options
context:
space:
mode:
Diffstat (limited to 'modules/convert')
-rw-r--r--modules/convert/convert.go5
-rw-r--r--modules/convert/issue.go2
-rw-r--r--modules/convert/issue_comment.go6
-rw-r--r--modules/convert/notification.go3
-rw-r--r--modules/convert/package.go2
-rw-r--r--modules/convert/pull.go4
-rw-r--r--modules/convert/pull_test.go2
-rw-r--r--modules/convert/repository.go11
-rw-r--r--modules/convert/status.go10
9 files changed, 25 insertions, 20 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index 107854e013..756a1f95d9 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -5,6 +5,7 @@
package convert
import (
+ "context"
"fmt"
"strconv"
"strings"
@@ -408,8 +409,8 @@ func ToOAuth2Application(app *auth.OAuth2Application) *api.OAuth2Application {
}
// ToLFSLock convert a LFSLock to api.LFSLock
-func ToLFSLock(l *git_model.LFSLock) *api.LFSLock {
- u, err := user_model.GetUserByID(l.OwnerID)
+func ToLFSLock(ctx context.Context, l *git_model.LFSLock) *api.LFSLock {
+ u, err := user_model.GetUserByID(ctx, l.OwnerID)
if err != nil {
return nil
}
diff --git a/modules/convert/issue.go b/modules/convert/issue.go
index ff3466cb3f..221aeb885a 100644
--- a/modules/convert/issue.go
+++ b/modules/convert/issue.go
@@ -149,7 +149,7 @@ func ToStopWatches(sws []*issues_model.Stopwatch) (api.StopWatches, error) {
}
repo, ok = repoCache[issue.RepoID]
if !ok {
- repo, err = repo_model.GetRepositoryByID(issue.RepoID)
+ repo, err = repo_model.GetRepositoryByID(db.DefaultContext, issue.RepoID)
if err != nil {
return nil, err
}
diff --git a/modules/convert/issue_comment.go b/modules/convert/issue_comment.go
index 81cd1ac245..c4fed6b8a1 100644
--- a/modules/convert/issue_comment.go
+++ b/modules/convert/issue_comment.go
@@ -138,15 +138,15 @@ func ToTimelineComment(ctx context.Context, c *issues_model.Comment, doer *user_
var repo *repo_model.Repository
if c.Label.BelongsToOrg() {
var err error
- org, err = user_model.GetUserByIDCtx(ctx, c.Label.OrgID)
+ org, err = user_model.GetUserByID(ctx, c.Label.OrgID)
if err != nil {
- log.Error("GetUserByIDCtx(%d): %v", c.Label.OrgID, err)
+ log.Error("GetUserByID(%d): %v", c.Label.OrgID, err)
return nil
}
}
if c.Label.BelongsToRepo() {
var err error
- repo, err = repo_model.GetRepositoryByIDCtx(ctx, c.Label.RepoID)
+ repo, err = repo_model.GetRepositoryByID(ctx, c.Label.RepoID)
if err != nil {
log.Error("GetRepositoryByIDCtx(%d): %v", c.Label.RepoID, err)
return nil
diff --git a/modules/convert/notification.go b/modules/convert/notification.go
index 49a1b148fb..5d3b078a25 100644
--- a/modules/convert/notification.go
+++ b/modules/convert/notification.go
@@ -7,6 +7,7 @@ import (
"net/url"
activities_model "code.gitea.io/gitea/models/activities"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
api "code.gitea.io/gitea/modules/structs"
)
@@ -23,7 +24,7 @@ func ToNotificationThread(n *activities_model.Notification) *api.NotificationThr
// since user only get notifications when he has access to use minimal access mode
if n.Repository != nil {
- result.Repository = ToRepo(n.Repository, perm.AccessModeRead)
+ result.Repository = ToRepo(db.DefaultContext, n.Repository, perm.AccessModeRead)
// This permission is not correct and we should not be reporting it
for repository := result.Repository; repository != nil; repository = repository.Parent {
diff --git a/modules/convert/package.go b/modules/convert/package.go
index 900f1dd816..68ae6f4e62 100644
--- a/modules/convert/package.go
+++ b/modules/convert/package.go
@@ -22,7 +22,7 @@ func ToPackage(ctx context.Context, pd *packages.PackageDescriptor, doer *user_m
}
if permission.HasAccess() {
- repo = ToRepo(pd.Repository, permission.AccessMode)
+ repo = ToRepo(ctx, pd.Repository, permission.AccessMode)
}
}
diff --git a/modules/convert/pull.go b/modules/convert/pull.go
index 4291d737a4..db0add6cde 100644
--- a/modules/convert/pull.go
+++ b/modules/convert/pull.go
@@ -79,7 +79,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
Name: pr.BaseBranch,
Ref: pr.BaseBranch,
RepoID: pr.BaseRepoID,
- Repository: ToRepo(pr.BaseRepo, p.AccessMode),
+ Repository: ToRepo(ctx, pr.BaseRepo, p.AccessMode),
},
Head: &api.PRBranchInfo{
Name: pr.HeadBranch,
@@ -139,7 +139,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
}
apiPullRequest.Head.RepoID = pr.HeadRepo.ID
- apiPullRequest.Head.Repository = ToRepo(pr.HeadRepo, p.AccessMode)
+ apiPullRequest.Head.Repository = ToRepo(ctx, pr.HeadRepo, p.AccessMode)
headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
if err != nil {
diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go
index 21d410cfcb..0915d096e6 100644
--- a/modules/convert/pull_test.go
+++ b/modules/convert/pull_test.go
@@ -31,7 +31,7 @@ func TestPullRequest_APIFormat(t *testing.T) {
Ref: "refs/pull/2/head",
Sha: "4a357436d925b5c974181ff12a994538ddc5a269",
RepoID: 1,
- Repository: ToRepo(headRepo, perm.AccessModeRead),
+ Repository: ToRepo(db.DefaultContext, headRepo, perm.AccessModeRead),
}, apiPullRequest.Head)
// withOut HeadRepo
diff --git a/modules/convert/repository.go b/modules/convert/repository.go
index 3c75f588fd..843556e1b1 100644
--- a/modules/convert/repository.go
+++ b/modules/convert/repository.go
@@ -4,6 +4,7 @@
package convert
import (
+ "context"
"time"
"code.gitea.io/gitea/models"
@@ -16,11 +17,11 @@ import (
)
// ToRepo converts a Repository to api.Repository
-func ToRepo(repo *repo_model.Repository, mode perm.AccessMode) *api.Repository {
- return innerToRepo(repo, mode, false)
+func ToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.AccessMode) *api.Repository {
+ return innerToRepo(ctx, repo, mode, false)
}
-func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent bool) *api.Repository {
+func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.AccessMode, isParent bool) *api.Repository {
var parent *api.Repository
cloneLink := repo.CloneLink()
@@ -30,12 +31,12 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
Pull: mode >= perm.AccessModeRead,
}
if !isParent {
- err := repo.GetBaseRepo()
+ err := repo.GetBaseRepo(ctx)
if err != nil {
return nil
}
if repo.BaseRepo != nil {
- parent = innerToRepo(repo.BaseRepo, mode, true)
+ parent = innerToRepo(ctx, repo.BaseRepo, mode, true)
}
}
diff --git a/modules/convert/status.go b/modules/convert/status.go
index 5eb38ad063..5fcf04074f 100644
--- a/modules/convert/status.go
+++ b/modules/convert/status.go
@@ -4,13 +4,15 @@
package convert
import (
+ "context"
+
git_model "code.gitea.io/gitea/models/git"
user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
)
// ToCommitStatus converts git_model.CommitStatus to api.CommitStatus
-func ToCommitStatus(status *git_model.CommitStatus) *api.CommitStatus {
+func ToCommitStatus(ctx context.Context, status *git_model.CommitStatus) *api.CommitStatus {
apiStatus := &api.CommitStatus{
Created: status.CreatedUnix.AsTime(),
Updated: status.CreatedUnix.AsTime(),
@@ -23,7 +25,7 @@ func ToCommitStatus(status *git_model.CommitStatus) *api.CommitStatus {
}
if status.CreatorID != 0 {
- creator, _ := user_model.GetUserByID(status.CreatorID)
+ creator, _ := user_model.GetUserByID(ctx, status.CreatorID)
apiStatus.Creator = ToUser(creator, nil)
}
@@ -31,7 +33,7 @@ func ToCommitStatus(status *git_model.CommitStatus) *api.CommitStatus {
}
// ToCombinedStatus converts List of CommitStatus to a CombinedStatus
-func ToCombinedStatus(statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus {
+func ToCombinedStatus(ctx context.Context, statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus {
if len(statuses) == 0 {
return nil
}
@@ -45,7 +47,7 @@ func ToCombinedStatus(statuses []*git_model.CommitStatus, repo *api.Repository)
retStatus.Statuses = make([]*api.CommitStatus, 0, len(statuses))
for _, status := range statuses {
- retStatus.Statuses = append(retStatus.Statuses, ToCommitStatus(status))
+ retStatus.Statuses = append(retStatus.Statuses, ToCommitStatus(ctx, status))
if status.State.NoBetterThan(retStatus.State) {
retStatus.State = status.State
}