Skip to content

Commit 2635ada

Browse files
authored
Merge branch 'main' into lunny/system_hook_api
2 parents a61d04e + 151b1a9 commit 2635ada

File tree

16 files changed

+84
-18
lines changed

16 files changed

+84
-18
lines changed

models/issues/comment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ func (t CommentType) String() string {
175175
return commentStrings[t]
176176
}
177177

178+
func AsCommentType(typeName string) CommentType {
179+
for index, name := range commentStrings {
180+
if typeName == name {
181+
return CommentType(index)
182+
}
183+
}
184+
return CommentTypeUnknown
185+
}
186+
178187
// RoleDescriptor defines comment tag type
179188
type RoleDescriptor int
180189

models/issues/comment_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ func TestFetchCodeComments(t *testing.T) {
6262
assert.NoError(t, err)
6363
assert.Len(t, res, 1)
6464
}
65+
66+
func TestAsCommentType(t *testing.T) {
67+
assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType(""))
68+
assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType("nonsense"))
69+
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
70+
assert.Equal(t, issues_model.CommentTypePRUnScheduledToAutoMerge, issues_model.AsCommentType("pull_cancel_scheduled_merge"))
71+
}

models/packages/package_blob.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ func DeleteBlobByID(ctx context.Context, blobID int64) error {
8585
}
8686

8787
// GetTotalBlobSize returns the total blobs size in bytes
88-
func GetTotalBlobSize() (int64, error) {
89-
return db.GetEngine(db.DefaultContext).
88+
func GetTotalBlobSize(ctx context.Context) (int64, error) {
89+
return db.GetEngine(ctx).
90+
SumInt(&PackageBlob{}, "size")
91+
}
92+
93+
// GetTotalUnreferencedBlobSize returns the total size of all unreferenced blobs in bytes
94+
func GetTotalUnreferencedBlobSize(ctx context.Context) (int64, error) {
95+
return db.GetEngine(ctx).
96+
Table("package_blob").
97+
Join("LEFT", "package_file", "package_file.blob_id = package_blob.id").
98+
Where("package_file.id IS NULL").
9099
SumInt(&PackageBlob{}, "size")
91100
}

models/packages/package_file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ func SearchFiles(ctx context.Context, opts *PackageFileSearchOptions) ([]*Packag
199199
return pfs, count, err
200200
}
201201

202-
// CalculateBlobSize sums up all blob sizes matching the search options.
202+
// CalculateFileSize sums up all blob sizes matching the search options.
203203
// It does NOT respect the deduplication of blobs.
204-
func CalculateBlobSize(ctx context.Context, opts *PackageFileSearchOptions) (int64, error) {
204+
func CalculateFileSize(ctx context.Context, opts *PackageFileSearchOptions) (int64, error) {
205205
return db.GetEngine(ctx).
206206
Table("package_file").
207207
Where(opts.toConds()).

models/user/user.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,10 @@ func GetUserByOpenID(uri string) (*User, error) {
12331233
// GetAdminUser returns the first administrator
12341234
func GetAdminUser() (*User, error) {
12351235
var admin User
1236-
has, err := db.GetEngine(db.DefaultContext).Where("is_admin=?", true).Get(&admin)
1236+
has, err := db.GetEngine(db.DefaultContext).
1237+
Where("is_admin=?", true).
1238+
Asc("id"). // Reliably get the admin with the lowest ID.
1239+
Get(&admin)
12371240
if err != nil {
12381241
return nil, err
12391242
} else if !has {

modules/migration/comment.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ type Commentable interface {
1717
type Comment struct {
1818
IssueIndex int64 `yaml:"issue_index"`
1919
Index int64
20+
CommentType string `yaml:"comment_type"` // see `commentStrings` in models/issues/comment.go
2021
PosterID int64 `yaml:"poster_id"`
2122
PosterName string `yaml:"poster_name"`
2223
PosterEmail string `yaml:"poster_email"`
2324
Created time.Time
2425
Updated time.Time
2526
Content string
2627
Reactions []*Reaction
28+
Meta map[string]interface{} `yaml:"meta,omitempty"` // see models/issues/comment.go for fields in Comment struct
2729
}
2830

2931
// GetExternalName ExternalUserMigrated interface

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,7 @@ repos.size = Size
26452645
26462646
packages.package_manage_panel = Package Management
26472647
packages.total_size = Total Size: %s
2648+
packages.unreferenced_size = Unreferenced Size: %s
26482649
packages.owner = Owner
26492650
packages.creator = Creator
26502651
packages.name = Name

routers/web/admin/packages.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ func Packages(ctx *context.Context) {
5151
return
5252
}
5353

54-
totalBlobSize, err := packages_model.GetTotalBlobSize()
54+
totalBlobSize, err := packages_model.GetTotalBlobSize(ctx)
5555
if err != nil {
5656
ctx.ServerError("GetTotalBlobSize", err)
5757
return
5858
}
5959

60+
totalUnreferencedBlobSize, err := packages_model.GetTotalUnreferencedBlobSize(ctx)
61+
if err != nil {
62+
ctx.ServerError("CalculateBlobSize", err)
63+
return
64+
}
65+
6066
ctx.Data["Title"] = ctx.Tr("packages.title")
6167
ctx.Data["PageIsAdmin"] = true
6268
ctx.Data["PageIsAdminPackages"] = true
@@ -65,8 +71,9 @@ func Packages(ctx *context.Context) {
6571
ctx.Data["AvailableTypes"] = packages_model.TypeList
6672
ctx.Data["SortType"] = sort
6773
ctx.Data["PackageDescriptors"] = pds
68-
ctx.Data["Total"] = total
69-
ctx.Data["TotalBlobSize"] = totalBlobSize
74+
ctx.Data["TotalCount"] = total
75+
ctx.Data["TotalBlobSize"] = totalBlobSize - totalUnreferencedBlobSize
76+
ctx.Data["TotalUnreferencedBlobSize"] = totalUnreferencedBlobSize
7077

7178
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
7279
pager.AddParamString("q", query)

routers/web/repo/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
784784
}
785785

786786
}
787-
if !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
787+
788+
if template.Ref != "" && !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
788789
template.Ref = git.BranchPrefix + template.Ref
789790
}
790791
ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0

services/issue/commit.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
repo_model "code.gitea.io/gitea/models/repo"
1919
user_model "code.gitea.io/gitea/models/user"
2020
"code.gitea.io/gitea/modules/container"
21+
"code.gitea.io/gitea/modules/git"
2122
"code.gitea.io/gitea/modules/log"
2223
"code.gitea.io/gitea/modules/references"
2324
"code.gitea.io/gitea/modules/repository"
@@ -175,7 +176,8 @@ func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, comm
175176
if !repo.CloseIssuesViaCommitInAnyBranch {
176177
// If the issue was specified to be in a particular branch, don't allow commits in other branches to close it
177178
if refIssue.Ref != "" {
178-
if branchName != refIssue.Ref {
179+
issueBranchName := strings.TrimPrefix(refIssue.Ref, git.BranchPrefix)
180+
if branchName != issueBranchName {
179181
continue
180182
}
181183
// Otherwise, only process commits to the default branch

0 commit comments

Comments
 (0)