Skip to content

Commit 46226d3

Browse files
authored
Merge branch 'main' into tense-past
2 parents 2a4fe6e + 2902d1e commit 46226d3

File tree

23 files changed

+92
-91
lines changed

23 files changed

+92
-91
lines changed

models/issues/assignees.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U
6363
}
6464

6565
// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
66-
func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
67-
ctx, committer, err := db.TxContext(db.DefaultContext)
66+
func ToggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
67+
ctx, committer, err := db.TxContext(ctx)
6868
if err != nil {
6969
return false, nil, err
7070
}

models/issues/assignees_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ func TestUpdateAssignee(t *testing.T) {
2424
// Assign multiple users
2525
user2, err := user_model.GetUserByID(db.DefaultContext, 2)
2626
assert.NoError(t, err)
27-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user2.ID)
27+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user2.ID)
2828
assert.NoError(t, err)
2929

3030
user3, err := user_model.GetUserByID(db.DefaultContext, 3)
3131
assert.NoError(t, err)
32-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user3.ID)
32+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user3.ID)
3333
assert.NoError(t, err)
3434

3535
user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
3636
assert.NoError(t, err)
37-
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user1.ID)
37+
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user1.ID)
3838
assert.NoError(t, err)
3939

4040
// Check if he got removed

models/issues/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User,
743743
}
744744

745745
// ChangeIssueTitle changes the title of this issue, as the given user.
746-
func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err error) {
747-
ctx, committer, err := db.TxContext(db.DefaultContext)
746+
func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User, oldTitle string) (err error) {
747+
ctx, committer, err := db.TxContext(ctx)
748748
if err != nil {
749749
return err
750750
}

models/issues/issue_xref_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestXRef_NeuterCrossReferences(t *testing.T) {
8383

8484
d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
8585
i.Title = "title2, no mentions"
86-
assert.NoError(t, issues_model.ChangeIssueTitle(i, d, title))
86+
assert.NoError(t, issues_model.ChangeIssueTitle(db.DefaultContext, i, d, title))
8787

8888
ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: itarget.ID, RefIssueID: i.ID, RefCommentID: 0})
8989
assert.Equal(t, issues_model.CommentTypeIssueRef, ref.Type)

models/repo/topic.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,16 @@ func (opts *FindTopicOptions) toConds() builder.Cond {
194194
// FindTopics retrieves the topics via FindTopicOptions
195195
func FindTopics(opts *FindTopicOptions) ([]*Topic, int64, error) {
196196
sess := db.GetEngine(db.DefaultContext).Select("topic.*").Where(opts.toConds())
197+
orderBy := "topic.repo_count DESC"
197198
if opts.RepoID > 0 {
198199
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
200+
orderBy = "topic.name" // when render topics for a repo, it's better to sort them by name, to get consistent result
199201
}
200202
if opts.PageSize != 0 && opts.Page != 0 {
201203
sess = db.SetSessionPagination(sess, opts)
202204
}
203205
topics := make([]*Topic, 0, 10)
204-
total, err := sess.Desc("topic.repo_count").FindAndCount(&topics)
206+
total, err := sess.OrderBy(orderBy).FindAndCount(&topics)
205207
return topics, total, err
206208
}
207209

modules/indexer/issues/meilisearch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package issues
66
import (
77
"context"
88
"strconv"
9+
"strings"
910
"sync"
1011
"time"
1112

@@ -120,10 +121,11 @@ func (b *MeilisearchIndexer) Delete(ids ...int64) error {
120121
// Search searches for issues by given conditions.
121122
// Returns the matching issue IDs
122123
func (b *MeilisearchIndexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int) (*SearchResult, error) {
123-
filter := make([][]string, 0, len(repoIDs))
124+
repoFilters := make([]string, 0, len(repoIDs))
124125
for _, repoID := range repoIDs {
125-
filter = append(filter, []string{"repo_id = " + strconv.FormatInt(repoID, 10)})
126+
repoFilters = append(repoFilters, "repo_id = "+strconv.FormatInt(repoID, 10))
126127
}
128+
filter := strings.Join(repoFilters, " OR ")
127129
searchRes, err := b.client.Index(b.indexerName).Search(keyword, &meilisearch.SearchRequest{
128130
Filter: filter,
129131
Limit: int64(limit),

routers/api/v1/repo/issue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ func CreateIssue(ctx *context.APIContext) {
651651
form.Labels = make([]int64, 0)
652652
}
653653

654-
if err := issue_service.NewIssue(ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs); err != nil {
654+
if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs); err != nil {
655655
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
656656
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
657657
return
@@ -752,7 +752,7 @@ func EditIssue(ctx *context.APIContext) {
752752
issue.Content = *form.Body
753753
}
754754
if form.Ref != nil {
755-
err = issue_service.ChangeIssueRef(issue, ctx.Doer, *form.Ref)
755+
err = issue_service.ChangeIssueRef(ctx, issue, ctx.Doer, *form.Ref)
756756
if err != nil {
757757
ctx.Error(http.StatusInternalServerError, "UpdateRef", err)
758758
return
@@ -790,7 +790,7 @@ func EditIssue(ctx *context.APIContext) {
790790
oneAssignee = *form.Assignee
791791
}
792792

793-
err = issue_service.UpdateAssignees(issue, oneAssignee, form.Assignees, ctx.Doer)
793+
err = issue_service.UpdateAssignees(ctx, issue, oneAssignee, form.Assignees, ctx.Doer)
794794
if err != nil {
795795
ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
796796
return
@@ -887,7 +887,7 @@ func DeleteIssue(ctx *context.APIContext) {
887887
return
888888
}
889889

890-
if err = issue_service.DeleteIssue(ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
890+
if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
891891
ctx.Error(http.StatusInternalServerError, "DeleteIssueByID", err)
892892
return
893893
}

routers/api/v1/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func EditPullRequest(ctx *context.APIContext) {
534534
// Send an empty array ([]) to clear all assignees from the Issue.
535535

536536
if ctx.Repo.CanWrite(unit.TypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) {
537-
err = issue_service.UpdateAssignees(issue, form.Assignee, form.Assignees, ctx.Doer)
537+
err = issue_service.UpdateAssignees(ctx, issue, form.Assignee, form.Assignees, ctx.Doer)
538538
if err != nil {
539539
if user_model.IsErrUserNotExist(err) {
540540
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))

routers/api/v1/repo/pull_review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
706706
}
707707

708708
for _, reviewer := range reviewers {
709-
comment, err := issue_service.ReviewRequest(pr.Issue, ctx.Doer, reviewer, isAdd)
709+
comment, err := issue_service.ReviewRequest(ctx, pr.Issue, ctx.Doer, reviewer, isAdd)
710710
if err != nil {
711711
ctx.Error(http.StatusInternalServerError, "ReviewRequest", err)
712712
return
@@ -750,7 +750,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
750750
}
751751

752752
for _, teamReviewer := range teamReviewers {
753-
comment, err := issue_service.TeamReviewRequest(pr.Issue, ctx.Doer, teamReviewer, isAdd)
753+
comment, err := issue_service.TeamReviewRequest(ctx, pr.Issue, ctx.Doer, teamReviewer, isAdd)
754754
if err != nil {
755755
ctx.ServerError("TeamReviewRequest", err)
756756
return

routers/web/repo/blame.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
repo_model "code.gitea.io/gitea/models/repo"
1414
user_model "code.gitea.io/gitea/models/user"
15-
"code.gitea.io/gitea/modules/base"
1615
"code.gitea.io/gitea/modules/charset"
1716
"code.gitea.io/gitea/modules/context"
1817
"code.gitea.io/gitea/modules/git"
@@ -23,10 +22,6 @@ import (
2322
"code.gitea.io/gitea/modules/util"
2423
)
2524

26-
const (
27-
tplBlame base.TplName = "repo/home"
28-
)
29-
3025
type blameRow struct {
3126
RowNumber int
3227
Avatar gotemplate.HTML
@@ -140,7 +135,7 @@ func RefBlame(ctx *context.Context) {
140135

141136
renderBlame(ctx, blameParts, commitNames, previousCommits)
142137

143-
ctx.HTML(http.StatusOK, tplBlame)
138+
ctx.HTML(http.StatusOK, tplRepoHome)
144139
}
145140

146141
func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*user_model.UserCommit, map[string]string) {

0 commit comments

Comments
 (0)