diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-12-10 09:27:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 09:27:50 +0800 |
commit | 719bddcd76610a63dadc8555760072957a11cf30 (patch) | |
tree | 0df26092fba7e3e21444fe493e6b349473b6b0cb /models/issue_xref.go | |
parent | fb8166c6c6b652a0e6fa98681780a6a71090faf3 (diff) | |
download | gitea-719bddcd76610a63dadc8555760072957a11cf30.tar.gz gitea-719bddcd76610a63dadc8555760072957a11cf30.zip |
Move repository model into models/repo (#17933)
* Some refactors related repository model
* Move more methods out of repository
* Move repository into models/repo
* Fix test
* Fix test
* some improvements
* Remove unnecessary function
Diffstat (limited to 'models/issue_xref.go')
-rw-r--r-- | models/issue_xref.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/models/issue_xref.go b/models/issue_xref.go index ceaff62be1..fdabedf29a 100644 --- a/models/issue_xref.go +++ b/models/issue_xref.go @@ -9,6 +9,7 @@ import ( "fmt" "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/references" @@ -79,7 +80,7 @@ func (issue *Issue) addCrossReferences(stdCtx context.Context, doer *user_model. func (issue *Issue) createCrossReferences(stdCtx context.Context, ctx *crossReferencesContext, plaincontent, mdcontent string) error { e := db.GetEngine(stdCtx) - xreflist, err := ctx.OrigIssue.getCrossReferences(e, ctx, plaincontent, mdcontent) + xreflist, err := ctx.OrigIssue.getCrossReferences(stdCtx, ctx, plaincontent, mdcontent) if err != nil { return err } @@ -136,35 +137,34 @@ func (issue *Issue) createCrossReferences(stdCtx context.Context, ctx *crossRefe return nil } -func (issue *Issue) getCrossReferences(e db.Engine, ctx *crossReferencesContext, plaincontent, mdcontent string) ([]*crossReference, error) { +func (issue *Issue) getCrossReferences(stdCtx context.Context, ctx *crossReferencesContext, plaincontent, mdcontent string) ([]*crossReference, error) { xreflist := make([]*crossReference, 0, 5) var ( - refRepo *Repository + refRepo *repo_model.Repository refIssue *Issue refAction references.XRefAction err error ) allrefs := append(references.FindAllIssueReferences(plaincontent), references.FindAllIssueReferencesMarkdown(mdcontent)...) - for _, ref := range allrefs { if ref.Owner == "" && ref.Name == "" { // Issues in the same repository - if err := ctx.OrigIssue.loadRepo(e); err != nil { + if err := ctx.OrigIssue.loadRepo(stdCtx); err != nil { return nil, err } refRepo = ctx.OrigIssue.Repo } else { // Issues in other repositories - refRepo, err = getRepositoryByOwnerAndName(e, ref.Owner, ref.Name) + refRepo, err = repo_model.GetRepositoryByOwnerAndNameCtx(stdCtx, ref.Owner, ref.Name) if err != nil { - if IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { continue } return nil, err } } - if refIssue, refAction, err = ctx.OrigIssue.verifyReferencedIssue(e, ctx, refRepo, ref); err != nil { + if refIssue, refAction, err = ctx.OrigIssue.verifyReferencedIssue(stdCtx, ctx, refRepo, ref); err != nil { return nil, err } if refIssue != nil { @@ -194,15 +194,16 @@ func (issue *Issue) updateCrossReferenceList(list []*crossReference, xref *cross } // verifyReferencedIssue will check if the referenced issue exists, and whether the doer has permission to do what -func (issue *Issue) verifyReferencedIssue(e db.Engine, ctx *crossReferencesContext, repo *Repository, +func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossReferencesContext, repo *repo_model.Repository, ref references.IssueReference) (*Issue, references.XRefAction, error) { refIssue := &Issue{RepoID: repo.ID, Index: ref.Index} refAction := ref.Action + e := db.GetEngine(stdCtx) if has, _ := e.Get(refIssue); !has { return nil, references.XRefActionNone, nil } - if err := refIssue.loadRepo(e); err != nil { + if err := refIssue.loadRepo(stdCtx); err != nil { return nil, references.XRefActionNone, err } @@ -213,7 +214,7 @@ func (issue *Issue) verifyReferencedIssue(e db.Engine, ctx *crossReferencesConte // Check doer permissions; set action to None if the doer can't change the destination if refIssue.RepoID != ctx.OrigIssue.RepoID || ref.Action != references.XRefActionNone { - perm, err := getUserRepoPermission(e, refIssue.Repo, ctx.Doer) + perm, err := getUserRepoPermission(stdCtx, refIssue.Repo, ctx.Doer) if err != nil { return nil, references.XRefActionNone, err } @@ -280,7 +281,7 @@ func (comment *Comment) LoadRefIssue() (err error) { } comment.RefIssue, err = GetIssueByID(comment.RefIssueID) if err == nil { - err = comment.RefIssue.loadRepo(db.GetEngine(db.DefaultContext)) + err = comment.RefIssue.loadRepo(db.DefaultContext) } return } |