aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_comment.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-12-10 09:27:50 +0800
committerGitHub <noreply@github.com>2021-12-10 09:27:50 +0800
commit719bddcd76610a63dadc8555760072957a11cf30 (patch)
tree0df26092fba7e3e21444fe493e6b349473b6b0cb /models/issue_comment.go
parentfb8166c6c6b652a0e6fa98681780a6a71090faf3 (diff)
downloadgitea-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_comment.go')
-rw-r--r--models/issue_comment.go51
1 files changed, 26 insertions, 25 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go
index 417caccfaf..754fa3439e 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -219,9 +219,9 @@ type Comment struct {
RefAction references.XRefAction `xorm:"SMALLINT"` // What happens if RefIssueID resolves
RefIsPull bool
- RefRepo *Repository `xorm:"-"`
- RefIssue *Issue `xorm:"-"`
- RefComment *Comment `xorm:"-"`
+ RefRepo *repo_model.Repository `xorm:"-"`
+ RefIssue *Issue `xorm:"-"`
+ RefComment *Comment `xorm:"-"`
Commits []*SignCommitWithStatuses `xorm:"-"`
OldCommit string `xorm:"-"`
@@ -316,7 +316,7 @@ func (c *Comment) HTMLURL() string {
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.loadRepo(db.GetEngine(db.DefaultContext))
+ err = c.Issue.loadRepo(db.DefaultContext)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -345,7 +345,7 @@ func (c *Comment) APIURL() string {
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.loadRepo(db.GetEngine(db.DefaultContext))
+ err = c.Issue.loadRepo(db.DefaultContext)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -366,7 +366,7 @@ func (c *Comment) IssueURL() string {
return ""
}
- err = c.Issue.loadRepo(db.GetEngine(db.DefaultContext))
+ err = c.Issue.loadRepo(db.DefaultContext)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -382,7 +382,7 @@ func (c *Comment) PRURL() string {
return ""
}
- err = c.Issue.loadRepo(db.GetEngine(db.DefaultContext))
+ err = c.Issue.loadRepo(db.DefaultContext)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -536,7 +536,7 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
return err
}
- if err = c.Issue.Repo.GetOwner(); err != nil {
+ if err = c.Issue.Repo.GetOwner(db.DefaultContext); err != nil {
return err
}
@@ -589,7 +589,7 @@ func (c *Comment) LoadTime() error {
return err
}
-func (c *Comment) loadReactions(e db.Engine, repo *Repository) (err error) {
+func (c *Comment) loadReactions(e db.Engine, repo *repo_model.Repository) (err error) {
if c.Reactions != nil {
return nil
}
@@ -608,7 +608,7 @@ func (c *Comment) loadReactions(e db.Engine, repo *Repository) (err error) {
}
// LoadReactions loads comment reactions
-func (c *Comment) LoadReactions(repo *Repository) error {
+func (c *Comment) LoadReactions(repo *repo_model.Repository) error {
return c.loadReactions(db.GetEngine(db.DefaultContext), repo)
}
@@ -675,7 +675,7 @@ func (c *Comment) CodeCommentURL() string {
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.loadRepo(db.GetEngine(db.DefaultContext))
+ err = c.Issue.loadRepo(db.DefaultContext)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -764,7 +764,7 @@ func createComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
return nil, err
}
- if err = opts.Repo.getOwner(e); err != nil {
+ if err = opts.Repo.GetOwner(ctx); err != nil {
return nil, err
}
@@ -843,7 +843,7 @@ func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Is
content = newDeadlineUnix.Format("2006-01-02") + "|" + issue.DeadlineUnix.Format("2006-01-02")
}
- if err := issue.loadRepo(db.GetEngine(ctx)); err != nil {
+ if err := issue.loadRepo(ctx); err != nil {
return nil, err
}
@@ -867,7 +867,7 @@ func createIssueDependencyComment(ctx context.Context, doer *user_model.User, is
if !add {
cType = CommentTypeRemoveDependency
}
- if err = issue.loadRepo(db.GetEngine(ctx)); err != nil {
+ if err = issue.loadRepo(ctx); err != nil {
return
}
@@ -898,7 +898,7 @@ func createIssueDependencyComment(ctx context.Context, doer *user_model.User, is
type CreateCommentOptions struct {
Type CommentType
Doer *user_model.User
- Repo *Repository
+ Repo *repo_model.Repository
Issue *Issue
Label *Label
@@ -953,7 +953,7 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
}
// CreateRefComment creates a commit reference comment to issue.
-func CreateRefComment(doer *user_model.User, repo *Repository, issue *Issue, content, commitSHA string) error {
+func CreateRefComment(doer *user_model.User, repo *repo_model.Repository, issue *Issue, content, commitSHA string) error {
if len(commitSHA) == 0 {
return fmt.Errorf("cannot create reference with empty commit SHA")
}
@@ -1144,11 +1144,11 @@ func deleteComment(e db.Engine, comment *Comment) error {
// CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS
type CodeComments map[string]map[int64][]*Comment
-func fetchCodeComments(e db.Engine, issue *Issue, currentUser *user_model.User) (CodeComments, error) {
- return fetchCodeCommentsByReview(e, issue, currentUser, nil)
+func fetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User) (CodeComments, error) {
+ return fetchCodeCommentsByReview(ctx, issue, currentUser, nil)
}
-func fetchCodeCommentsByReview(e db.Engine, issue *Issue, currentUser *user_model.User, review *Review) (CodeComments, error) {
+func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *user_model.User, review *Review) (CodeComments, error) {
pathToLineToComment := make(CodeComments)
if review == nil {
review = &Review{ID: 0}
@@ -1159,7 +1159,7 @@ func fetchCodeCommentsByReview(e db.Engine, issue *Issue, currentUser *user_mode
ReviewID: review.ID,
}
- comments, err := findCodeComments(e, opts, issue, currentUser, review)
+ comments, err := findCodeComments(ctx, opts, issue, currentUser, review)
if err != nil {
return nil, err
}
@@ -1173,7 +1173,7 @@ func fetchCodeCommentsByReview(e db.Engine, issue *Issue, currentUser *user_mode
return pathToLineToComment, nil
}
-func findCodeComments(e db.Engine, opts FindCommentsOptions, issue *Issue, currentUser *user_model.User, review *Review) ([]*Comment, error) {
+func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issue, currentUser *user_model.User, review *Review) ([]*Comment, error) {
var comments []*Comment
if review == nil {
review = &Review{ID: 0}
@@ -1182,6 +1182,7 @@ func findCodeComments(e db.Engine, opts FindCommentsOptions, issue *Issue, curre
if review.ID == 0 {
conds = conds.And(builder.Eq{"invalidated": false})
}
+ e := db.GetEngine(ctx)
if err := e.Where(conds).
Asc("comment.created_unix").
Asc("comment.id").
@@ -1189,7 +1190,7 @@ func findCodeComments(e db.Engine, opts FindCommentsOptions, issue *Issue, curre
return nil, err
}
- if err := issue.loadRepo(e); err != nil {
+ if err := issue.loadRepo(ctx); err != nil {
return nil, err
}
@@ -1249,12 +1250,12 @@ func FetchCodeCommentsByLine(issue *Issue, currentUser *user_model.User, treePat
TreePath: treePath,
Line: line,
}
- return findCodeComments(db.GetEngine(db.DefaultContext), opts, issue, currentUser, nil)
+ return findCodeComments(db.DefaultContext, opts, issue, currentUser, nil)
}
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
func FetchCodeComments(issue *Issue, currentUser *user_model.User) (CodeComments, error) {
- return fetchCodeComments(db.GetEngine(db.DefaultContext), issue, currentUser)
+ return fetchCodeComments(db.DefaultContext, issue, currentUser)
}
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
@@ -1313,7 +1314,7 @@ func CreatePushPullComment(pusher *user_model.User, pr *PullRequest, oldCommitID
// getCommitsFromRepo get commit IDs from repo in between oldCommitID and newCommitID
// isForcePush will be true if oldCommit isn't on the branch
// Commit on baseBranch will skip
-func getCommitIDsFromRepo(repo *Repository, oldCommitID, newCommitID, baseBranch string) (commitIDs []string, isForcePush bool, err error) {
+func getCommitIDsFromRepo(repo *repo_model.Repository, oldCommitID, newCommitID, baseBranch string) (commitIDs []string, isForcePush bool, err error) {
repoPath := repo.RepoPath()
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {