Skip to content

Commit fc3d082

Browse files
authored
Move attachment into models/repo/ (#17650)
* Move attachment into models/repo/ * Fix test * Fix bug
1 parent 7a03473 commit fc3d082

39 files changed

+471
-408
lines changed

cmd/migrate_storage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/models/db"
1414
"code.gitea.io/gitea/models/migrations"
15+
repo_model "code.gitea.io/gitea/models/repo"
1516
"code.gitea.io/gitea/modules/log"
1617
"code.gitea.io/gitea/modules/setting"
1718
"code.gitea.io/gitea/modules/storage"
@@ -79,7 +80,7 @@ var CmdMigrateStorage = cli.Command{
7980
}
8081

8182
func migrateAttachments(dstStorage storage.ObjectStorage) error {
82-
return models.IterateAttachment(func(attach *models.Attachment) error {
83+
return repo_model.IterateAttachment(func(attach *repo_model.Attachment) error {
8384
_, err := storage.Copy(dstStorage, attach.RelativePath(), storage.Attachments, attach.RelativePath())
8485
return err
8586
})

integrations/attachment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strings"
1515
"testing"
1616

17-
"code.gitea.io/gitea/models"
17+
repo_model "code.gitea.io/gitea/models/repo"
1818
"code.gitea.io/gitea/modules/storage"
1919
"code.gitea.io/gitea/modules/test"
2020

@@ -122,7 +122,7 @@ func TestGetAttachment(t *testing.T) {
122122
t.Run(tc.name, func(t *testing.T) {
123123
//Write empty file to be available for response
124124
if tc.createFile {
125-
_, err := storage.Attachments.Save(models.AttachmentRelativePath(tc.uuid), strings.NewReader("hello world"), -1)
125+
_, err := storage.Attachments.Save(repo_model.AttachmentRelativePath(tc.uuid), strings.NewReader("hello world"), -1)
126126
assert.NoError(t, err)
127127
}
128128
//Actual test

models/error.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,29 +1679,6 @@ func (err ErrMilestoneNotExist) Error() string {
16791679
return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
16801680
}
16811681

1682-
// _____ __ __ .__ __
1683-
// / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
1684-
// / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
1685-
// / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
1686-
// \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
1687-
// \/ \/ \/ \/ \/ \/ \/
1688-
1689-
// ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
1690-
type ErrAttachmentNotExist struct {
1691-
ID int64
1692-
UUID string
1693-
}
1694-
1695-
// IsErrAttachmentNotExist checks if an error is a ErrAttachmentNotExist.
1696-
func IsErrAttachmentNotExist(err error) bool {
1697-
_, ok := err.(ErrAttachmentNotExist)
1698-
return ok
1699-
}
1700-
1701-
func (err ErrAttachmentNotExist) Error() string {
1702-
return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
1703-
}
1704-
17051682
// ___________
17061683
// \__ ___/___ _____ _____
17071684
// | |_/ __ \\__ \ / \
@@ -1758,7 +1735,7 @@ type ErrUploadNotExist struct {
17581735

17591736
// IsErrUploadNotExist checks if an error is a ErrUploadNotExist.
17601737
func IsErrUploadNotExist(err error) bool {
1761-
_, ok := err.(ErrAttachmentNotExist)
1738+
_, ok := err.(ErrUploadNotExist)
17621739
return ok
17631740
}
17641741

0 commit comments

Comments
 (0)