1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-01 15:18:37 +00:00

A small refactor to use context in the service layer (#35179)

This commit is contained in:
Lunny Xiao
2025-07-31 11:43:54 +08:00
committed by GitHub
parent c3f5ea3b1f
commit 84d31bc842
2 changed files with 4 additions and 7 deletions

View File

@@ -581,7 +581,7 @@ func GetPullCommits(ctx *context.Context) {
} }
resp := &pullCommitList{} resp := &pullCommitList{}
commits, lastReviewCommitSha, err := pull_service.GetPullCommits(ctx, issue) commits, lastReviewCommitSha, err := pull_service.GetPullCommits(ctx, ctx.Repo.GitRepo, ctx.Doer, issue)
if err != nil { if err != nil {
ctx.JSON(http.StatusInternalServerError, err) ctx.JSON(http.StatusInternalServerError, err)
return return

View File

@@ -33,7 +33,6 @@ import (
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
gitea_context "code.gitea.io/gitea/services/context"
issue_service "code.gitea.io/gitea/services/issue" issue_service "code.gitea.io/gitea/services/issue"
notify_service "code.gitea.io/gitea/services/notify" notify_service "code.gitea.io/gitea/services/notify"
) )
@@ -1065,11 +1064,9 @@ type CommitInfo struct {
// GetPullCommits returns all commits on given pull request and the last review commit sha // GetPullCommits returns all commits on given pull request and the last review commit sha
// Attention: The last review commit sha must be from the latest review whose commit id is not empty. // Attention: The last review commit sha must be from the latest review whose commit id is not empty.
// So the type of the latest review cannot be "ReviewTypeRequest". // So the type of the latest review cannot be "ReviewTypeRequest".
func GetPullCommits(ctx *gitea_context.Context, issue *issues_model.Issue) ([]CommitInfo, string, error) { func GetPullCommits(ctx context.Context, baseGitRepo *git.Repository, doer *user_model.User, issue *issues_model.Issue) ([]CommitInfo, string, error) {
pull := issue.PullRequest pull := issue.PullRequest
baseGitRepo := ctx.Repo.GitRepo
if err := pull.LoadBaseRepo(ctx); err != nil { if err := pull.LoadBaseRepo(ctx); err != nil {
return nil, "", err return nil, "", err
} }
@@ -1105,11 +1102,11 @@ func GetPullCommits(ctx *gitea_context.Context, issue *issues_model.Issue) ([]Co
} }
var lastReviewCommitID string var lastReviewCommitID string
if ctx.IsSigned { if doer != nil {
// get last review of current user and store information in context (if available) // get last review of current user and store information in context (if available)
lastreview, err := issues_model.FindLatestReviews(ctx, issues_model.FindReviewOptions{ lastreview, err := issues_model.FindLatestReviews(ctx, issues_model.FindReviewOptions{
IssueID: issue.ID, IssueID: issue.ID,
ReviewerID: ctx.Doer.ID, ReviewerID: doer.ID,
Types: []issues_model.ReviewType{ Types: []issues_model.ReviewType{
issues_model.ReviewTypeApprove, issues_model.ReviewTypeApprove,
issues_model.ReviewTypeComment, issues_model.ReviewTypeComment,