diff options
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/packages/conan/auth.go | 2 | ||||
-rw-r--r-- | routers/api/packages/container/auth.go | 2 | ||||
-rw-r--r-- | routers/api/packages/nuget/auth.go | 2 | ||||
-rw-r--r-- | routers/api/v1/org/team.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/fork.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/hook.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_comment.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/key.go | 13 | ||||
-rw-r--r-- | routers/api/v1/repo/migrate.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 20 | ||||
-rw-r--r-- | routers/api/v1/repo/status.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/transfer.go | 8 | ||||
-rw-r--r-- | routers/api/v1/user/key.go | 3 | ||||
-rw-r--r-- | routers/api/v1/user/repo.go | 4 | ||||
-rw-r--r-- | routers/api/v1/user/star.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/watch.go | 2 |
18 files changed, 43 insertions, 41 deletions
diff --git a/routers/api/packages/conan/auth.go b/routers/api/packages/conan/auth.go index fe33e2c740..f3adaf7bee 100644 --- a/routers/api/packages/conan/auth.go +++ b/routers/api/packages/conan/auth.go @@ -30,7 +30,7 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS return nil } - u, err := user_model.GetUserByID(uid) + u, err := user_model.GetUserByID(req.Context(), uid) if err != nil { log.Error("GetUserByID: %v", err) return nil diff --git a/routers/api/packages/container/auth.go b/routers/api/packages/container/auth.go index 948001dcad..e134f74c8f 100644 --- a/routers/api/packages/container/auth.go +++ b/routers/api/packages/container/auth.go @@ -34,7 +34,7 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS return user_model.NewGhostUser() } - u, err := user_model.GetUserByID(uid) + u, err := user_model.GetUserByID(req.Context(), uid) if err != nil { log.Error("GetUserByID: %v", err) return nil diff --git a/routers/api/packages/nuget/auth.go b/routers/api/packages/nuget/auth.go index 2be102a38b..890c930184 100644 --- a/routers/api/packages/nuget/auth.go +++ b/routers/api/packages/nuget/auth.go @@ -29,7 +29,7 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS return nil } - u, err := user_model.GetUserByID(token.UID) + u, err := user_model.GetUserByID(req.Context(), token.UID) if err != nil { log.Error("GetUserByID: %v", err) return nil diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index f233494fa5..798b792e71 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -546,7 +546,7 @@ func GetTeamRepos(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err) return } - repos[i] = convert.ToRepo(repo, access) + repos[i] = convert.ToRepo(ctx, repo, access) } ctx.SetTotalCountHeader(int64(team.NumRepos)) ctx.JSON(http.StatusOK, repos) @@ -598,7 +598,7 @@ func GetTeamRepo(ctx *context.APIContext) { return } - ctx.JSON(http.StatusOK, convert.ToRepo(repo, access)) + ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, access)) } // getRepositoryByParams get repository by a team's organization ID and repo name diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index e2cb4400f5..f2cd10e711 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -63,7 +63,7 @@ func ListForks(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "AccessLevel", err) return } - apiForks[i] = convert.ToRepo(fork, access) + apiForks[i] = convert.ToRepo(ctx, fork, access) } ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumForks)) @@ -150,5 +150,5 @@ func CreateFork(ctx *context.APIContext) { } // TODO change back to 201 - ctx.JSON(http.StatusAccepted, convert.ToRepo(fork, perm.AccessModeOwner)) + ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx, fork, perm.AccessModeOwner)) } diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go index 9b84fb2b30..0c3d59a419 100644 --- a/routers/api/v1/repo/hook.go +++ b/routers/api/v1/repo/hook.go @@ -184,7 +184,7 @@ func TestHook(ctx *context.APIContext) { Commits: []*api.PayloadCommit{commit}, TotalCommits: 1, HeadCommit: commit, - Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone), + Repo: convert.ToRepo(ctx, ctx.Repo.Repository, perm.AccessModeNone), Pusher: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone), Sender: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone), }); err != nil { diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index c539a36238..30dc7a6832 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -623,7 +623,7 @@ func CreateIssue(ctx *context.APIContext) { // Check if the passed assignees is assignable for _, aID := range assigneeIDs { - assignee, err := user_model.GetUserByID(aID) + assignee, err := user_model.GetUserByID(ctx, aID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserByID", err) return diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 7f6f24605d..120c1d88a0 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -199,7 +199,7 @@ func isXRefCommentAccessible(ctx stdCtx.Context, user *user_model.User, c *issue if issues_model.CommentTypeIsRef(c.Type) && c.RefRepoID != issueRepoID && c.RefRepoID != 0 { var err error // Set RefRepo for description in template - c.RefRepo, err = repo_model.GetRepositoryByIDCtx(ctx, c.RefRepoID) + c.RefRepo, err = repo_model.GetRepositoryByID(ctx, c.RefRepoID) if err != nil { return false } diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index cff6850469..54313e8e76 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -5,6 +5,7 @@ package repo import ( + stdCtx "context" "fmt" "net/http" "net/url" @@ -23,16 +24,16 @@ import ( ) // appendPrivateInformation appends the owner and key type information to api.PublicKey -func appendPrivateInformation(apiKey *api.DeployKey, key *asymkey_model.DeployKey, repository *repo_model.Repository) (*api.DeployKey, error) { +func appendPrivateInformation(ctx stdCtx.Context, apiKey *api.DeployKey, key *asymkey_model.DeployKey, repository *repo_model.Repository) (*api.DeployKey, error) { apiKey.ReadOnly = key.Mode == perm.AccessModeRead if repository.ID == key.RepoID { - apiKey.Repository = convert.ToRepo(repository, key.Mode) + apiKey.Repository = convert.ToRepo(ctx, repository, key.Mode) } else { - repo, err := repo_model.GetRepositoryByID(key.RepoID) + repo, err := repo_model.GetRepositoryByID(ctx, key.RepoID) if err != nil { return apiKey, err } - apiKey.Repository = convert.ToRepo(repo, key.Mode) + apiKey.Repository = convert.ToRepo(ctx, repo, key.Mode) } return apiKey, nil } @@ -107,7 +108,7 @@ func ListDeployKeys(ctx *context.APIContext) { } apiKeys[i] = convert.ToDeployKey(apiLink, keys[i]) if ctx.Doer.IsAdmin || ((ctx.Repo.Repository.ID == keys[i].RepoID) && (ctx.Doer.ID == ctx.Repo.Owner.ID)) { - apiKeys[i], _ = appendPrivateInformation(apiKeys[i], keys[i], ctx.Repo.Repository) + apiKeys[i], _ = appendPrivateInformation(ctx, apiKeys[i], keys[i], ctx.Repo.Repository) } } @@ -161,7 +162,7 @@ func GetDeployKey(ctx *context.APIContext) { apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) apiKey := convert.ToDeployKey(apiLink, key) if ctx.Doer.IsAdmin || ((ctx.Repo.Repository.ID == key.RepoID) && (ctx.Doer.ID == ctx.Repo.Owner.ID)) { - apiKey, _ = appendPrivateInformation(apiKey, key, ctx.Repo.Repository) + apiKey, _ = appendPrivateInformation(ctx, apiKey, key, ctx.Repo.Repository) } ctx.JSON(http.StatusOK, apiKey) } diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index a0316c9a78..35516ff58f 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -66,7 +66,7 @@ func Migrate(ctx *context.APIContext) { if len(form.RepoOwner) != 0 { repoOwner, err = user_model.GetUserByName(ctx, form.RepoOwner) } else if form.RepoOwnerID != 0 { - repoOwner, err = user_model.GetUserByID(form.RepoOwnerID) + repoOwner, err = user_model.GetUserByID(ctx, form.RepoOwnerID) } else { repoOwner = ctx.Doer } @@ -211,7 +211,7 @@ func Migrate(ctx *context.APIContext) { } log.Trace("Repository migrated: %s/%s", repoOwner.Name, form.RepoName) - ctx.JSON(http.StatusCreated, convert.ToRepo(repo, perm.AccessModeAdmin)) + ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, perm.AccessModeAdmin)) } func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, remoteAddr string, err error) { diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 53505e998c..1246ede9e6 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -399,7 +399,7 @@ func CreatePullRequest(ctx *context.APIContext) { } // Check if the passed assignees is assignable for _, aID := range assigneeIDs { - assignee, err := user_model.GetUserByIDCtx(ctx, aID) + assignee, err := user_model.GetUserByID(ctx, aID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserByID", err) return diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index e8603d1917..3b55b496a9 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -215,7 +215,7 @@ func Search(ctx *context.APIContext) { Error: err.Error(), }) } - results[i] = convert.ToRepo(repo, accessMode) + results[i] = convert.ToRepo(ctx, repo, accessMode) } ctx.SetLinkHeader(int(count), opts.PageSize) ctx.SetTotalCountHeader(count) @@ -257,12 +257,12 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre } // reload repo from db to get a real state after creation - repo, err = repo_model.GetRepositoryByID(repo.ID) + repo, err = repo_model.GetRepositoryByID(ctx, repo.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err) } - ctx.JSON(http.StatusCreated, convert.ToRepo(repo, perm.AccessModeOwner)) + ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, perm.AccessModeOwner)) } // Create one repository of mine @@ -407,7 +407,7 @@ func Generate(ctx *context.APIContext) { } log.Trace("Repository generated [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name) - ctx.JSON(http.StatusCreated, convert.ToRepo(repo, perm.AccessModeOwner)) + ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, perm.AccessModeOwner)) } // CreateOrgRepoDeprecated create one repository of the organization @@ -523,7 +523,7 @@ func Get(ctx *context.APIContext) { return } - ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode)) + ctx.JSON(http.StatusOK, convert.ToRepo(ctx, ctx.Repo.Repository, ctx.Repo.AccessMode)) } // GetByID returns a single Repository @@ -544,7 +544,7 @@ func GetByID(ctx *context.APIContext) { // "200": // "$ref": "#/responses/Repository" - repo, err := repo_model.GetRepositoryByID(ctx.ParamsInt64(":id")) + repo, err := repo_model.GetRepositoryByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if repo_model.IsErrRepoNotExist(err) { ctx.NotFound() @@ -562,7 +562,7 @@ func GetByID(ctx *context.APIContext) { ctx.NotFound() return } - ctx.JSON(http.StatusOK, convert.ToRepo(repo, perm.AccessMode)) + ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, perm.AccessMode)) } // Edit edit repository properties @@ -618,13 +618,13 @@ func Edit(ctx *context.APIContext) { } } - repo, err := repo_model.GetRepositoryByID(ctx.Repo.Repository.ID) + repo, err := repo_model.GetRepositoryByID(ctx, ctx.Repo.Repository.ID) if err != nil { ctx.InternalServerError(err) return } - ctx.JSON(http.StatusOK, convert.ToRepo(repo, ctx.Repo.AccessMode)) + ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, ctx.Repo.AccessMode)) } // updateBasicProperties updates the basic properties of a repo: Name, Description, Website and Visibility @@ -669,7 +669,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err if opts.Private != nil { // Visibility of forked repository is forced sync with base repository. if repo.IsFork { - if err := repo.GetBaseRepo(); err != nil { + if err := repo.GetBaseRepo(ctx); err != nil { ctx.Error(http.StatusInternalServerError, "Unable to load base repository", err) return err } diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index 84827a91ad..0b196d162c 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -66,7 +66,7 @@ func NewCommitStatus(ctx *context.APIContext) { return } - ctx.JSON(http.StatusCreated, convert.ToCommitStatus(status)) + ctx.JSON(http.StatusCreated, convert.ToCommitStatus(ctx, status)) } // GetCommitStatuses returns all statuses for any given commit hash @@ -199,7 +199,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { apiStatuses := make([]*api.CommitStatus, 0, len(statuses)) for _, status := range statuses { - apiStatuses = append(apiStatuses, convert.ToCommitStatus(status)) + apiStatuses = append(apiStatuses, convert.ToCommitStatus(ctx, status)) } ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) @@ -263,7 +263,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { return } - combiStatus := convert.ToCombinedStatus(statuses, convert.ToRepo(repo, ctx.Repo.AccessMode)) + combiStatus := convert.ToCombinedStatus(ctx, statuses, convert.ToRepo(ctx, repo, ctx.Repo.AccessMode)) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, combiStatus) diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index a40419e13e..fb15566a4b 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -122,12 +122,12 @@ func Transfer(ctx *context.APIContext) { if ctx.Repo.Repository.Status == repo_model.RepositoryPendingTransfer { log.Trace("Repository transfer initiated: %s -> %s", oldFullname, ctx.Repo.Repository.FullName()) - ctx.JSON(http.StatusCreated, convert.ToRepo(ctx.Repo.Repository, perm.AccessModeAdmin)) + ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, ctx.Repo.Repository, perm.AccessModeAdmin)) return } log.Trace("Repository transferred: %s -> %s", oldFullname, ctx.Repo.Repository.FullName()) - ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx.Repo.Repository, perm.AccessModeAdmin)) + ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx, ctx.Repo.Repository, perm.AccessModeAdmin)) } // AcceptTransfer accept a repo transfer @@ -165,7 +165,7 @@ func AcceptTransfer(ctx *context.APIContext) { return } - ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode)) + ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx, ctx.Repo.Repository, ctx.Repo.AccessMode)) } // RejectTransfer reject a repo transfer @@ -203,7 +203,7 @@ func RejectTransfer(ctx *context.APIContext) { return } - ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode)) + ctx.JSON(http.StatusOK, convert.ToRepo(ctx, ctx.Repo.Repository, ctx.Repo.AccessMode)) } func acceptOrRejectRepoTransfer(ctx *context.APIContext, accept bool) error { diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index d00eec85e4..25bda0444a 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -7,6 +7,7 @@ import ( "net/http" asymkey_model "code.gitea.io/gitea/models/asymkey" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" @@ -29,7 +30,7 @@ func appendPrivateInformation(apiKey *api.PublicKey, key *asymkey_model.PublicKe if defaultUser.ID == key.OwnerID { apiKey.Owner = convert.ToUser(defaultUser, defaultUser) } else { - user, err := user_model.GetUserByID(key.OwnerID) + user, err := user_model.GetUserByID(db.DefaultContext, key.OwnerID) if err != nil { return apiKey, err } diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 2af70f9ad3..e79a9d8f8b 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -44,7 +44,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { return } if ctx.IsSigned && ctx.Doer.IsAdmin || access >= perm.AccessModeRead { - apiRepos = append(apiRepos, convert.ToRepo(repos[i], access)) + apiRepos = append(apiRepos, convert.ToRepo(ctx, repos[i], access)) } } @@ -127,7 +127,7 @@ func ListMyRepos(ctx *context.APIContext) { if err != nil { ctx.Error(http.StatusInternalServerError, "AccessLevel", err) } - results[i] = convert.ToRepo(repo, accessMode) + results[i] = convert.ToRepo(ctx, repo, accessMode) } ctx.SetLinkHeader(int(count), opts.ListOptions.PageSize) diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 2ef5806974..0475489640 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -32,7 +32,7 @@ func getStarredRepos(ctx std_context.Context, user *user_model.User, private boo if err != nil { return nil, err } - repos[i] = convert.ToRepo(starred, access) + repos[i] = convert.ToRepo(ctx, starred, access) } return repos, nil } diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index 43c097444e..707e5da090 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -30,7 +30,7 @@ func getWatchedRepos(ctx std_context.Context, user *user_model.User, private boo if err != nil { return nil, 0, err } - repos[i] = convert.ToRepo(watched, access) + repos[i] = convert.ToRepo(ctx, watched, access) } return repos, total, nil } |