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

+9
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

+7
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

+11-2
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

+2-2
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

+4-1
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

+2
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

+1
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

+10-3
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

+2-1
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

+3-1
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

services/migrations/gitea_uploader.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,34 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
454454
if comment.Updated.IsZero() {
455455
comment.Updated = comment.Created
456456
}
457-
457+
if comment.CommentType == "" {
458+
// if type field is missing, then assume a normal comment
459+
comment.CommentType = issues_model.CommentTypeComment.String()
460+
}
458461
cm := issues_model.Comment{
459462
IssueID: issue.ID,
460-
Type: issues_model.CommentTypeComment,
463+
Type: issues_model.AsCommentType(comment.CommentType),
461464
Content: comment.Content,
462465
CreatedUnix: timeutil.TimeStamp(comment.Created.Unix()),
463466
UpdatedUnix: timeutil.TimeStamp(comment.Updated.Unix()),
464467
}
465468

469+
switch cm.Type {
470+
case issues_model.CommentTypeAssignees:
471+
cm.AssigneeID = comment.Meta["AssigneeID"].(int64)
472+
if comment.Meta["RemovedAssigneeID"] != nil {
473+
cm.RemovedAssignee = true
474+
}
475+
case issues_model.CommentTypeChangeTitle:
476+
if comment.Meta["OldTitle"] != nil {
477+
cm.OldTitle = fmt.Sprintf("%s", comment.Meta["OldTitle"])
478+
}
479+
if comment.Meta["NewTitle"] != nil {
480+
cm.NewTitle = fmt.Sprintf("%s", comment.Meta["NewTitle"])
481+
}
482+
default:
483+
}
484+
466485
if err := g.remapUser(comment, &cm); err != nil {
467486
return err
468487
}

services/packages/packages.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ func checkSizeQuotaExceeded(ctx context.Context, doer, owner *user_model.User, p
361361
}
362362

363363
if setting.Packages.LimitTotalOwnerSize > -1 {
364-
totalSize, err := packages_model.CalculateBlobSize(ctx, &packages_model.PackageFileSearchOptions{
364+
totalSize, err := packages_model.CalculateFileSize(ctx, &packages_model.PackageFileSearchOptions{
365365
OwnerID: owner.ID,
366366
})
367367
if err != nil {
368-
log.Error("CalculateBlobSize failed: %v", err)
368+
log.Error("CalculateFileSize failed: %v", err)
369369
return err
370370
}
371371
if totalSize+uploadSize > setting.Packages.LimitTotalOwnerSize {

services/pull/update.go

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest,
118118
}
119119
prUnit, err := pr.BaseRepo.GetUnit(ctx, unit.TypePullRequests)
120120
if err != nil {
121+
if repo_model.IsErrUnitTypeNotExist(err) {
122+
return false, false, nil
123+
}
121124
log.Error("pr.BaseRepo.GetUnit(unit.TypePullRequests): %v", err)
122125
return false, false, err
123126
}

templates/admin/packages/list.tmpl

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<div class="ui container">
55
{{template "base/alert" .}}
66
<h4 class="ui top attached header">
7-
{{.locale.Tr "admin.packages.package_manage_panel"}} ({{.locale.Tr "admin.total" .Total}}, {{.locale.Tr "admin.packages.total_size" (FileSize .TotalBlobSize)}})
7+
{{.locale.Tr "admin.packages.package_manage_panel"}} ({{.locale.Tr "admin.total" .TotalCount}},
8+
{{.locale.Tr "admin.packages.total_size" (FileSize .TotalBlobSize)}},
9+
{{.locale.Tr "admin.packages.unreferenced_size" (FileSize .TotalUnreferencedBlobSize)}})
810
</h4>
911
<div class="ui attached segment">
1012
<form class="ui form ignore-dirty">

web_src/js/markup/asciicast.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ export async function renderAsciinemaPlayer() {
22
const els = document.querySelectorAll('.asciinema-player-container');
33
if (!els.length) return;
44

5-
const player = await import(/* webpackChunkName: "asciinema-player" */'asciinema-player');
5+
const [player] = await Promise.all([
6+
import(/* webpackChunkName: "asciinema-player" */'asciinema-player'),
7+
import(/* webpackChunkName: "asciinema-player" */'asciinema-player/dist/bundle/asciinema-player.css'),
8+
]);
69

710
for (const el of els) {
811
player.create(el.getAttribute('data-asciinema-player-src'), el, {

web_src/less/markup/asciicast.less

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import "../asciinema-player/dist/bundle/asciinema-player.css";
2-
31
.asciinema-player-container {
42
width: 100%;
53
height: auto;

0 commit comments

Comments
 (0)