diff options
Diffstat (limited to 'modules')
47 files changed, 335 insertions, 265 deletions
diff --git a/modules/context/api.go b/modules/context/api.go index 4a2d5d1665..b6fcdd2a1c 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -13,8 +13,8 @@ import ( "net/url" "strings" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -327,7 +327,7 @@ func ReferencesGitRepo(allowEmpty bool) func(http.Handler) http.Handler { // For API calls. if ctx.Repo.GitRepo == nil { - repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) gitRepo, err := git.OpenRepository(repoPath) if err != nil { ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err) @@ -385,7 +385,7 @@ func RepoRefForAPI(next http.Handler) http.Handler { var err error if ctx.Repo.GitRepo == nil { - repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) ctx.Repo.GitRepo, err = git.OpenRepository(repoPath) if err != nil { ctx.InternalServerError(err) diff --git a/modules/context/repo.go b/modules/context/repo.go index b2844c04c4..694c483bd4 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -14,6 +14,8 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/cache" @@ -42,7 +44,7 @@ var IssueTemplateDirCandidates = []string{ // PullRequest contains information to make a pull request type PullRequest struct { - BaseRepo *models.Repository + BaseRepo *repo_model.Repository Allowed bool SameRepo bool HeadInfoSubURL string // [<user>:]<branch> url segment @@ -55,7 +57,7 @@ type Repository struct { IsViewBranch bool IsViewTag bool IsViewCommit bool - Repository *models.Repository + Repository *repo_model.Repository Owner *user_model.User Commit *git.Commit Tag *git.Tag @@ -66,9 +68,9 @@ type Repository struct { TreePath string CommitID string RepoLink string - CloneLink models.CloneLink + CloneLink repo_model.CloneLink CommitsCount int64 - Mirror *models.Mirror + Mirror *repo_model.Mirror PullRequest *PullRequest } @@ -118,7 +120,7 @@ func (r *Repository) CanCommitToBranch(doer *user_model.User) (CanCommitToBranch requireSigned = protectedBranch.RequireSignedCommits } - sign, keyID, _, err := r.Repository.SignCRUDAction(doer, r.Repository.RepoPath(), git.BranchPrefix+r.BranchName) + sign, keyID, _, err := models.SignCRUDAction(r.Repository, doer, r.Repository.RepoPath(), git.BranchPrefix+r.BranchName) canCommit := r.CanEnableEditor() && userCanPush if requireSigned { @@ -242,38 +244,39 @@ func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) { } // RetrieveBaseRepo retrieves base repository -func RetrieveBaseRepo(ctx *Context, repo *models.Repository) { +func RetrieveBaseRepo(ctx *Context, repo *repo_model.Repository) { // Non-fork repository will not return error in this method. if err := repo.GetBaseRepo(); err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { repo.IsFork = false repo.ForkID = 0 return } ctx.ServerError("GetBaseRepo", err) return - } else if err = repo.BaseRepo.GetOwner(); err != nil { + } else if err = repo.BaseRepo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("BaseRepo.GetOwner", err) return } } // RetrieveTemplateRepo retrieves template repository used to generate this repository -func RetrieveTemplateRepo(ctx *Context, repo *models.Repository) { +func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) { // Non-generated repository will not return error in this method. - if err := repo.GetTemplateRepo(); err != nil { - if models.IsErrRepoNotExist(err) { + templateRepo, err := repo_model.GetTemplateRepo(repo) + if err != nil { + if repo_model.IsErrRepoNotExist(err) { repo.TemplateID = 0 return } ctx.ServerError("GetTemplateRepo", err) return - } else if err = repo.TemplateRepo.GetOwner(); err != nil { + } else if err = templateRepo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("TemplateRepo.GetOwner", err) return } - perm, err := models.GetUserRepoPermission(repo.TemplateRepo, ctx.User) + perm, err := models.GetUserRepoPermission(templateRepo, ctx.User) if err != nil { ctx.ServerError("GetUserRepoPermission", err) return @@ -307,7 +310,7 @@ func EarlyResponseForGoGetMeta(ctx *Context) { ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`, map[string]string{ "GoGetImport": ComposeGoGetImport(username, reponame), - "CloneLink": models.ComposeHTTPSCloneURL(username, reponame), + "CloneLink": repo_model.ComposeHTTPSCloneURL(username, reponame), }))) } @@ -316,7 +319,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) { ownerName := ctx.Params(":username") previousRepoName := ctx.Params(":reponame") - repo, err := models.GetRepositoryByID(redirectRepoID) + repo, err := repo_model.GetRepositoryByID(redirectRepoID) if err != nil { ctx.ServerError("GetRepositoryByID", err) return @@ -334,9 +337,9 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) { ctx.Redirect(path.Join(setting.AppSubURL, redirectPath)) } -func repoAssignment(ctx *Context, repo *models.Repository) { +func repoAssignment(ctx *Context, repo *repo_model.Repository) { var err error - if err = repo.GetOwner(); err != nil { + if err = repo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("GetOwner", err) return } @@ -361,21 +364,24 @@ func repoAssignment(ctx *Context, repo *models.Repository) { if repo.IsMirror { var err error - ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID) + mirror, err := repo_model.GetMirrorByRepoID(repo.ID) if err != nil { ctx.ServerError("GetMirrorByRepoID", err) return } - ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune - ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval - ctx.Data["Mirror"] = ctx.Repo.Mirror + ctx.Data["MirrorEnablePrune"] = mirror.EnablePrune + ctx.Data["MirrorInterval"] = mirror.Interval + ctx.Data["Mirror"] = mirror } - if err = repo.LoadPushMirrors(); err != nil { - ctx.ServerError("LoadPushMirrors", err) + + pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID) + if err != nil { + ctx.ServerError("GetPushMirrorsByRepoID", err) return } ctx.Repo.Repository = repo + ctx.Data["PushMirrors"] = pushMirrors ctx.Data["RepoName"] = ctx.Repo.Repository.Name ctx.Data["IsEmptyRepo"] = ctx.Repo.Repository.IsEmpty } @@ -386,9 +392,9 @@ func RepoIDAssignment() func(ctx *Context) { repoID := ctx.ParamsInt64(":repoid") // Get repository. - repo, err := models.GetRepositoryByID(repoID) + repo, err := repo_model.GetRepositoryByID(repoID) if err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByID", nil) } else { ctx.ServerError("GetRepositoryByID", err) @@ -433,9 +439,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { ctx.Data["Username"] = ctx.Repo.Owner.Name // Get repository. - repo, err := models.GetRepositoryByName(owner.ID, repoName) + repo, err := repo_model.GetRepositoryByName(owner.ID, repoName) if err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { redirectRepoID, err := models.LookupRepoRedirect(owner.ID, repoName) if err == nil { RedirectToRepo(ctx, redirectRepoID) @@ -534,11 +540,11 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { return } - gitRepo, err := git.OpenRepositoryCtx(ctx, models.RepoPath(userName, repoName)) + gitRepo, err := git.OpenRepositoryCtx(ctx, repo_model.RepoPath(userName, repoName)) if err != nil { if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") { log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err) - ctx.Repo.Repository.Status = models.RepositoryBroken + ctx.Repo.Repository.Status = repo_model.RepositoryBroken ctx.Repo.Repository.IsEmpty = true ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch // Only allow access to base of repo or settings @@ -547,7 +553,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { } return } - ctx.ServerError("RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err) + ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err) return } ctx.Repo.GitRepo = gitRepo @@ -570,7 +576,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { if err != nil { if strings.Contains(err.Error(), "fatal: not a git repository ") { log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err) - ctx.Repo.Repository.Status = models.RepositoryBroken + ctx.Repo.Repository.Status = repo_model.RepositoryBroken ctx.Repo.Repository.IsEmpty = true ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch // Only allow access to base of repo or settings @@ -629,7 +635,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { ctx.Data["CanCompareOrPull"] = canCompare ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest - if ctx.Repo.Repository.Status == models.RepositoryPendingTransfer { + if ctx.Repo.Repository.Status == repo_model.RepositoryPendingTransfer { repoTransfer, err := models.GetPendingRepositoryTransfer(ctx.Repo.Repository) if err != nil { ctx.ServerError("GetPendingRepositoryTransfer", err) @@ -791,7 +797,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context ) if ctx.Repo.GitRepo == nil { - repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, repoPath) if err != nil { ctx.ServerError("RepoRef Invalid repo "+repoPath, err) diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 8c6a610625..eda9f23cd6 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" @@ -34,7 +35,7 @@ func ToEmail(email *user_model.EmailAddress) *api.Email { } // ToBranch convert a git.Commit and git.Branch to an api.Branch -func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { +func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { if bp == nil { var hasPerm bool var err error @@ -76,7 +77,7 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models. return nil, err } branch.UserCanPush = bp.CanUserPush(user.ID) - branch.UserCanMerge = bp.IsUserMergeWhitelisted(user.ID, permission) + branch.UserCanMerge = models.IsUserMergeWhitelisted(bp, user.ID, permission) } return branch, nil @@ -138,7 +139,7 @@ func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection { } // ToTag convert a git.Tag to an api.Tag -func ToTag(repo *models.Repository, t *git.Tag) *api.Tag { +func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag { return &api.Tag{ Name: t.Name, Message: strings.TrimSpace(t.Message), @@ -310,7 +311,7 @@ func ToTeam(team *models.Team) *api.Team { } // ToAnnotatedTag convert git.Tag to api.AnnotatedTag -func ToAnnotatedTag(repo *models.Repository, t *git.Tag, c *git.Commit) *api.AnnotatedTag { +func ToAnnotatedTag(repo *repo_model.Repository, t *git.Tag, c *git.Commit) *api.AnnotatedTag { return &api.AnnotatedTag{ Tag: t.Name, SHA: t.ID.String(), @@ -323,7 +324,7 @@ func ToAnnotatedTag(repo *models.Repository, t *git.Tag, c *git.Commit) *api.Ann } // ToAnnotatedTagObject convert a git.Commit to an api.AnnotatedTagObject -func ToAnnotatedTagObject(repo *models.Repository, commit *git.Commit) *api.AnnotatedTagObject { +func ToAnnotatedTagObject(repo *repo_model.Repository, commit *git.Commit) *api.AnnotatedTagObject { return &api.AnnotatedTagObject{ SHA: commit.ID.String(), Type: string(git.ObjectCommit), diff --git a/modules/convert/git_commit.go b/modules/convert/git_commit.go index 3148d880ff..55cac5fd58 100644 --- a/modules/convert/git_commit.go +++ b/modules/convert/git_commit.go @@ -8,7 +8,7 @@ import ( "net/url" "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -28,7 +28,7 @@ func ToCommitUser(sig *git.Signature) *api.CommitUser { } // ToCommitMeta convert a git.Tag to an api.CommitMeta -func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta { +func ToCommitMeta(repo *repo_model.Repository, tag *git.Tag) *api.CommitMeta { return &api.CommitMeta{ SHA: tag.Object.String(), URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()), @@ -37,7 +37,7 @@ func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta { } // ToPayloadCommit convert a git.Commit to api.PayloadCommit -func ToPayloadCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit { +func ToPayloadCommit(repo *repo_model.Repository, c *git.Commit) *api.PayloadCommit { authorUsername := "" if author, err := user_model.GetUserByEmail(c.Author.Email); err == nil { authorUsername = author.Name @@ -72,7 +72,7 @@ func ToPayloadCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit } // ToCommit convert a git.Commit to api.Commit -func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]*user_model.User) (*api.Commit, error) { +func ToCommit(repo *repo_model.Repository, commit *git.Commit, userCache map[string]*user_model.User) (*api.Commit, error) { var apiAuthor, apiCommitter *api.User diff --git a/modules/convert/git_commit_test.go b/modules/convert/git_commit_test.go index aacdb1ad7c..118ba3a007 100644 --- a/modules/convert/git_commit_test.go +++ b/modules/convert/git_commit_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" @@ -19,7 +19,7 @@ import ( func TestToCommitMeta(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - headRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000") signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)} tag := &git.Tag{ diff --git a/modules/convert/issue.go b/modules/convert/issue.go index c67ff5427f..4972b070a7 100644 --- a/modules/convert/issue.go +++ b/modules/convert/issue.go @@ -10,6 +10,8 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -30,7 +32,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue { if err := issue.LoadRepo(); err != nil { return &api.Issue{} } - if err := issue.Repo.GetOwner(); err != nil { + if err := issue.Repo.GetOwner(db.DefaultContext); err != nil { return &api.Issue{} } @@ -129,10 +131,10 @@ func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) { result := api.StopWatches(make([]api.StopWatch, 0, len(sws))) issueCache := make(map[int64]*models.Issue) - repoCache := make(map[int64]*models.Repository) + repoCache := make(map[int64]*repo_model.Repository) var ( issue *models.Issue - repo *models.Repository + repo *repo_model.Repository ok bool err error ) @@ -147,7 +149,7 @@ func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) { } repo, ok = repoCache[issue.RepoID] if !ok { - repo, err = models.GetRepositoryByID(issue.RepoID) + repo, err = repo_model.GetRepositoryByID(issue.RepoID) if err != nil { return nil, err } @@ -176,7 +178,7 @@ func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList { } // ToLabel converts Label to API format -func ToLabel(label *models.Label, repo *models.Repository, org *user_model.User) *api.Label { +func ToLabel(label *models.Label, repo *repo_model.Repository, org *user_model.User) *api.Label { result := &api.Label{ ID: label.ID, Name: label.Name, @@ -203,7 +205,7 @@ func ToLabel(label *models.Label, repo *models.Repository, org *user_model.User) } // ToLabelList converts list of Label to API format -func ToLabelList(labels []*models.Label, repo *models.Repository, org *user_model.User) []*api.Label { +func ToLabelList(labels []*models.Label, repo *repo_model.Repository, org *user_model.User) []*api.Label { result := make([]*api.Label, len(labels)) for i := range labels { result[i] = ToLabel(labels[i], repo, org) diff --git a/modules/convert/issue_test.go b/modules/convert/issue_test.go index 21ca7469e1..fb75413eab 100644 --- a/modules/convert/issue_test.go +++ b/modules/convert/issue_test.go @@ -10,6 +10,7 @@ import ( "time" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -21,7 +22,7 @@ import ( func TestLabel_ToLabel(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: 1}).(*models.Label) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: label.RepoID}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: label.RepoID}).(*repo_model.Repository) assert.Equal(t, &api.Label{ ID: label.ID, Name: label.Name, diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go index 1bac5d3a4a..11789b1200 100644 --- a/modules/convert/pull_test.go +++ b/modules/convert/pull_test.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/structs" @@ -18,7 +19,7 @@ import ( func TestPullRequest_APIFormat(t *testing.T) { //with HeadRepo assert.NoError(t, unittest.PrepareTestDatabase()) - headRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest) assert.NoError(t, pr.LoadAttributes()) assert.NoError(t, pr.LoadIssue()) diff --git a/modules/convert/repository.go b/modules/convert/repository.go index 46b2745b34..9859ea2674 100644 --- a/modules/convert/repository.go +++ b/modules/convert/repository.go @@ -6,17 +6,19 @@ package convert import ( "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" api "code.gitea.io/gitea/modules/structs" ) // ToRepo converts a Repository to api.Repository -func ToRepo(repo *models.Repository, mode perm.AccessMode) *api.Repository { +func ToRepo(repo *repo_model.Repository, mode perm.AccessMode) *api.Repository { return innerToRepo(repo, mode, false) } -func innerToRepo(repo *models.Repository, mode perm.AccessMode, isParent bool) *api.Repository { +func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent bool) *api.Repository { var parent *api.Repository cloneLink := repo.CloneLink() @@ -73,7 +75,7 @@ func innerToRepo(repo *models.Repository, mode perm.AccessMode, isParent bool) * allowRebase := false allowRebaseMerge := false allowSquash := false - defaultMergeStyle := models.MergeStyleMerge + defaultMergeStyle := repo_model.MergeStyleMerge if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil { config := unit.PullRequestsConfig() hasPullRequests = true @@ -89,7 +91,7 @@ func innerToRepo(repo *models.Repository, mode perm.AccessMode, isParent bool) * hasProjects = true } - if err := repo.GetOwner(); err != nil { + if err := repo.GetOwner(db.DefaultContext); err != nil { return nil } @@ -97,7 +99,9 @@ func innerToRepo(repo *models.Repository, mode perm.AccessMode, isParent bool) * mirrorInterval := "" if repo.IsMirror { - if err := repo.GetMirror(); err == nil { + var err error + repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID) + if err == nil { mirrorInterval = repo.Mirror.Interval.String() } } diff --git a/modules/convert/wiki.go b/modules/convert/wiki.go index 9563f1544e..1112da43f8 100644 --- a/modules/convert/wiki.go +++ b/modules/convert/wiki.go @@ -7,7 +7,7 @@ package convert import ( "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" @@ -49,7 +49,7 @@ func ToWikiCommitList(commits []*git.Commit, total int64) *api.WikiCommitList { } // ToWikiPageMetaData converts meta information to a WikiPageMetaData -func ToWikiPageMetaData(title string, lastCommit *git.Commit, repo *models.Repository) *api.WikiPageMetaData { +func ToWikiPageMetaData(title string, lastCommit *git.Commit, repo *repo_model.Repository) *api.WikiPageMetaData { suburl := wiki_service.NameToSubURL(title) return &api.WikiPageMetaData{ Title: title, diff --git a/modules/doctor/checkOldArchives.go b/modules/doctor/checkOldArchives.go index a4e2ffbd1f..0db8794080 100644 --- a/modules/doctor/checkOldArchives.go +++ b/modules/doctor/checkOldArchives.go @@ -8,7 +8,7 @@ import ( "os" "path/filepath" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" ) @@ -16,7 +16,7 @@ import ( func checkOldArchives(logger log.Logger, autofix bool) error { numRepos := 0 numReposUpdated := 0 - err := iterateRepositories(func(repo *models.Repository) error { + err := iterateRepositories(func(repo *repo_model.Repository) error { if repo.IsEmpty { return nil } diff --git a/modules/doctor/fix16961.go b/modules/doctor/fix16961.go index 2e1db834cd..4797c97ef3 100644 --- a/modules/doctor/fix16961.go +++ b/modules/doctor/fix16961.go @@ -8,9 +8,10 @@ import ( "bytes" "fmt" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" @@ -36,8 +37,8 @@ func parseBool16961(bs []byte) (bool, error) { return false, fmt.Errorf("unexpected bool format: %s", string(bs)) } -func fixUnitConfig16961(bs []byte, cfg *models.UnitConfig) (fixed bool, err error) { - err = models.JSONUnmarshalHandleDoubleEncode(bs, &cfg) +func fixUnitConfig16961(bs []byte, cfg *repo_model.UnitConfig) (fixed bool, err error) { + err = json.UnmarshalHandleDoubleEncode(bs, &cfg) if err == nil { return } @@ -50,8 +51,8 @@ func fixUnitConfig16961(bs []byte, cfg *models.UnitConfig) (fixed bool, err erro return true, nil } -func fixExternalWikiConfig16961(bs []byte, cfg *models.ExternalWikiConfig) (fixed bool, err error) { - err = models.JSONUnmarshalHandleDoubleEncode(bs, &cfg) +func fixExternalWikiConfig16961(bs []byte, cfg *repo_model.ExternalWikiConfig) (fixed bool, err error) { + err = json.UnmarshalHandleDoubleEncode(bs, &cfg) if err == nil { return } @@ -66,8 +67,8 @@ func fixExternalWikiConfig16961(bs []byte, cfg *models.ExternalWikiConfig) (fixe return true, nil } -func fixExternalTrackerConfig16961(bs []byte, cfg *models.ExternalTrackerConfig) (fixed bool, err error) { - err = models.JSONUnmarshalHandleDoubleEncode(bs, &cfg) +func fixExternalTrackerConfig16961(bs []byte, cfg *repo_model.ExternalTrackerConfig) (fixed bool, err error) { + err = json.UnmarshalHandleDoubleEncode(bs, &cfg) if err == nil { return } @@ -91,8 +92,8 @@ func fixExternalTrackerConfig16961(bs []byte, cfg *models.ExternalTrackerConfig) return true, nil } -func fixPullRequestsConfig16961(bs []byte, cfg *models.PullRequestsConfig) (fixed bool, err error) { - err = models.JSONUnmarshalHandleDoubleEncode(bs, &cfg) +func fixPullRequestsConfig16961(bs []byte, cfg *repo_model.PullRequestsConfig) (fixed bool, err error) { + err = json.UnmarshalHandleDoubleEncode(bs, &cfg) if err == nil { return } @@ -169,12 +170,12 @@ func fixPullRequestsConfig16961(bs []byte, cfg *models.PullRequestsConfig) (fixe return } - cfg.DefaultMergeStyle = models.MergeStyle(string(bytes.Join(parts[8:], []byte{' '}))) + cfg.DefaultMergeStyle = repo_model.MergeStyle(string(bytes.Join(parts[8:], []byte{' '}))) return true, nil } -func fixIssuesConfig16961(bs []byte, cfg *models.IssuesConfig) (fixed bool, err error) { - err = models.JSONUnmarshalHandleDoubleEncode(bs, &cfg) +func fixIssuesConfig16961(bs []byte, cfg *repo_model.IssuesConfig) (fixed bool, err error) { + err = json.UnmarshalHandleDoubleEncode(bs, &cfg) if err == nil { return } @@ -208,7 +209,7 @@ func fixIssuesConfig16961(bs []byte, cfg *models.IssuesConfig) (fixed bool, err return true, nil } -func fixBrokenRepoUnit16961(repoUnit *models.RepoUnit, bs []byte) (fixed bool, err error) { +func fixBrokenRepoUnit16961(repoUnit *repo_model.RepoUnit, bs []byte) (fixed bool, err error) { // Shortcut empty or null values if len(bs) == 0 { return false, nil @@ -216,33 +217,33 @@ func fixBrokenRepoUnit16961(repoUnit *models.RepoUnit, bs []byte) (fixed bool, e switch unit.Type(repoUnit.Type) { case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects: - cfg := &models.UnitConfig{} + cfg := &repo_model.UnitConfig{} repoUnit.Config = cfg if fixed, err := fixUnitConfig16961(bs, cfg); !fixed { return false, err } case unit.TypeExternalWiki: - cfg := &models.ExternalWikiConfig{} + cfg := &repo_model.ExternalWikiConfig{} repoUnit.Config = cfg if fixed, err := fixExternalWikiConfig16961(bs, cfg); !fixed { return false, err } case unit.TypeExternalTracker: - cfg := &models.ExternalTrackerConfig{} + cfg := &repo_model.ExternalTrackerConfig{} repoUnit.Config = cfg if fixed, err := fixExternalTrackerConfig16961(bs, cfg); !fixed { return false, err } case unit.TypePullRequests: - cfg := &models.PullRequestsConfig{} + cfg := &repo_model.PullRequestsConfig{} repoUnit.Config = cfg if fixed, err := fixPullRequestsConfig16961(bs, cfg); !fixed { return false, err } case unit.TypeIssues: - cfg := &models.IssuesConfig{} + cfg := &repo_model.IssuesConfig{} repoUnit.Config = cfg if fixed, err := fixIssuesConfig16961(bs, cfg); !fixed { return false, err @@ -275,7 +276,7 @@ func fixBrokenRepoUnits16961(logger log.Logger, autofix bool) error { unit := bean.(*RepoUnit) bs := unit.Config - repoUnit := &models.RepoUnit{ + repoUnit := &repo_model.RepoUnit{ ID: unit.ID, RepoID: unit.RepoID, Type: unit.Type, @@ -291,7 +292,7 @@ func fixBrokenRepoUnits16961(logger log.Logger, autofix bool) error { return nil } - return models.UpdateRepoUnit(repoUnit) + return repo_model.UpdateRepoUnit(repoUnit) }, ) diff --git a/modules/doctor/fix16961_test.go b/modules/doctor/fix16961_test.go index 986425b4d8..f5e5667c09 100644 --- a/modules/doctor/fix16961_test.go +++ b/modules/doctor/fix16961_test.go @@ -7,7 +7,7 @@ package doctor import ( "testing" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "github.com/stretchr/testify/assert" ) @@ -46,7 +46,7 @@ func Test_fixUnitConfig_16961(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotFixed, err := fixUnitConfig16961([]byte(tt.bs), &models.UnitConfig{}) + gotFixed, err := fixUnitConfig16961([]byte(tt.bs), &repo_model.UnitConfig{}) if (err != nil) != tt.wantErr { t.Errorf("fixUnitConfig_16961() error = %v, wantErr %v", err, tt.wantErr) return @@ -89,7 +89,7 @@ func Test_fixExternalWikiConfig_16961(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := &models.ExternalWikiConfig{} + cfg := &repo_model.ExternalWikiConfig{} gotFixed, err := fixExternalWikiConfig16961([]byte(tt.bs), cfg) if (err != nil) != tt.wantErr { t.Errorf("fixExternalWikiConfig_16961() error = %v, wantErr %v", err, tt.wantErr) @@ -109,14 +109,14 @@ func Test_fixExternalTrackerConfig_16961(t *testing.T) { tests := []struct { name string bs string - expected models.ExternalTrackerConfig + expected repo_model.ExternalTrackerConfig wantFixed bool wantErr bool }{ { name: "normal", bs: `{"ExternalTrackerURL":"a","ExternalTrackerFormat":"b","ExternalTrackerStyle":"c"}`, - expected: models.ExternalTrackerConfig{ + expected: repo_model.ExternalTrackerConfig{ ExternalTrackerURL: "a", ExternalTrackerFormat: "b", ExternalTrackerStyle: "c", @@ -127,7 +127,7 @@ func Test_fixExternalTrackerConfig_16961(t *testing.T) { { name: "broken", bs: "&{a b c}", - expected: models.ExternalTrackerConfig{ + expected: repo_model.ExternalTrackerConfig{ ExternalTrackerURL: "a", ExternalTrackerFormat: "b", ExternalTrackerStyle: "c", @@ -150,7 +150,7 @@ func Test_fixExternalTrackerConfig_16961(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := &models.ExternalTrackerConfig{} + cfg := &repo_model.ExternalTrackerConfig{} gotFixed, err := fixExternalTrackerConfig16961([]byte(tt.bs), cfg) if (err != nil) != tt.wantErr { t.Errorf("fixExternalTrackerConfig_16961() error = %v, wantErr %v", err, tt.wantErr) @@ -176,7 +176,7 @@ func Test_fixPullRequestsConfig_16961(t *testing.T) { tests := []struct { name string bs string - expected models.PullRequestsConfig + expected repo_model.PullRequestsConfig wantFixed bool wantErr bool }{ @@ -187,7 +187,7 @@ func Test_fixPullRequestsConfig_16961(t *testing.T) { { name: "broken - 1.14", bs: `&{%!s(bool=false) %!s(bool=true) %!s(bool=true) %!s(bool=true) %!s(bool=true) %!s(bool=false) %!s(bool=false)}`, - expected: models.PullRequestsConfig{ + expected: repo_model.PullRequestsConfig{ IgnoreWhitespaceConflicts: false, AllowMerge: true, AllowRebase: true, @@ -201,19 +201,19 @@ func Test_fixPullRequestsConfig_16961(t *testing.T) { { name: "broken - 1.15", bs: `&{%!s(bool=false) %!s(bool=true) %!s(bool=true) %!s(bool=true) %!s(bool=true) %!s(bool=false) %!s(bool=false) %!s(bool=false) merge}`, - expected: models.PullRequestsConfig{ + expected: repo_model.PullRequestsConfig{ AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, - DefaultMergeStyle: models.MergeStyleMerge, + DefaultMergeStyle: repo_model.MergeStyleMerge, }, wantFixed: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := &models.PullRequestsConfig{} + cfg := &repo_model.PullRequestsConfig{} gotFixed, err := fixPullRequestsConfig16961([]byte(tt.bs), cfg) if (err != nil) != tt.wantErr { t.Errorf("fixPullRequestsConfig_16961() error = %v, wantErr %v", err, tt.wantErr) @@ -231,14 +231,14 @@ func Test_fixIssuesConfig_16961(t *testing.T) { tests := []struct { name string bs string - expected models.IssuesConfig + expected repo_model.IssuesConfig wantFixed bool wantErr bool }{ { name: "normal", bs: `{"EnableTimetracker":true,"AllowOnlyContributorsToTrackTime":true,"EnableDependencies":true}`, - expected: models.IssuesConfig{ + expected: repo_model.IssuesConfig{ EnableTimetracker: true, AllowOnlyContributorsToTrackTime: true, EnableDependencies: true, @@ -247,7 +247,7 @@ func Test_fixIssuesConfig_16961(t *testing.T) { { name: "broken", bs: `&{%!s(bool=true) %!s(bool=true) %!s(bool=true)}`, - expected: models.IssuesConfig{ + expected: repo_model.IssuesConfig{ EnableTimetracker: true, AllowOnlyContributorsToTrackTime: true, EnableDependencies: true, @@ -257,7 +257,7 @@ func Test_fixIssuesConfig_16961(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := &models.IssuesConfig{} + cfg := &repo_model.IssuesConfig{} gotFixed, err := fixIssuesConfig16961([]byte(tt.bs), cfg) if (err != nil) != tt.wantErr { t.Errorf("fixIssuesConfig_16961() error = %v, wantErr %v", err, tt.wantErr) diff --git a/modules/doctor/mergebase.go b/modules/doctor/mergebase.go index c959da8d7f..ef78cc49d1 100644 --- a/modules/doctor/mergebase.go +++ b/modules/doctor/mergebase.go @@ -10,13 +10,14 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "xorm.io/builder" ) -func iteratePRs(repo *models.Repository, each func(*models.Repository, *models.PullRequest) error) error { +func iteratePRs(repo *repo_model.Repository, each func(*repo_model.Repository, *models.PullRequest) error) error { return db.Iterate( db.DefaultContext, new(models.PullRequest), @@ -31,9 +32,9 @@ func checkPRMergeBase(logger log.Logger, autofix bool) error { numRepos := 0 numPRs := 0 numPRsUpdated := 0 - err := iterateRepositories(func(repo *models.Repository) error { + err := iterateRepositories(func(repo *repo_model.Repository) error { numRepos++ - return iteratePRs(repo, func(repo *models.Repository, pr *models.PullRequest) error { + return iteratePRs(repo, func(repo *repo_model.Repository, pr *models.PullRequest) error { numPRs++ pr.BaseRepo = repo repoPath := repo.RepoPath() diff --git a/modules/doctor/misc.go b/modules/doctor/misc.go index 1cf8024b98..a788e5f6a9 100644 --- a/modules/doctor/misc.go +++ b/modules/doctor/misc.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -25,13 +26,13 @@ import ( "xorm.io/builder" ) -func iterateRepositories(each func(*models.Repository) error) error { +func iterateRepositories(each func(*repo_model.Repository) error) error { err := db.Iterate( db.DefaultContext, - new(models.Repository), + new(repo_model.Repository), builder.Gt{"id": 0}, func(idx int, bean interface{}) error { - return each(bean.(*models.Repository)) + return each(bean.(*repo_model.Repository)) }, ) return err @@ -48,7 +49,7 @@ func checkScriptType(logger log.Logger, autofix bool) error { } func checkHooks(logger log.Logger, autofix bool) error { - if err := iterateRepositories(func(repo *models.Repository) error { + if err := iterateRepositories(func(repo *repo_model.Repository) error { results, err := repository.CheckDelegateHooks(repo.RepoPath()) if err != nil { logger.Critical("Unable to check delegate hooks for repo %-v. ERROR: %v", repo, err) @@ -84,7 +85,7 @@ func checkEnablePushOptions(logger log.Logger, autofix bool) error { numRepos := 0 numNeedUpdate := 0 - if err := iterateRepositories(func(repo *models.Repository) error { + if err := iterateRepositories(func(repo *repo_model.Repository) error { numRepos++ r, err := git.OpenRepository(repo.RepoPath()) if err != nil { @@ -131,13 +132,13 @@ func checkDaemonExport(logger log.Logger, autofix bool) error { logger.Critical("Unable to create cache: %v", err) return err } - if err := iterateRepositories(func(repo *models.Repository) error { + if err := iterateRepositories(func(repo *repo_model.Repository) error { numRepos++ if owner, has := cache.Get(repo.OwnerID); has { repo.Owner = owner.(*user_model.User) } else { - if err := repo.GetOwner(); err != nil { + if err := repo.GetOwner(db.DefaultContext); err != nil { return err } cache.Add(repo.OwnerID, repo.Owner) diff --git a/modules/gitgraph/graph_models.go b/modules/gitgraph/graph_models.go index d7d198e01c..e7280e2adc 100644 --- a/modules/gitgraph/graph_models.go +++ b/modules/gitgraph/graph_models.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -87,7 +88,7 @@ func (graph *Graph) AddCommit(row, column int, flowID int64, data []byte) error // LoadAndProcessCommits will load the git.Commits for each commit in the graph, // the associate the commit with the user author, and check the commit verification // before finally retrieving the latest status -func (graph *Graph) LoadAndProcessCommits(repository *models.Repository, gitRepo *git.Repository) error { +func (graph *Graph) LoadAndProcessCommits(repository *repo_model.Repository, gitRepo *git.Repository) error { var err error var ok bool diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go index 97d5fb082c..1affdf73b0 100644 --- a/modules/indexer/code/bleve.go +++ b/modules/indexer/code/bleve.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/analyze" "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/git" @@ -181,7 +181,7 @@ func NewBleveIndexer(indexDir string) (*BleveIndexer, bool, error) { } func (b *BleveIndexer) addUpdate(batchWriter git.WriteCloserError, batchReader *bufio.Reader, commitSha string, - update fileUpdate, repo *models.Repository, batch *gitea_bleve.FlushingBatch) error { + update fileUpdate, repo *repo_model.Repository, batch *gitea_bleve.FlushingBatch) error { // Ignore vendored files in code search if setting.Indexer.ExcludeVendored && analyze.IsVendor(update.Filename) { return nil @@ -234,7 +234,7 @@ func (b *BleveIndexer) addUpdate(batchWriter git.WriteCloserError, batchReader * }) } -func (b *BleveIndexer) addDelete(filename string, repo *models.Repository, batch *gitea_bleve.FlushingBatch) error { +func (b *BleveIndexer) addDelete(filename string, repo *repo_model.Repository, batch *gitea_bleve.FlushingBatch) error { id := filenameIndexerID(repo.ID, filename) return batch.Delete(id) } @@ -271,7 +271,7 @@ func (b *BleveIndexer) Close() { } // Index indexes the data -func (b *BleveIndexer) Index(repo *models.Repository, sha string, changes *repoChanges) error { +func (b *BleveIndexer) Index(repo *repo_model.Repository, sha string, changes *repoChanges) error { batch := gitea_bleve.NewFlushingBatch(b.indexer, maxBatchSize) if len(changes.Updates) > 0 { diff --git a/modules/indexer/code/elastic_search.go b/modules/indexer/code/elastic_search.go index 6e0813dc15..bd5faf3b04 100644 --- a/modules/indexer/code/elastic_search.go +++ b/modules/indexer/code/elastic_search.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/analyze" "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/git" @@ -177,7 +177,7 @@ func (b *ElasticSearchIndexer) init() (bool, error) { return exists, nil } -func (b *ElasticSearchIndexer) addUpdate(batchWriter git.WriteCloserError, batchReader *bufio.Reader, sha string, update fileUpdate, repo *models.Repository) ([]elastic.BulkableRequest, error) { +func (b *ElasticSearchIndexer) addUpdate(batchWriter git.WriteCloserError, batchReader *bufio.Reader, sha string, update fileUpdate, repo *repo_model.Repository) ([]elastic.BulkableRequest, error) { // Ignore vendored files in code search if setting.Indexer.ExcludeVendored && analyze.IsVendor(update.Filename) { return nil, nil @@ -236,7 +236,7 @@ func (b *ElasticSearchIndexer) addUpdate(batchWriter git.WriteCloserError, batch }, nil } -func (b *ElasticSearchIndexer) addDelete(filename string, repo *models.Repository) elastic.BulkableRequest { +func (b *ElasticSearchIndexer) addDelete(filename string, repo *repo_model.Repository) elastic.BulkableRequest { id := filenameIndexerID(repo.ID, filename) return elastic.NewBulkDeleteRequest(). Index(b.indexerAliasName). @@ -244,7 +244,7 @@ func (b *ElasticSearchIndexer) addDelete(filename string, repo *models.Repositor } // Index will save the index data -func (b *ElasticSearchIndexer) Index(repo *models.Repository, sha string, changes *repoChanges) error { +func (b *ElasticSearchIndexer) Index(repo *repo_model.Repository, sha string, changes *repoChanges) error { reqs := make([]elastic.BulkableRequest, 0) if len(changes.Updates) > 0 { diff --git a/modules/indexer/code/git.go b/modules/indexer/code/git.go index 919d785406..b76f6d6778 100644 --- a/modules/indexer/code/git.go +++ b/modules/indexer/code/git.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -27,7 +27,7 @@ type repoChanges struct { RemovedFilenames []string } -func getDefaultBranchSha(repo *models.Repository) (string, error) { +func getDefaultBranchSha(repo *repo_model.Repository) (string, error) { stdout, err := git.NewCommand("show-ref", "-s", git.BranchPrefix+repo.DefaultBranch).RunInDir(repo.RepoPath()) if err != nil { return "", err @@ -36,8 +36,8 @@ func getDefaultBranchSha(repo *models.Repository) (string, error) { } // getRepoChanges returns changes to repo since last indexer update -func getRepoChanges(repo *models.Repository, revision string) (*repoChanges, error) { - status, err := repo.GetIndexerStatus(models.RepoIndexerTypeCode) +func getRepoChanges(repo *repo_model.Repository, revision string) (*repoChanges, error) { + status, err := repo_model.GetIndexerStatus(repo, repo_model.RepoIndexerTypeCode) if err != nil { return nil, err } @@ -89,7 +89,7 @@ func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) { } // genesisChanges get changes to add repo to the indexer for the first time -func genesisChanges(repo *models.Repository, revision string) (*repoChanges, error) { +func genesisChanges(repo *repo_model.Repository, revision string) (*repoChanges, error) { var changes repoChanges stdout, err := git.NewCommand("ls-tree", "--full-tree", "-l", "-r", revision). RunInDirBytes(repo.RepoPath()) @@ -101,7 +101,7 @@ func genesisChanges(repo *models.Repository, revision string) (*repoChanges, err } // nonGenesisChanges get changes since the previous indexer update -func nonGenesisChanges(repo *models.Repository, revision string) (*repoChanges, error) { +func nonGenesisChanges(repo *repo_model.Repository, revision string) (*repoChanges, error) { diffCmd := git.NewCommand("diff", "--name-status", repo.CodeIndexerStatus.CommitSha, revision) stdout, err := diffCmd.RunInDir(repo.RepoPath()) diff --git a/modules/indexer/code/indexer.go b/modules/indexer/code/indexer.go index c56b1b2bb0..a616d0e662 100644 --- a/modules/indexer/code/indexer.go +++ b/modules/indexer/code/indexer.go @@ -11,8 +11,8 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/queue" @@ -42,7 +42,7 @@ type SearchResultLanguages struct { // Indexer defines an interface to index and search code contents type Indexer interface { - Index(repo *models.Repository, sha string, changes *repoChanges) error + Index(repo *repo_model.Repository, sha string, changes *repoChanges) error Delete(repoID int64) error Search(repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int64, []*SearchResult, []*SearchResultLanguages, error) Close() @@ -83,8 +83,8 @@ var ( ) func index(indexer Indexer, repoID int64) error { - repo, err := models.GetRepositoryByID(repoID) - if models.IsErrRepoNotExist(err) { + repo, err := repo_model.GetRepositoryByID(repoID) + if repo_model.IsErrRepoNotExist(err) { return indexer.Delete(repoID) } if err != nil { @@ -106,7 +106,7 @@ func index(indexer Indexer, repoID int64) error { return err } - return repo.UpdateIndexerStatus(models.RepoIndexerTypeCode, sha) + return repo_model.UpdateIndexerStatus(repo, repo_model.RepoIndexerTypeCode, sha) } // Init initialize the repo indexer @@ -256,7 +256,7 @@ func Init() { } // UpdateRepoIndexer update a repository's entries in the indexer -func UpdateRepoIndexer(repo *models.Repository) { +func UpdateRepoIndexer(repo *repo_model.Repository) { indexData := &IndexerData{RepoID: repo.ID} if err := indexerQueue.Push(indexData); err != nil { log.Error("Update repo index data %v failed: %v", indexData, err) @@ -297,7 +297,7 @@ func populateRepoIndexer(ctx context.Context) { return default: } - ids, err := models.GetUnindexedRepos(models.RepoIndexerTypeCode, maxRepoID, 0, 50) + ids, err := repo_model.GetUnindexedRepos(repo_model.RepoIndexerTypeCode, maxRepoID, 0, 50) if err != nil { log.Error("populateRepoIndexer: %v", err) return diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go index b8fedcb323..98494afceb 100644 --- a/modules/indexer/code/indexer_test.go +++ b/modules/indexer/code/indexer_test.go @@ -8,6 +8,7 @@ import ( "path/filepath" "testing" + _ "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" "github.com/stretchr/testify/assert" diff --git a/modules/indexer/code/wrapped.go b/modules/indexer/code/wrapped.go index 5b19f9c625..7e97a6a324 100644 --- a/modules/indexer/code/wrapped.go +++ b/modules/indexer/code/wrapped.go @@ -8,7 +8,7 @@ import ( "fmt" "sync" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" ) var ( @@ -57,7 +57,7 @@ func (w *wrappedIndexer) get() (Indexer, error) { return w.internal, nil } -func (w *wrappedIndexer) Index(repo *models.Repository, sha string, changes *repoChanges) error { +func (w *wrappedIndexer) Index(repo *repo_model.Repository, sha string, changes *repoChanges) error { indexer, err := w.get() if err != nil { return err diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go index 0b855460bd..4db5091762 100644 --- a/modules/indexer/issues/indexer.go +++ b/modules/indexer/issues/indexer.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/queue" @@ -269,7 +270,7 @@ func populateIssueIndexer(ctx context.Context) { } // UpdateRepoIndexer add/update all issues of the repositories -func UpdateRepoIndexer(repo *models.Repository) { +func UpdateRepoIndexer(repo *repo_model.Repository) { is, err := models.Issues(&models.IssuesOptions{ RepoIDs: []int64{repo.ID}, IsClosed: util.OptionalBoolNone, @@ -310,7 +311,7 @@ func UpdateIssueIndexer(issue *models.Issue) { } // DeleteRepoIssueIndexer deletes repo's all issues indexes -func DeleteRepoIssueIndexer(repo *models.Repository) { +func DeleteRepoIssueIndexer(repo *repo_model.Repository) { var ids []int64 ids, err := models.GetIssueIDsByRepoID(repo.ID) if err != nil { diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 8353891c7c..0855165556 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -11,6 +11,7 @@ import ( "testing" "time" + _ "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" diff --git a/modules/indexer/stats/db.go b/modules/indexer/stats/db.go index 9e251d0f69..9d2942a266 100644 --- a/modules/indexer/stats/db.go +++ b/modules/indexer/stats/db.go @@ -7,7 +7,7 @@ package stats import ( "fmt" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" @@ -23,7 +23,7 @@ func (db *DBIndexer) Index(id int64) error { ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().ShutdownContext(), fmt.Sprintf("Stats.DB Index Repo[%d]", id)) defer finished() - repo, err := models.GetRepositoryByID(id) + repo, err := repo_model.GetRepositoryByID(id) if err != nil { return err } @@ -31,7 +31,7 @@ func (db *DBIndexer) Index(id int64) error { return nil } - status, err := repo.GetIndexerStatus(models.RepoIndexerTypeStats) + status, err := repo_model.GetIndexerStatus(repo, repo_model.RepoIndexerTypeStats) if err != nil { return err } @@ -64,7 +64,7 @@ func (db *DBIndexer) Index(id int64) error { log.Error("Unable to get language stats for ID %s for default branch %s in %s. Error: %v", commitID, repo.DefaultBranch, repo.RepoPath(), err) return err } - err = repo.UpdateLanguageStats(commitID, stats) + err = repo_model.UpdateLanguageStats(repo, commitID, stats) if err != nil { log.Error("Unable to update language stats for ID %s for default branch %s in %s. Error: %v", commitID, repo.DefaultBranch, repo.RepoPath(), err) return err diff --git a/modules/indexer/stats/indexer.go b/modules/indexer/stats/indexer.go index fe87a2268b..f4fe54b8cb 100644 --- a/modules/indexer/stats/indexer.go +++ b/modules/indexer/stats/indexer.go @@ -5,8 +5,8 @@ package stats import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" ) @@ -62,7 +62,7 @@ func populateRepoIndexer() { return default: } - ids, err := models.GetUnindexedRepos(models.RepoIndexerTypeStats, maxRepoID, 0, 50) + ids, err := repo_model.GetUnindexedRepos(repo_model.RepoIndexerTypeStats, maxRepoID, 0, 50) if err != nil { log.Error("populateRepoIndexer: %v", err) return diff --git a/modules/indexer/stats/indexer_test.go b/modules/indexer/stats/indexer_test.go index f52d73a32e..b32100b458 100644 --- a/modules/indexer/stats/indexer_test.go +++ b/modules/indexer/stats/indexer_test.go @@ -9,7 +9,8 @@ import ( "testing" "time" - "code.gitea.io/gitea/models" + _ "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/setting" @@ -32,12 +33,12 @@ func TestRepoStatsIndex(t *testing.T) { time.Sleep(5 * time.Second) - repo, err := models.GetRepositoryByID(1) + repo, err := repo_model.GetRepositoryByID(1) assert.NoError(t, err) - status, err := repo.GetIndexerStatus(models.RepoIndexerTypeStats) + status, err := repo_model.GetIndexerStatus(repo, repo_model.RepoIndexerTypeStats) assert.NoError(t, err) assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.CommitSha) - langs, err := repo.GetTopLanguageStats(5) + langs, err := repo_model.GetTopLanguageStats(repo, 5) assert.NoError(t, err) assert.Empty(t, langs) } diff --git a/modules/indexer/stats/queue.go b/modules/indexer/stats/queue.go index fde3f2ff01..b458444697 100644 --- a/modules/indexer/stats/queue.go +++ b/modules/indexer/stats/queue.go @@ -7,7 +7,7 @@ package stats import ( "fmt" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/queue" @@ -38,7 +38,7 @@ func initStatsQueue() error { } // UpdateRepoIndexer update a repository's entries in the indexer -func UpdateRepoIndexer(repo *models.Repository) error { +func UpdateRepoIndexer(repo *repo_model.Repository) error { if err := statsQueue.Push(repo.ID); err != nil { if err != queue.ErrAlreadyInQueue { return err diff --git a/modules/json/json.go b/modules/json/json.go index be42b6ae6c..1cbb658261 100644 --- a/modules/json/json.go +++ b/modules/json/json.go @@ -6,6 +6,7 @@ package json import ( "bytes" + "encoding/binary" "encoding/json" "io" @@ -140,3 +141,32 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { func Valid(data []byte) bool { return json.Valid(data) } + +// UnmarshalHandleDoubleEncode - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's +// possible that a Blob may be double encoded or gain an unwanted prefix of 0xff 0xfe. +func UnmarshalHandleDoubleEncode(bs []byte, v interface{}) error { + err := json.Unmarshal(bs, v) + if err != nil { + ok := true + rs := []byte{} + temp := make([]byte, 2) + for _, rn := range string(bs) { + if rn > 0xffff { + ok = false + break + } + binary.LittleEndian.PutUint16(temp, uint16(rn)) + rs = append(rs, temp...) + } + if ok { + if len(rs) > 1 && rs[0] == 0xff && rs[1] == 0xfe { + rs = rs[2:] + } + err = json.Unmarshal(rs, v) + } + } + if err != nil && len(bs) > 2 && bs[0] == 0xff && bs[1] == 0xfe { + err = json.Unmarshal(bs[2:], v) + } + return err +} diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go index 81a011fbed..376c5d103b 100644 --- a/modules/notification/action/action.go +++ b/modules/notification/action/action.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" @@ -89,7 +90,7 @@ func (a *actionNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *m } // NotifyCreateIssueComment notifies comment on an issue to notifiers -func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, +func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { act := &models.Action{ ActUserID: doer.ID, @@ -150,7 +151,7 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions } } -func (a *actionNotifier) NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) { +func (a *actionNotifier) NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string) { log.Trace("action.ChangeRepositoryName: %s/%s", doer.Name, repo.Name) if err := models.NotifyWatchers(&models.Action{ @@ -166,7 +167,7 @@ func (a *actionNotifier) NotifyRenameRepository(doer *user_model.User, repo *mod } } -func (a *actionNotifier) NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) { +func (a *actionNotifier) NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -180,7 +181,7 @@ func (a *actionNotifier) NotifyTransferRepository(doer *user_model.User, repo *m } } -func (a *actionNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func (a *actionNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -193,7 +194,7 @@ func (a *actionNotifier) NotifyCreateRepository(doer *user_model.User, u *user_m } } -func (a *actionNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { +func (a *actionNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -298,7 +299,7 @@ func (*actionNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *m } } -func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { data, err := json.Marshal(commits) if err != nil { log.Error("Marshal: %v", err) @@ -331,7 +332,7 @@ func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *models } } -func (a *actionNotifier) NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifyCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { opType := models.ActionCommitRepo if refType == "tag" { // has sent same action in `NotifyPushCommits`, so skip it. @@ -350,7 +351,7 @@ func (a *actionNotifier) NotifyCreateRef(doer *user_model.User, repo *models.Rep } } -func (a *actionNotifier) NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifyDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { opType := models.ActionDeleteBranch if refType == "tag" { // has sent same action in `NotifyPushCommits`, so skip it. @@ -369,7 +370,7 @@ func (a *actionNotifier) NotifyDeleteRef(doer *user_model.User, repo *models.Rep } } -func (a *actionNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (a *actionNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { data, err := json.Marshal(commits) if err != nil { log.Error("json.Marshal: %v", err) @@ -390,7 +391,7 @@ func (a *actionNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *mo } } -func (a *actionNotifier) NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifySyncCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: repo.OwnerID, ActUser: repo.MustOwner(), @@ -404,7 +405,7 @@ func (a *actionNotifier) NotifySyncCreateRef(doer *user_model.User, repo *models } } -func (a *actionNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: repo.OwnerID, ActUser: repo.MustOwner(), diff --git a/modules/notification/action/action_test.go b/modules/notification/action/action_test.go index 2218bd46cb..3664b82104 100644 --- a/modules/notification/action/action_test.go +++ b/modules/notification/action/action_test.go @@ -10,6 +10,7 @@ import ( "testing" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -24,7 +25,7 @@ func TestRenameRepoAction(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID}).(*repo_model.Repository) repo.Owner = user oldRepoName := repo.Name diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index 24f6375a69..937476475a 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -6,6 +6,7 @@ package base import ( "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/repository" ) @@ -14,12 +15,12 @@ import ( type Notifier interface { Run() - NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) - NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) - NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) - NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) - NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) - NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) + NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) + NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) + NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) + NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) + NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string) + NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) NotifyIssueChangeStatus(*user_model.User, *models.Issue, *models.Comment, bool) @@ -42,7 +43,7 @@ type Notifier interface { NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) - NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) NotifyUpdateComment(*user_model.User, *models.Comment, string) NotifyDeleteComment(*user_model.User, *models.Comment) @@ -51,13 +52,13 @@ type Notifier interface { NotifyUpdateRelease(doer *user_model.User, rel *models.Release) NotifyDeleteRelease(doer *user_model.User, rel *models.Release) - NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) - NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) - NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) + NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) + NotifyCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) + NotifyDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) - NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) - NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) - NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) + NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) + NotifySyncCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) + NotifySyncDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) - NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) + NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) } diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 8a977e122b..062edf400d 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -6,6 +6,7 @@ package base import ( "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/repository" ) @@ -23,7 +24,7 @@ func (*NullNotifier) Run() { } // NotifyCreateIssueComment places a place holder function -func (*NullNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, +func (*NullNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { } @@ -121,53 +122,53 @@ func (*NullNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *model } // NotifyCreateRepository places a place holder function -func (*NullNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func (*NullNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { } // NotifyDeleteRepository places a place holder function -func (*NullNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { +func (*NullNotifier) NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) { } // NotifyForkRepository places a place holder function -func (*NullNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { +func (*NullNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) { } // NotifyMigrateRepository places a place holder function -func (*NullNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func (*NullNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { } // NotifyPushCommits notifies commits pushed to notifiers -func (*NullNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (*NullNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { } // NotifyCreateRef notifies branch or tag creation to notifiers -func (*NullNotifier) NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifyCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { } // NotifyDeleteRef notifies branch or tag deletion to notifiers -func (*NullNotifier) NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifyDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { } // NotifyRenameRepository places a place holder function -func (*NullNotifier) NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) { +func (*NullNotifier) NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string) { } // NotifyTransferRepository places a place holder function -func (*NullNotifier) NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) { +func (*NullNotifier) NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) { } // NotifySyncPushCommits places a place holder function -func (*NullNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (*NullNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { } // NotifySyncCreateRef places a place holder function -func (*NullNotifier) NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifySyncCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { } // NotifySyncDeleteRef places a place holder function -func (*NullNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { } // NotifyRepoPendingTransfer places a place holder function -func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { +func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) { } diff --git a/modules/notification/indexer/indexer.go b/modules/notification/indexer/indexer.go index 03914db03b..92fe3c5019 100644 --- a/modules/notification/indexer/indexer.go +++ b/modules/notification/indexer/indexer.go @@ -6,6 +6,7 @@ package indexer import ( "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" code_indexer "code.gitea.io/gitea/modules/indexer/code" @@ -30,7 +31,7 @@ func NewNotifier() base.Notifier { return &indexerNotifier{} } -func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, +func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { if comment.Type == models.CommentTypeComment { if issue.Comments == nil { @@ -107,14 +108,14 @@ func (r *indexerNotifier) NotifyDeleteComment(doer *user_model.User, comment *mo } } -func (r *indexerNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { +func (r *indexerNotifier) NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) { issue_indexer.DeleteRepoIssueIndexer(repo) if setting.Indexer.RepoIndexerEnabled { code_indexer.UpdateRepoIndexer(repo) } } -func (r *indexerNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func (r *indexerNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { issue_indexer.UpdateRepoIndexer(repo) if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty { code_indexer.UpdateRepoIndexer(repo) @@ -124,7 +125,7 @@ func (r *indexerNotifier) NotifyMigrateRepository(doer *user_model.User, u *user } } -func (r *indexerNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (r *indexerNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch { code_indexer.UpdateRepoIndexer(repo) } @@ -133,7 +134,7 @@ func (r *indexerNotifier) NotifyPushCommits(pusher *user_model.User, repo *model } } -func (r *indexerNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (r *indexerNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch { code_indexer.UpdateRepoIndexer(repo) } diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go index c1c9e96135..6ad0ca0d85 100644 --- a/modules/notification/mail/mail.go +++ b/modules/notification/mail/mail.go @@ -8,6 +8,7 @@ import ( "fmt" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" @@ -27,7 +28,7 @@ func NewNotifier() base.Notifier { return &mailNotifier{} } -func (m *mailNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, +func (m *mailNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { var act models.ActionType if comment.Type == models.CommentTypeClose { @@ -184,7 +185,7 @@ func (m *mailNotifier) NotifyNewRelease(rel *models.Release) { mailer.MailNewRelease(rel) } -func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { +func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) { if err := mailer.SendRepoTransferNotifyMail(doer, newOwner, repo); err != nil { log.Error("NotifyRepoPendingTransfer: %v", err) } diff --git a/modules/notification/notification.go b/modules/notification/notification.go index 9bea38faf6..d976dfea66 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -6,6 +6,7 @@ package notification import ( "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/notification/base" @@ -39,7 +40,7 @@ func NewContext() { } // NotifyCreateIssueComment notifies issue comment related message to notifiers -func NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, +func NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { for _, notifier := range notifiers { notifier.NotifyCreateIssueComment(doer, repo, issue, comment, mentions) @@ -209,91 +210,91 @@ func NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue, } // NotifyCreateRepository notifies create repository to notifiers -func NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { notifier.NotifyCreateRepository(doer, u, repo) } } // NotifyMigrateRepository notifies create repository to notifiers -func NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { notifier.NotifyMigrateRepository(doer, u, repo) } } // NotifyTransferRepository notifies create repository to notifiers -func NotifyTransferRepository(doer *user_model.User, repo *models.Repository, newOwnerName string) { +func NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, newOwnerName string) { for _, notifier := range notifiers { notifier.NotifyTransferRepository(doer, repo, newOwnerName) } } // NotifyDeleteRepository notifies delete repository to notifiers -func NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { +func NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { notifier.NotifyDeleteRepository(doer, repo) } } // NotifyForkRepository notifies fork repository to notifiers -func NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { +func NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) { for _, notifier := range notifiers { notifier.NotifyForkRepository(doer, oldRepo, repo) } } // NotifyRenameRepository notifies repository renamed -func NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldName string) { +func NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldName string) { for _, notifier := range notifiers { notifier.NotifyRenameRepository(doer, repo, oldName) } } // NotifyPushCommits notifies commits pushed to notifiers -func NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { for _, notifier := range notifiers { notifier.NotifyPushCommits(pusher, repo, opts, commits) } } // NotifyCreateRef notifies branch or tag creation to notifiers -func NotifyCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func NotifyCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifyCreateRef(pusher, repo, refType, refFullName) } } // NotifyDeleteRef notifies branch or tag deletion to notifiers -func NotifyDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func NotifyDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifyDeleteRef(pusher, repo, refType, refFullName) } } // NotifySyncPushCommits notifies commits pushed to notifiers -func NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { for _, notifier := range notifiers { notifier.NotifySyncPushCommits(pusher, repo, opts, commits) } } // NotifySyncCreateRef notifies branch or tag creation to notifiers -func NotifySyncCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func NotifySyncCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifySyncCreateRef(pusher, repo, refType, refFullName) } } // NotifySyncDeleteRef notifies branch or tag deletion to notifiers -func NotifySyncDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func NotifySyncDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName) } } // NotifyRepoPendingTransfer notifies creation of pending transfer to notifiers -func NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { +func NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { notifier.NotifyRepoPendingTransfer(doer, newOwner, repo) } diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go index 04967fc589..25f015d0e5 100644 --- a/modules/notification/ui/ui.go +++ b/modules/notification/ui/ui.go @@ -6,6 +6,7 @@ package ui import ( "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" @@ -51,7 +52,7 @@ func (ns *notificationService) Run() { graceful.GetManager().RunWithShutdownFns(ns.issueQueue.Run) } -func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, +func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { var opts = issueNotificationOpts{ IssueID: issue.ID, @@ -233,7 +234,7 @@ func (ns *notificationService) NotifyPullReviewRequest(doer *user_model.User, is } } -func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { +func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) { if err := models.CreateRepoTransferNotification(doer, newOwner, repo); err != nil { log.Error("NotifyRepoPendingTransfer: %v", err) } diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index 378e7fd202..7e96ed0501 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -7,6 +7,7 @@ package webhook import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" @@ -73,7 +74,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *m } } -func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { +func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) { oldMode, _ := models.AccessLevel(doer, oldRepo) mode, _ := models.AccessLevel(doer, repo) @@ -101,7 +102,7 @@ func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, r } } -func (m *webhookNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func (m *webhookNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { // Add to hook queue for created repo after session commit. if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{ Action: api.HookRepoCreated, @@ -113,7 +114,7 @@ func (m *webhookNotifier) NotifyCreateRepository(doer *user_model.User, u *user_ } } -func (m *webhookNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { +func (m *webhookNotifier) NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) { u := repo.MustOwner() if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{ @@ -126,7 +127,7 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *user_model.User, repo *mo } } -func (m *webhookNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { +func (m *webhookNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) { // Add to hook queue for created repo after session commit. if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{ Action: api.HookRepoCreated, @@ -402,7 +403,7 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *models.C } } -func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, +func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { mode, _ := models.AccessLevel(doer, repo) @@ -564,7 +565,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issu } } -func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { apiPusher := convert.ToUser(pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -697,7 +698,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review } } -func (m *webhookNotifier) NotifyCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifyCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { apiPusher := convert.ToUser(pusher, nil) apiRepo := convert.ToRepo(repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) @@ -748,7 +749,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *user_model.User, p } } -func (m *webhookNotifier) NotifyDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifyDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { apiPusher := convert.ToUser(pusher, nil) apiRepo := convert.ToRepo(repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) @@ -793,7 +794,7 @@ func (m *webhookNotifier) NotifyDeleteRelease(doer *user_model.User, rel *models sendReleaseHook(doer, rel, api.HookReleaseDeleted) } -func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { apiPusher := convert.ToUser(pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -816,10 +817,10 @@ func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *m } } -func (m *webhookNotifier) NotifySyncCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifySyncCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { m.NotifyCreateRef(pusher, repo, refType, refFullName) } -func (m *webhookNotifier) NotifySyncDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifySyncDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { m.NotifyDeleteRef(pusher, repo, refType, refFullName) } diff --git a/modules/repofiles/commit_status.go b/modules/repofiles/commit_status.go index 2074b4b464..21aaa9ee59 100644 --- a/modules/repofiles/commit_status.go +++ b/modules/repofiles/commit_status.go @@ -8,6 +8,7 @@ import ( "fmt" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" ) @@ -15,7 +16,7 @@ import ( // CreateCommitStatus creates a new CommitStatus given a bunch of parameters // NOTE: All text-values will be trimmed from whitespaces. // Requires: Repo, Creator, SHA -func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { +func CreateCommitStatus(repo *repo_model.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { repoPath := repo.RepoPath() // confirm that commit is exist diff --git a/modules/repository/commits_test.go b/modules/repository/commits_test.go index b6a63dc127..30edf3362e 100644 --- a/modules/repository/commits_test.go +++ b/modules/repository/commits_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/git" @@ -49,7 +49,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) { } pushCommits.HeadCommit = &PushCommit{Sha1: "69554a6"} - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 16}).(*repo_model.Repository) payloadCommits, headCommit, err := pushCommits.ToAPIPayloadCommits(repo.RepoPath(), "/user2/repo16") assert.NoError(t, err) assert.Len(t, payloadCommits, 3) diff --git a/modules/repository/create.go b/modules/repository/create.go index 850f7488bd..ddc001d600 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -19,7 +20,7 @@ import ( ) // CreateRepository creates a repository for the user/organization. -func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) { +func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*repo_model.Repository, error) { if !doer.IsAdmin && !u.CanCreateRepo() { return nil, models.ErrReachLimitOfRepo{ Limit: u.MaxRepoCreation, @@ -37,7 +38,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) ( } } - repo := &models.Repository{ + repo := &repo_model.Repository{ OwnerID: u.ID, Owner: u, OwnerName: u.Name, @@ -55,7 +56,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) ( TrustModel: opts.TrustModel, } - var rollbackRepo *models.Repository + var rollbackRepo *repo_model.Repository if err := db.WithTx(func(ctx context.Context) error { if err := models.CreateRepository(ctx, doer, u, repo, false); err != nil { @@ -67,7 +68,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) ( return nil } - repoPath := models.RepoPath(u.Name, repo.Name) + repoPath := repo_model.RepoPath(u.Name, repo.Name) isExist, err := util.IsExist(repoPath) if err != nil { log.Error("Unable to check if %s exists. Error: %v", repoPath, err) @@ -106,7 +107,7 @@ func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) ( } } - if err := repo.CheckDaemonExportOK(ctx); err != nil { + if err := models.CheckDaemonExportOK(ctx, repo); err != nil { return fmt.Errorf("checkDaemonExportOK: %v", err) } diff --git a/modules/repository/generate.go b/modules/repository/generate.go index 61a8b0d111..756cfe227e 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -14,6 +14,7 @@ import ( "time" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -45,7 +46,7 @@ var defaultTransformers = []transformer{ {Name: "TITLE", Transform: strings.Title}, } -func generateExpansion(src string, templateRepo, generateRepo *models.Repository) string { +func generateExpansion(src string, templateRepo, generateRepo *repo_model.Repository) string { expansions := []expansion{ {Name: "REPO_NAME", Value: generateRepo.Name, Transformers: defaultTransformers}, {Name: "TEMPLATE_NAME", Value: templateRepo.Name, Transformers: defaultTransformers}, @@ -98,7 +99,7 @@ func checkGiteaTemplate(tmpDir string) (*models.GiteaTemplate, error) { return gt, nil } -func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmpDir string) error { +func generateRepoCommit(repo, templateRepo, generateRepo *repo_model.Repository, tmpDir string) error { commitTimeStr := time.Now().Format(time.RFC3339) authorSig := repo.Owner.NewGitSig() @@ -186,7 +187,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp return initRepoCommit(tmpDir, repo, repo.Owner, templateRepo.DefaultBranch) } -func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *models.Repository) (err error) { +func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository) (err error) { tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name) if err != nil { return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err) @@ -203,7 +204,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *m } // re-fetch repo - if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil { + if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil { return fmt.Errorf("getRepositoryByID: %v", err) } @@ -224,12 +225,12 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *m } // GenerateGitContent generates git content from a template repository -func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models.Repository) error { +func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error { if err := generateGitContent(ctx, generateRepo, templateRepo, generateRepo); err != nil { return err } - if err := generateRepo.UpdateSize(ctx); err != nil { + if err := models.UpdateRepoSize(ctx, generateRepo); err != nil { return fmt.Errorf("failed to update size for repository: %v", err) } @@ -240,8 +241,8 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models. } // GenerateRepository generates a repository from a template -func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) { - generateRepo := &models.Repository{ +func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *repo_model.Repository, opts models.GenerateRepoOptions) (_ *repo_model.Repository, err error) { + generateRepo := &repo_model.Repository{ OwnerID: owner.ID, Owner: owner, OwnerName: owner.Name, @@ -276,7 +277,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ return generateRepo, err } - if err = generateRepo.CheckDaemonExportOK(ctx); err != nil { + if err = models.CheckDaemonExportOK(ctx, generateRepo); err != nil { return generateRepo, fmt.Errorf("checkDaemonExportOK: %v", err) } diff --git a/modules/repository/init.go b/modules/repository/init.go index d7f31fabde..cfee1a3215 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -14,6 +14,7 @@ import ( "time" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -23,7 +24,7 @@ import ( "github.com/unknwon/com" ) -func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error { +func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error { commitTimeStr := time.Now().Format(time.RFC3339) authorSig := repo.Owner.NewGitSig() @@ -101,7 +102,7 @@ func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, rep } // initRepoCommit temporarily changes with work directory. -func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, defaultBranch string) (err error) { +func initRepoCommit(tmpPath string, repo *repo_model.Repository, u *user_model.User, defaultBranch string) (err error) { commitTimeStr := time.Now().Format(time.RFC3339) sig := u.NewGitSig() @@ -137,7 +138,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, if sign { args = append(args, "-S"+keyID) - if repo.GetTrustModel() == models.CommitterTrustModel || repo.GetTrustModel() == models.CollaboratorCommitterTrustModel { + if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { // need to set the committer to the KeyID owner committerName = signer.Name committerEmail = signer.Email @@ -175,7 +176,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, func checkInitRepository(owner, name string) (err error) { // Somehow the directory could exist. - repoPath := models.RepoPath(owner, name) + repoPath := repo_model.RepoPath(owner, name) isExist, err := util.IsExist(repoPath) if err != nil { log.Error("Unable to check if %s exists. Error: %v", repoPath, err) @@ -198,7 +199,7 @@ func checkInitRepository(owner, name string) (err error) { } // InitRepository initializes README and .gitignore if needed. -func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { +func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, opts models.CreateRepoOptions) (err error) { if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil { return err } @@ -227,7 +228,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re // Re-fetch the repository from database before updating it (else it would // override changes that were done earlier with sql) - if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil { + if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil { return fmt.Errorf("getRepositoryByID: %v", err) } diff --git a/modules/repository/push.go b/modules/repository/push.go index 11272f883d..038735f585 100644 --- a/modules/repository/push.go +++ b/modules/repository/push.go @@ -7,7 +7,7 @@ package repository import ( "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" ) @@ -104,7 +104,7 @@ func IsForcePush(opts *PushUpdateOptions) (bool, error) { } output, err := git.NewCommand("rev-list", "--max-count=1", opts.OldCommitID, "^"+opts.NewCommitID). - RunInDir(models.RepoPath(opts.RepoUserName, opts.RepoName)) + RunInDir(repo_model.RepoPath(opts.RepoUserName, opts.RepoName)) if err != nil { return false, err } else if len(output) > 0 { diff --git a/modules/repository/repo.go b/modules/repository/repo.go index c7145658f8..d04cd28a59 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" @@ -48,10 +49,10 @@ func WikiRemoteURL(remote string) string { // MigrateRepositoryGitData starts migrating git related data after created migrating repository func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, - repo *models.Repository, opts migration.MigrateOptions, + repo *repo_model.Repository, opts migration.MigrateOptions, httpTransport *http.Transport, -) (*models.Repository, error) { - repoPath := models.RepoPath(u.Name, opts.RepoName) +) (*repo_model.Repository, error) { + repoPath := repo_model.RepoPath(u.Name, opts.RepoName) if u.IsOrganization() { t, err := models.OrgFromUser(u).GetOwnerTeam() @@ -79,7 +80,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, } if opts.Wiki { - wikiPath := models.WikiPath(u.Name, opts.RepoName) + wikiPath := repo_model.WikiPath(u.Name, opts.RepoName) wikiRemotePath := WikiRemoteURL(opts.CloneAddr) if len(wikiRemotePath) > 0 { if err := util.RemoveAll(wikiPath); err != nil { @@ -104,7 +105,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, repo.Owner = u } - if err = repo.CheckDaemonExportOK(ctx); err != nil { + if err = models.CheckDaemonExportOK(ctx, repo); err != nil { return repo, fmt.Errorf("checkDaemonExportOK: %v", err) } @@ -153,12 +154,12 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, } } - if err = repo.UpdateSize(db.DefaultContext); err != nil { + if err = models.UpdateRepoSize(db.DefaultContext, repo); err != nil { log.Error("Failed to update size for repository: %v", err) } if opts.Mirror { - mirrorModel := models.Mirror{ + mirrorModel := repo_model.Mirror{ RepoID: repo.ID, Interval: setting.Mirror.DefaultInterval, EnablePrune: true, @@ -188,7 +189,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, } } - if err = models.InsertMirror(&mirrorModel); err != nil { + if err = repo_model.InsertMirror(&mirrorModel); err != nil { return repo, fmt.Errorf("InsertOne: %v", err) } @@ -216,7 +217,7 @@ func cleanUpMigrateGitConfig(configPath string) error { } // CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors. -func CleanUpMigrateInfo(repo *models.Repository) (*models.Repository, error) { +func CleanUpMigrateInfo(repo *repo_model.Repository) (*repo_model.Repository, error) { repoPath := repo.RepoPath() if err := createDelegateHooks(repoPath); err != nil { return repo, fmt.Errorf("createDelegateHooks: %v", err) @@ -242,7 +243,7 @@ func CleanUpMigrateInfo(repo *models.Repository) (*models.Repository, error) { } // SyncReleasesWithTags synchronizes release table with repository tags -func SyncReleasesWithTags(repo *models.Repository, gitRepo *git.Repository) error { +func SyncReleasesWithTags(repo *repo_model.Repository, gitRepo *git.Repository) error { existingRelTags := make(map[string]struct{}) opts := models.FindReleasesOptions{ IncludeDrafts: true, @@ -290,7 +291,7 @@ func SyncReleasesWithTags(repo *models.Repository, gitRepo *git.Repository) erro } // PushUpdateAddTag must be called for any push actions to add tag -func PushUpdateAddTag(repo *models.Repository, gitRepo *git.Repository, tagName string) error { +func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagName string) error { tag, err := gitRepo.GetTag(tagName) if err != nil { return fmt.Errorf("GetTag: %v", err) @@ -341,7 +342,7 @@ func PushUpdateAddTag(repo *models.Repository, gitRepo *git.Repository, tagName } // StoreMissingLfsObjectsInRepository downloads missing LFS objects -func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *models.Repository, gitRepo *git.Repository, lfsClient lfs.Client) error { +func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, lfsClient lfs.Client) error { contentStore := lfs.NewContentStore() pointerChan := make(chan lfs.PointerBlob) @@ -364,7 +365,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *models.Reposi if err := contentStore.Put(p, content); err != nil { log.Error("Error storing content for LFS meta object %v: %v", p, err) - if _, err2 := repo.RemoveLFSMetaObjectByOid(p.Oid); err2 != nil { + if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, p.Oid); err2 != nil { log.Error("Error removing LFS meta object %v: %v", p, err2) } return err @@ -383,7 +384,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *models.Reposi var batch []lfs.Pointer for pointerBlob := range pointerChan { - meta, err := repo.GetLFSMetaObjectByOid(pointerBlob.Oid) + meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid) if err != nil && err != models.ErrLFSObjectNotExist { log.Error("Error querying LFS meta object %v: %v", pointerBlob.Pointer, err) return err diff --git a/modules/templates/helper.go b/modules/templates/helper.go index eb0c7f7e71..f4529503d8 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -24,6 +24,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/avatars" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/emoji" @@ -581,7 +582,7 @@ func AvatarByAction(action *models.Action, others ...interface{}) template.HTML } // RepoAvatar renders repo avatars. args: repo, size(int), class (string) -func RepoAvatar(repo *models.Repository, others ...interface{}) template.HTML { +func RepoAvatar(repo *repo_model.Repository, others ...interface{}) template.HTML { size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...) src := repo.RelAvatarLink() @@ -953,7 +954,7 @@ type remoteAddress struct { Password string } -func mirrorRemoteAddress(m models.RemoteMirrorer) remoteAddress { +func mirrorRemoteAddress(m repo_model.RemoteMirrorer) remoteAddress { a := remoteAddress{} u, err := git.GetRemoteAddress(git.DefaultContext, m.GetRepository().RepoPath(), m.GetRemoteName()) diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index 548e454c8e..1f893122f3 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -14,6 +14,8 @@ import ( "testing" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" @@ -54,7 +56,7 @@ func MockContext(t *testing.T, path string) *context.Context { // LoadRepo load a repo into a test context. func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) { ctx.Repo = &context.Repository{} - ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository) + ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}).(*repo_model.Repository) var err error ctx.Repo.Owner, err = user_model.GetUserByID(ctx.Repo.Repository.OwnerID) assert.NoError(t, err) @@ -85,7 +87,7 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) { // LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has // already been populated. func LoadGitRepo(t *testing.T, ctx *context.Context) { - assert.NoError(t, ctx.Repo.Repository.GetOwner()) + assert.NoError(t, ctx.Repo.Repository.GetOwner(db.DefaultContext)) var err error ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath()) assert.NoError(t, err) |