Skip to content

Commit 84d31bc

Browse files
authored
A small refactor to use context in the service layer (go-gitea#35179)
1 parent c3f5ea3 commit 84d31bc

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ func GetPullCommits(ctx *context.Context) {
581581
}
582582
resp := &pullCommitList{}
583583

584-
commits, lastReviewCommitSha, err := pull_service.GetPullCommits(ctx, issue)
584+
commits, lastReviewCommitSha, err := pull_service.GetPullCommits(ctx, ctx.Repo.GitRepo, ctx.Doer, issue)
585585
if err != nil {
586586
ctx.JSON(http.StatusInternalServerError, err)
587587
return

services/pull/pull.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
repo_module "code.gitea.io/gitea/modules/repository"
3434
"code.gitea.io/gitea/modules/setting"
3535
"code.gitea.io/gitea/modules/util"
36-
gitea_context "code.gitea.io/gitea/services/context"
3736
issue_service "code.gitea.io/gitea/services/issue"
3837
notify_service "code.gitea.io/gitea/services/notify"
3938
)
@@ -1065,11 +1064,9 @@ type CommitInfo struct {
10651064
// GetPullCommits returns all commits on given pull request and the last review commit sha
10661065
// Attention: The last review commit sha must be from the latest review whose commit id is not empty.
10671066
// So the type of the latest review cannot be "ReviewTypeRequest".
1068-
func GetPullCommits(ctx *gitea_context.Context, issue *issues_model.Issue) ([]CommitInfo, string, error) {
1067+
func GetPullCommits(ctx context.Context, baseGitRepo *git.Repository, doer *user_model.User, issue *issues_model.Issue) ([]CommitInfo, string, error) {
10691068
pull := issue.PullRequest
10701069

1071-
baseGitRepo := ctx.Repo.GitRepo
1072-
10731070
if err := pull.LoadBaseRepo(ctx); err != nil {
10741071
return nil, "", err
10751072
}
@@ -1105,11 +1102,11 @@ func GetPullCommits(ctx *gitea_context.Context, issue *issues_model.Issue) ([]Co
11051102
}
11061103

11071104
var lastReviewCommitID string
1108-
if ctx.IsSigned {
1105+
if doer != nil {
11091106
// get last review of current user and store information in context (if available)
11101107
lastreview, err := issues_model.FindLatestReviews(ctx, issues_model.FindReviewOptions{
11111108
IssueID: issue.ID,
1112-
ReviewerID: ctx.Doer.ID,
1109+
ReviewerID: doer.ID,
11131110
Types: []issues_model.ReviewType{
11141111
issues_model.ReviewTypeApprove,
11151112
issues_model.ReviewTypeComment,

0 commit comments

Comments
 (0)