Skip to content

Commit a1892cf

Browse files
lunnywxiaoguang
andauthored
Move some functions from issue.go to standalone files (#32468)
Just functions move, no code change. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 43c252d commit a1892cf

File tree

8 files changed

+3497
-3345
lines changed

8 files changed

+3497
-3345
lines changed

routers/web/repo/issue.go

Lines changed: 199 additions & 3345 deletions
Large diffs are not rendered by default.

routers/web/repo/issue_comment.go

Lines changed: 472 additions & 0 deletions
Large diffs are not rendered by default.

routers/web/repo/issue_list.go

Lines changed: 882 additions & 0 deletions
Large diffs are not rendered by default.

routers/web/repo/issue_new.go

Lines changed: 403 additions & 0 deletions
Large diffs are not rendered by default.

routers/web/repo/issue_page_meta.go

Lines changed: 444 additions & 0 deletions
Large diffs are not rendered by default.

routers/web/repo/issue_poster.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repo
5+
6+
import (
7+
"net/http"
8+
"slices"
9+
"strings"
10+
11+
repo_model "code.gitea.io/gitea/models/repo"
12+
user_model "code.gitea.io/gitea/models/user"
13+
"code.gitea.io/gitea/modules/setting"
14+
shared_user "code.gitea.io/gitea/routers/web/shared/user"
15+
"code.gitea.io/gitea/services/context"
16+
)
17+
18+
type userSearchInfo struct {
19+
UserID int64 `json:"user_id"`
20+
UserName string `json:"username"`
21+
AvatarLink string `json:"avatar_link"`
22+
FullName string `json:"full_name"`
23+
}
24+
25+
type userSearchResponse struct {
26+
Results []*userSearchInfo `json:"results"`
27+
}
28+
29+
// IssuePosters get posters for current repo's issues/pull requests
30+
func IssuePosters(ctx *context.Context) {
31+
issuePosters(ctx, false)
32+
}
33+
34+
func PullPosters(ctx *context.Context) {
35+
issuePosters(ctx, true)
36+
}
37+
38+
func issuePosters(ctx *context.Context, isPullList bool) {
39+
repo := ctx.Repo.Repository
40+
search := strings.TrimSpace(ctx.FormString("q"))
41+
posters, err := repo_model.GetIssuePostersWithSearch(ctx, repo, isPullList, search, setting.UI.DefaultShowFullName)
42+
if err != nil {
43+
ctx.JSON(http.StatusInternalServerError, err)
44+
return
45+
}
46+
47+
if search == "" && ctx.Doer != nil {
48+
// the returned posters slice only contains limited number of users,
49+
// to make the current user (doer) can quickly filter their own issues, always add doer to the posters slice
50+
if !slices.ContainsFunc(posters, func(user *user_model.User) bool { return user.ID == ctx.Doer.ID }) {
51+
posters = append(posters, ctx.Doer)
52+
}
53+
}
54+
55+
posters = shared_user.MakeSelfOnTop(ctx.Doer, posters)
56+
57+
resp := &userSearchResponse{}
58+
resp.Results = make([]*userSearchInfo, len(posters))
59+
for i, user := range posters {
60+
resp.Results[i] = &userSearchInfo{UserID: user.ID, UserName: user.Name, AvatarLink: user.AvatarLink(ctx)}
61+
if setting.UI.DefaultShowFullName {
62+
resp.Results[i].FullName = user.FullName
63+
}
64+
}
65+
ctx.JSON(http.StatusOK, resp)
66+
}

0 commit comments

Comments
 (0)