1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Move some files into models' sub packages (#20262)

* Move some files into models' sub packages

* Move functions

* merge main branch

* Fix check

* fix check

* Fix some tests

* Fix lint

* Fix lint

* Revert lint changes

* Fix error comments

* Fix lint

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
Lunny Xiao
2022-08-25 10:31:57 +08:00
committed by GitHub
parent 4a4bfafa23
commit 1d8543e7db
154 changed files with 1763 additions and 1738 deletions

View File

@@ -23,7 +23,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
)
func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool, error) {
func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) {
var created bool
// Only actual create when publish.
if !rel.IsDraft {
@@ -112,12 +112,12 @@ func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool,
}
// CreateRelease creates a new release of repository.
func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs []string, msg string) error {
has, err := models.IsReleaseExist(gitRepo.Ctx, rel.RepoID, rel.TagName)
func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentUUIDs []string, msg string) error {
has, err := repo_model.IsReleaseExist(gitRepo.Ctx, rel.RepoID, rel.TagName)
if err != nil {
return err
} else if has {
return models.ErrReleaseAlreadyExist{
return repo_model.ErrReleaseAlreadyExist{
TagName: rel.TagName,
}
}
@@ -131,7 +131,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
return err
}
if err = models.AddReleaseAttachments(gitRepo.Ctx, rel.ID, attachmentUUIDs); err != nil {
if err = repo_model.AddReleaseAttachments(gitRepo.Ctx, rel.ID, attachmentUUIDs); err != nil {
return err
}
@@ -144,7 +144,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
// CreateNewTag creates a new repository tag
func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commit, tagName, msg string) error {
has, err := models.IsReleaseExist(ctx, repo.ID, tagName)
has, err := repo_model.IsReleaseExist(ctx, repo.ID, tagName)
if err != nil {
return err
} else if has {
@@ -159,7 +159,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
}
defer closer.Close()
rel := &models.Release{
rel := &repo_model.Release{
RepoID: repo.ID,
Repo: repo,
PublisherID: doer.ID,
@@ -182,7 +182,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
// addAttachmentUUIDs accept a slice of new created attachments' uuids which will be reassigned release_id as the created release
// delAttachmentUUIDs accept a slice of attachments' uuids which will be deleted from the release
// editAttachments accept a map of attachment uuid to new attachment name which will be updated with attachments.
func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.Release,
func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_model.Release,
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string,
) (err error) {
if rel.ID == 0 {
@@ -200,11 +200,11 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.R
}
defer committer.Close()
if err = models.UpdateRelease(ctx, rel); err != nil {
if err = repo_model.UpdateRelease(ctx, rel); err != nil {
return err
}
if err = models.AddReleaseAttachments(ctx, rel.ID, addAttachmentUUIDs); err != nil {
if err = repo_model.AddReleaseAttachments(ctx, rel.ID, addAttachmentUUIDs); err != nil {
return fmt.Errorf("AddReleaseAttachments: %v", err)
}
@@ -283,7 +283,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.R
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, delTag bool) error {
rel, err := models.GetReleaseByID(ctx, id)
rel, err := repo_model.GetReleaseByID(ctx, id)
if err != nil {
return fmt.Errorf("GetReleaseByID: %v", err)
}
@@ -324,13 +324,13 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
}, repository.NewPushCommits())
notification.NotifyDeleteRef(doer, repo, "tag", git.TagPrefix+rel.TagName)
if err := models.DeleteReleaseByID(id); err != nil {
if err := repo_model.DeleteReleaseByID(id); err != nil {
return fmt.Errorf("DeleteReleaseByID: %v", err)
}
} else {
rel.IsTag = true
if err = models.UpdateRelease(ctx, rel); err != nil {
if err = repo_model.UpdateRelease(ctx, rel); err != nil {
return fmt.Errorf("Update: %v", err)
}
}