-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Show package count in header #26467
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
Show package count in header #26467
Changes from all commits
bbec567
22b9d49
4d19b4c
67657f2
9623b96
36785f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
git_model "code.gitea.io/gitea/models/git" | ||
issues_model "code.gitea.io/gitea/models/issues" | ||
"code.gitea.io/gitea/models/organization" | ||
packages_model "code.gitea.io/gitea/models/packages" | ||
"code.gitea.io/gitea/models/perm" | ||
access_model "code.gitea.io/gitea/models/perm/access" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
|
@@ -283,6 +284,8 @@ func ToDeployKey(apiLink string, key *asymkey_model.DeployKey) *api.DeployKey { | |
|
||
// ToOrganization convert user_model.User to api.Organization | ||
func ToOrganization(ctx context.Context, org *organization.Organization) *api.Organization { | ||
numPackages, _ := packages_model.CountLatestVersions(ctx, &packages_model.PackageSearchOptions{OwnerID: org.ID, IsInternal: util.OptionalBoolFalse}) | ||
Comment on lines
286
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks really strange and not at all how the code should be structured. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To the API response in general: The Number is shown on the Profile, so it should also be returned by the API, so 3rd Party Apps can add this Feature easily. As we don't show Issues or Milestones on the profile, there is no need to return a count. To the location: There are also other places in the convert API ehere databse querrys are done, but I can move it to the User7org Modell and add a |
||
|
||
return &api.Organization{ | ||
ID: org.ID, | ||
AvatarURL: org.AsUser().AvatarLink(ctx), | ||
|
@@ -295,6 +298,7 @@ func ToOrganization(ctx context.Context, org *organization.Organization) *api.Or | |
Location: org.Location, | ||
Visibility: org.Visibility.String(), | ||
RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess, | ||
Packages: int(numPackages), | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,14 @@ import ( | |
"time" | ||
|
||
"code.gitea.io/gitea/models" | ||
packages_model "code.gitea.io/gitea/models/packages" | ||
"code.gitea.io/gitea/models/perm" | ||
access_model "code.gitea.io/gitea/models/perm/access" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
unit_model "code.gitea.io/gitea/models/unit" | ||
"code.gitea.io/gitea/modules/log" | ||
api "code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
||
// ToRepo converts a Repository to api.Repository | ||
|
@@ -135,6 +137,12 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR | |
|
||
numReleases, _ := repo_model.GetReleaseCountByRepoID(ctx, repo.ID, repo_model.FindReleasesOptions{IncludeDrafts: false, IncludeTags: false}) | ||
|
||
numPackages, _ := packages_model.CountLatestVersions(ctx, &packages_model.PackageSearchOptions{ | ||
OwnerID: repo.Owner.ID, | ||
RepoID: repo.ID, | ||
IsInternal: util.OptionalBoolFalse, | ||
}) | ||
|
||
mirrorInterval := "" | ||
var mirrorUpdated time.Time | ||
if repo.IsMirror { | ||
|
@@ -193,6 +201,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR | |
OpenIssues: repo.NumOpenIssues, | ||
OpenPulls: repo.NumOpenPulls, | ||
Releases: int(numReleases), | ||
Packages: int(numPackages), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. |
||
DefaultBranch: repo.DefaultBranch, | ||
Created: repo.CreatedUnix.AsTime(), | ||
Updated: repo.UpdatedUnix.AsTime(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ package convert | |
import ( | ||
"context" | ||
|
||
packages_model "code.gitea.io/gitea/models/packages" | ||
"code.gitea.io/gitea/models/perm" | ||
user_model "code.gitea.io/gitea/models/user" | ||
api "code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
||
// ToUser convert user_model.User to api.User | ||
|
@@ -47,6 +49,8 @@ func ToUserWithAccessMode(ctx context.Context, user *user_model.User, accessMode | |
// toUser convert user_model.User to api.User | ||
// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself | ||
func toUser(ctx context.Context, user *user_model.User, signed, authed bool) *api.User { | ||
numPackages, _ := packages_model.CountLatestVersions(ctx, &packages_model.PackageSearchOptions{OwnerID: user.ID, IsInternal: util.OptionalBoolFalse}) | ||
|
||
result := &api.User{ | ||
ID: user.ID, | ||
UserName: user.Name, | ||
|
@@ -62,6 +66,7 @@ func toUser(ctx context.Context, user *user_model.User, signed, authed bool) *ap | |
Followers: user.NumFollowers, | ||
Following: user.NumFollowing, | ||
StarredRepos: user.NumStars, | ||
Packages: int(numPackages), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. |
||
} | ||
|
||
result.Visibility = user.Visibility.String() | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs a serious refactoring.
A
modules/context
file, which is one of the most essential files in the hierarchy, should not depend onmodels
andservices
…But that's not a problem for this PR.