Skip to content

Show Org-level Project in Repo-projects list #33830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions routers/web/repo/projects.go
Original file line number Diff line number Diff line change
@@ -62,21 +62,21 @@ func Projects(ctx *context.Context) {
keyword := ctx.FormTrim("q")
repo := ctx.Repo.Repository
page := ctx.FormInt("page")
ownerID := repo.OwnerID
if page <= 1 {
page = 1
}

ctx.Data["OpenCount"] = repo.NumOpenProjects
ctx.Data["ClosedCount"] = repo.NumClosedProjects

var total int
if !isShowClosed {
total = repo.NumOpenProjects
} else {
total = repo.NumClosedProjects
}

projects, count, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
projects := make([]*project_model.Project, 0, total)

repoProjects, count, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
ListOptions: db.ListOptions{
PageSize: setting.UI.IssuePagingNum,
Page: page,
@@ -88,10 +88,59 @@ func Projects(ctx *context.Context) {
Title: keyword,
})
if err != nil {
ctx.ServerError("GetProjects", err)
ctx.ServerError("GetRepoProjects", err)
return
}

projects = append(projects, repoProjects...)

openOrgProjects, openCountForOrgProjects, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
ListOptions: db.ListOptions{
PageSize: setting.UI.IssuePagingNum,
Page: page,
},
OwnerID: ownerID,
IsClosed: optional.Some(false),
OrderBy: project_model.GetSearchOrderByBySortType(sortType),
Type: project_model.TypeOrganization,
Title: keyword,
})
if err != nil {
ctx.ServerError("GetOrgProjects", err)
return
}

closeOrgProjects, closeCountForOrgProjects, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to load both open and closed org projects?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it maybe necessary, you need to get the number of open projects and closed projects, in previous logic you can just get repo level projects other than org level projects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use db.Count for those non-current selected org level projects rather than db.FindAndCount.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-03-10 at 10 05 22 AM i mean even if you use db.count, still need to get the number of open projects and closed projects

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I mean. For open state, you can use db.FindAndCount get opened projects and use db.Count for closed number. For close state, you can use db.FindAndCount get closed projects and use db.Count for opened.

ListOptions: db.ListOptions{
PageSize: setting.UI.IssuePagingNum,
Page: page,
},
OwnerID: ownerID,
IsClosed: optional.Some(true),
OrderBy: project_model.GetSearchOrderByBySortType(sortType),
Type: project_model.TypeOrganization,
Title: keyword,
})
if err != nil {
ctx.ServerError("GetOrgProjects", err)
return
}

if isShowClosed {
count += closeCountForOrgProjects
total += int(closeCountForOrgProjects)
projects = append(projects, closeOrgProjects...)
} else {
count += openCountForOrgProjects
total += int(openCountForOrgProjects)
projects = append(projects, openOrgProjects...)
}

totalOpenCount := repo.NumOpenProjects + int(openCountForOrgProjects)
totalCloseCount := repo.NumClosedProjects + int(closeCountForOrgProjects)
ctx.Data["OpenCount"] = totalOpenCount
ctx.Data["ClosedCount"] = totalCloseCount

if err := project_service.LoadIssueNumbersForProjects(ctx, projects, ctx.Doer); err != nil {
ctx.ServerError("LoadIssueNumbersForProjects", err)
return