Skip to content

Commit

Permalink
Move some functions from issue.go to standalone files (#32468)
Browse files Browse the repository at this point in the history
Just functions move, no code change.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
  • Loading branch information
lunny and wxiaoguang authored Nov 11, 2024
1 parent 43c252d commit a1892cf
Show file tree
Hide file tree
Showing 8 changed files with 3,497 additions and 3,345 deletions.
3,544 changes: 199 additions & 3,345 deletions routers/web/repo/issue.go

Large diffs are not rendered by default.

472 changes: 472 additions & 0 deletions routers/web/repo/issue_comment.go

Large diffs are not rendered by default.

882 changes: 882 additions & 0 deletions routers/web/repo/issue_list.go

Large diffs are not rendered by default.

403 changes: 403 additions & 0 deletions routers/web/repo/issue_new.go

Large diffs are not rendered by default.

444 changes: 444 additions & 0 deletions routers/web/repo/issue_page_meta.go

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions routers/web/repo/issue_poster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package repo

import (
"net/http"
"slices"
"strings"

repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
shared_user "code.gitea.io/gitea/routers/web/shared/user"
"code.gitea.io/gitea/services/context"
)

type userSearchInfo struct {
UserID int64 `json:"user_id"`
UserName string `json:"username"`
AvatarLink string `json:"avatar_link"`
FullName string `json:"full_name"`
}

type userSearchResponse struct {
Results []*userSearchInfo `json:"results"`
}

// IssuePosters get posters for current repo's issues/pull requests
func IssuePosters(ctx *context.Context) {
issuePosters(ctx, false)
}

func PullPosters(ctx *context.Context) {
issuePosters(ctx, true)
}

func issuePosters(ctx *context.Context, isPullList bool) {
repo := ctx.Repo.Repository
search := strings.TrimSpace(ctx.FormString("q"))
posters, err := repo_model.GetIssuePostersWithSearch(ctx, repo, isPullList, search, setting.UI.DefaultShowFullName)
if err != nil {
ctx.JSON(http.StatusInternalServerError, err)
return
}

if search == "" && ctx.Doer != nil {
// the returned posters slice only contains limited number of users,
// to make the current user (doer) can quickly filter their own issues, always add doer to the posters slice
if !slices.ContainsFunc(posters, func(user *user_model.User) bool { return user.ID == ctx.Doer.ID }) {
posters = append(posters, ctx.Doer)
}
}

posters = shared_user.MakeSelfOnTop(ctx.Doer, posters)

resp := &userSearchResponse{}
resp.Results = make([]*userSearchInfo, len(posters))
for i, user := range posters {
resp.Results[i] = &userSearchInfo{UserID: user.ID, UserName: user.Name, AvatarLink: user.AvatarLink(ctx)}
if setting.UI.DefaultShowFullName {
resp.Results[i].FullName = user.FullName
}
}
ctx.JSON(http.StatusOK, resp)
}
Loading

0 comments on commit a1892cf

Please # to comment.