Skip to content

Commit 68d7666

Browse files
committed
Merge remote-tracking branch 'upstream/release/v1.17' into codeberg-1.17
2 parents dbc0f11 + e321b40 commit 68d7666

File tree

29 files changed

+191
-102
lines changed

29 files changed

+191
-102
lines changed

cmd/dump_repo.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/modules/convert"
13+
"code.gitea.io/gitea/modules/git"
1314
"code.gitea.io/gitea/modules/log"
1415
base "code.gitea.io/gitea/modules/migration"
1516
"code.gitea.io/gitea/modules/setting"
@@ -83,6 +84,11 @@ func runDumpRepository(ctx *cli.Context) error {
8384
return err
8485
}
8586

87+
// migrations.GiteaLocalUploader depends on git module
88+
if err := git.InitSimple(context.Background()); err != nil {
89+
return err
90+
}
91+
8692
log.Info("AppPath: %s", setting.AppPath)
8793
log.Info("AppWorkPath: %s", setting.AppWorkPath)
8894
log.Info("Custom path: %s", setting.CustomPath)
@@ -128,7 +134,9 @@ func runDumpRepository(ctx *cli.Context) error {
128134
} else {
129135
units := strings.Split(ctx.String("units"), ",")
130136
for _, unit := range units {
131-
switch strings.ToLower(unit) {
137+
switch strings.ToLower(strings.TrimSpace(unit)) {
138+
case "":
139+
continue
132140
case "wiki":
133141
opts.Uncyclo = true
134142
case "issues":
@@ -145,6 +153,8 @@ func runDumpRepository(ctx *cli.Context) error {
145153
opts.Comments = true
146154
case "pull_requests":
147155
opts.PullRequests = true
156+
default:
157+
return errors.New("invalid unit: " + unit)
148158
}
149159
}
150160
}

cmd/restore_repo.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"errors"
99
"net/http"
10+
"strings"
1011

1112
"code.gitea.io/gitea/modules/log"
1213
"code.gitea.io/gitea/modules/private"
@@ -37,10 +38,10 @@ var CmdRestoreRepository = cli.Command{
3738
Value: "",
3839
Usage: "Restore destination repository name",
3940
},
40-
cli.StringSliceFlag{
41+
cli.StringFlag{
4142
Name: "units",
42-
Value: nil,
43-
Usage: `Which items will be restored, one or more units should be repeated with this flag.
43+
Value: "",
44+
Usage: `Which items will be restored, one or more units should be separated as comma.
4445
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
4546
},
4647
cli.BoolFlag{
@@ -55,13 +56,16 @@ func runRestoreRepository(c *cli.Context) error {
5556
defer cancel()
5657

5758
setting.LoadFromExisting()
58-
59+
var units []string
60+
if s := c.String("units"); s != "" {
61+
units = strings.Split(s, ",")
62+
}
5963
statusCode, errStr := private.RestoreRepo(
6064
ctx,
6165
c.String("repo_dir"),
6266
c.String("owner_name"),
6367
c.String("repo_name"),
64-
c.StringSlice("units"),
68+
units,
6569
c.Bool("validation"),
6670
)
6771
if statusCode == http.StatusOK {

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ PATH =
16871687
;ENABLED = true
16881688
;;
16891689
;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
1690-
;ALLOWED_TYPES = .docx,.gif,.gz,.jpeg,.jpg,.mp4,.log,.pdf,.png,.pptx,.txt,.xlsx,.zip
1690+
;ALLOWED_TYPES = .csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip
16911691
;;
16921692
;; Max size of each file. Defaults to 4MB
16931693
;MAX_SIZE = 4

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ Default templates for project boards:
741741
## Issue and pull request attachments (`attachment`)
742742

743743
- `ENABLED`: **true**: Whether issue and pull request attachments are enabled.
744-
- `ALLOWED_TYPES`: **.docx,.gif,.gz,.jpeg,.jpg,mp4,.log,.pdf,.png,.pptx,.txt,.xlsx,.zip**: Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
744+
- `ALLOWED_TYPES`: **.csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip**: Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
745745
- `MAX_SIZE`: **4**: Maximum size (MB).
746746
- `MAX_FILES`: **5**: Maximum number of attachments that can be uploaded at once.
747747
- `STORAGE_TYPE`: **local**: Storage type for attachments, `local` for local disk or `minio` for s3 compatible object storage service, default is `local` or other name defined with `[storage.xxx]`

models/action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ func init() {
9292

9393
// TableIndices implements xorm's TableIndices interface
9494
func (a *Action) TableIndices() []*schemas.Index {
95+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
96+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
97+
9598
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
9699
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
97100

98-
repoIndex := schemas.NewIndex("r_c_u_d", schemas.IndexType)
99-
repoIndex.AddColumn("repo_id", "created_unix", "user_id", "is_deleted")
100-
101101
return []*schemas.Index{actUserIndex, repoIndex}
102102
}
103103

models/issues/issue_project.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64
124124
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
125125
oldProjectID := issue.projectID(ctx)
126126

127+
// Only check if we add a new project and not remove it.
128+
if newProjectID > 0 {
129+
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
130+
if err != nil {
131+
return err
132+
}
133+
if newProject.RepoID != issue.RepoID {
134+
return fmt.Errorf("issue's repository is not the same as project's repository")
135+
}
136+
}
137+
127138
if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
128139
return err
129140
}

models/issues/milestone.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ func NewMilestone(m *Milestone) (err error) {
124124
return committer.Commit()
125125
}
126126

127+
// HasMilestoneByRepoID returns if the milestone exists in the repository.
128+
func HasMilestoneByRepoID(ctx context.Context, repoID, id int64) (bool, error) {
129+
return db.GetEngine(ctx).ID(id).Where("repo_id=?", repoID).Exist(new(Milestone))
130+
}
131+
127132
// GetMilestoneByRepoID returns the milestone in a repository.
128133
func GetMilestoneByRepoID(ctx context.Context, repoID, id int64) (*Milestone, error) {
129134
m := new(Milestone)

models/migrations/migrations.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type Version struct {
5656
Version int64
5757
}
5858

59+
// Use noopMigration when there is a migration that has been no-oped
60+
var noopMigration = func(_ *xorm.Engine) error { return nil }
61+
5962
// This is a sequence of migrations. Add new migrations to the bottom of the list.
6063
// If you want to "retire" a migration, remove it from the top of the list and
6164
// update minDBVersion accordingly
@@ -351,7 +354,7 @@ var migrations = []Migration{
351354
// v198 -> v199
352355
NewMigration("Add issue content history table", addTableIssueContentHistory),
353356
// v199 -> v200
354-
NewMigration("No-op (remote version is using AppState now)", addRemoteVersionTableNoop),
357+
NewMigration("No-op (remote version is using AppState now)", noopMigration),
355358
// v200 -> v201
356359
NewMigration("Add table app_state", addTableAppState),
357360
// v201 -> v202
@@ -388,9 +391,11 @@ var migrations = []Migration{
388391
// v215 -> v216
389392
NewMigration("allow to view files in PRs", addReviewViewedFiles),
390393
// v216 -> v217
391-
NewMigration("Improve Action table indices", improveActionTableIndices),
394+
NewMigration("No-op (Improve Action table indices v1)", noopMigration),
392395
// v217 -> v218
393396
NewMigration("Alter hook_task table TEXT fields to LONGTEXT", alterHookTaskTextFieldsToLongText),
397+
// v218 -> v219
398+
NewMigration("Improve Action table indices v2", improveActionTableIndices),
394399
}
395400

396401
// GetCurrentDBVersion returns the current db version

models/migrations/v199.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@
44

55
package migrations
66

7-
import (
8-
"xorm.io/xorm"
9-
)
10-
11-
func addRemoteVersionTableNoop(x *xorm.Engine) error {
12-
// we used to use a table `remote_version` to store information for updater, now we use `AppState`, so this migration task is a no-op now.
13-
return nil
14-
}
7+
// We used to use a table `remote_version` to store information for updater, now we use `AppState`, so this migration task is a no-op now.

models/migrations/v216.go

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,5 @@
44

55
package migrations
66

7-
import (
8-
"code.gitea.io/gitea/modules/timeutil"
9-
10-
"xorm.io/xorm"
11-
"xorm.io/xorm/schemas"
12-
)
13-
14-
type improveActionTableIndicesAction struct {
15-
ID int64 `xorm:"pk autoincr"`
16-
UserID int64 // Receiver user id.
17-
OpType int
18-
ActUserID int64 // Action user id.
19-
RepoID int64
20-
CommentID int64 `xorm:"INDEX"`
21-
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
22-
RefName string
23-
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
24-
Content string `xorm:"TEXT"`
25-
CreatedUnix timeutil.TimeStamp `xorm:"created"`
26-
}
27-
28-
// TableName sets the name of this table
29-
func (a *improveActionTableIndicesAction) TableName() string {
30-
return "action"
31-
}
32-
33-
// TableIndices implements xorm's TableIndices interface
34-
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
35-
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
36-
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
37-
38-
repoIndex := schemas.NewIndex("r_c_u_d", schemas.IndexType)
39-
repoIndex.AddColumn("repo_id", "created_unix", "user_id", "is_deleted")
40-
41-
return []*schemas.Index{actUserIndex, repoIndex}
42-
}
43-
44-
func improveActionTableIndices(x *xorm.Engine) error {
45-
return x.Sync2(&improveActionTableIndicesAction{})
46-
}
7+
// This migration added non-ideal indices to the action table which on larger datasets slowed things down
8+
// it has been superceded by v218.go

models/migrations/v218.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"code.gitea.io/gitea/modules/timeutil"
9+
10+
"xorm.io/xorm"
11+
"xorm.io/xorm/schemas"
12+
)
13+
14+
type improveActionTableIndicesAction struct {
15+
ID int64 `xorm:"pk autoincr"`
16+
UserID int64 // Receiver user id.
17+
OpType int
18+
ActUserID int64 // Action user id.
19+
RepoID int64
20+
CommentID int64 `xorm:"INDEX"`
21+
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
22+
RefName string
23+
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
24+
Content string `xorm:"TEXT"`
25+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
26+
}
27+
28+
// TableName sets the name of this table
29+
func (*improveActionTableIndicesAction) TableName() string {
30+
return "action"
31+
}
32+
33+
// TableIndices implements xorm's TableIndices interface
34+
func (*improveActionTableIndicesAction) TableIndices() []*schemas.Index {
35+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
36+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
37+
38+
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
39+
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
40+
41+
return []*schemas.Index{actUserIndex, repoIndex}
42+
}
43+
44+
func improveActionTableIndices(x *xorm.Engine) error {
45+
return x.Sync2(&improveActionTableIndicesAction{})
46+
}

modules/indexer/code/elastic_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (b *ElasticSearchIndexer) Index(ctx context.Context, repo *repo_model.Repos
284284
reqs := make([]elastic.BulkableRequest, 0)
285285
if len(changes.Updates) > 0 {
286286
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
287-
if err := git.EnsureValidGitRepository(git.DefaultContext, repo.RepoPath()); err != nil {
287+
if err := git.EnsureValidGitRepository(ctx, repo.RepoPath()); err != nil {
288288
log.Error("Unable to open git repo: %s for %-v: %v", repo.RepoPath(), repo, err)
289289
return err
290290
}

modules/migration/null_downloader.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,52 @@ func (n NullDownloader) SetContext(_ context.Context) {}
1919

2020
// GetRepoInfo returns a repository information
2121
func (n NullDownloader) GetRepoInfo() (*Repository, error) {
22-
return nil, &ErrNotSupported{Entity: "RepoInfo"}
22+
return nil, ErrNotSupported{Entity: "RepoInfo"}
2323
}
2424

2525
// GetTopics return repository topics
2626
func (n NullDownloader) GetTopics() ([]string, error) {
27-
return nil, &ErrNotSupported{Entity: "Topics"}
27+
return nil, ErrNotSupported{Entity: "Topics"}
2828
}
2929

3030
// GetMilestones returns milestones
3131
func (n NullDownloader) GetMilestones() ([]*Milestone, error) {
32-
return nil, &ErrNotSupported{Entity: "Milestones"}
32+
return nil, ErrNotSupported{Entity: "Milestones"}
3333
}
3434

3535
// GetReleases returns releases
3636
func (n NullDownloader) GetReleases() ([]*Release, error) {
37-
return nil, &ErrNotSupported{Entity: "Releases"}
37+
return nil, ErrNotSupported{Entity: "Releases"}
3838
}
3939

4040
// GetLabels returns labels
4141
func (n NullDownloader) GetLabels() ([]*Label, error) {
42-
return nil, &ErrNotSupported{Entity: "Labels"}
42+
return nil, ErrNotSupported{Entity: "Labels"}
4343
}
4444

4545
// GetIssues returns issues according start and limit
4646
func (n NullDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
47-
return nil, false, &ErrNotSupported{Entity: "Issues"}
47+
return nil, false, ErrNotSupported{Entity: "Issues"}
4848
}
4949

5050
// GetComments returns comments of an issue or PR
5151
func (n NullDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
52-
return nil, false, &ErrNotSupported{Entity: "Comments"}
52+
return nil, false, ErrNotSupported{Entity: "Comments"}
5353
}
5454

5555
// GetAllComments returns paginated comments
5656
func (n NullDownloader) GetAllComments(page, perPage int) ([]*Comment, bool, error) {
57-
return nil, false, &ErrNotSupported{Entity: "AllComments"}
57+
return nil, false, ErrNotSupported{Entity: "AllComments"}
5858
}
5959

6060
// GetPullRequests returns pull requests according page and perPage
6161
func (n NullDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
62-
return nil, false, &ErrNotSupported{Entity: "PullRequests"}
62+
return nil, false, ErrNotSupported{Entity: "PullRequests"}
6363
}
6464

6565
// GetReviews returns pull requests review
6666
func (n NullDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
67-
return nil, &ErrNotSupported{Entity: "Reviews"}
67+
return nil, ErrNotSupported{Entity: "Reviews"}
6868
}
6969

7070
// FormatCloneURL add authentication into remote URLs

modules/setting/attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func newAttachmentService() {
2727

2828
Attachment.Storage = getStorage("attachments", storageType, sec)
2929

30-
Attachment.AllowedTypes = sec.Key("ALLOWED_TYPES").MustString(".docx,.gif,.gz,.jpeg,.jpg,.mp4,.log,.pdf,.png,.pptx,.txt,.xlsx,.zip")
30+
Attachment.AllowedTypes = sec.Key("ALLOWED_TYPES").MustString(".csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip")
3131
Attachment.MaxSize = sec.Key("MAX_SIZE").MustInt64(4)
3232
Attachment.MaxFiles = sec.Key("MAX_FILES").MustInt(5)
3333
Attachment.Enabled = sec.Key("ENABLED").MustBool(true)

routers/api/v1/repo/pull_review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
886886
return
887887
}
888888

889-
_, err := pull_service.DismissReview(ctx, review.ID, msg, ctx.Doer, isDismiss)
889+
_, err := pull_service.DismissReview(ctx, review.ID, ctx.Repo.Repository.ID, msg, ctx.Doer, isDismiss)
890890
if err != nil {
891891
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
892892
return

0 commit comments

Comments
 (0)