Browse Source

Исправлена работа с родителями и комментариями #31

repo_rename
parent
commit
f310ff2fa0
  1. 22
      models/issue_comment.go
  2. 67
      models/issue_comment_list.go
  3. 10
      modules/convert/issue_comment.go
  4. 2
      modules/structs/issue_comment.go
  5. 7
      routers/web/repo/issue.go
  6. 50
      templates/repo/issue/view_content/comments.tmpl

22
models/issue_comment.go

@ -82,10 +82,6 @@ const (
CommentTypeAddDependency CommentTypeAddDependency
// 20 Dependency removed // 20 Dependency removed
CommentTypeRemoveDependency CommentTypeRemoveDependency
// 19 Parent added
CommentTypeAddParent
// 20 Parent removed
CommentTypeRemoveParent
// 21 Comment a line of code // 21 Comment a line of code
CommentTypeCode CommentTypeCode
// 22 Reviews a pull request by giving general feedback // 22 Reviews a pull request by giving general feedback
@ -112,6 +108,10 @@ const (
CommentTypeDismissReview CommentTypeDismissReview
// 33 Change issue ref // 33 Change issue ref
CommentTypeChangeIssueRef CommentTypeChangeIssueRef
// 34 Parent added
CommentTypeAddParent
// 35 Parent removed
CommentTypeRemoveParent
) )
var commentStrings = []string{ var commentStrings = []string{
@ -149,6 +149,8 @@ var commentStrings = []string{
"project_board", "project_board",
"dismiss_review", "dismiss_review",
"change_issue_ref", "change_issue_ref",
"add_parent",
"remove_parent",
} }
func (t CommentType) String() string { func (t CommentType) String() string {
@ -228,6 +230,8 @@ type Comment struct {
NewRef string NewRef string
DependentIssueID int64 DependentIssueID int64
DependentIssue *Issue `xorm:"-"` DependentIssue *Issue `xorm:"-"`
ParentIssueID int64
ParentIssue *Issue `xorm:"-"`
CommitID int64 CommitID int64
Line int64 // - previous line / + proposed line Line int64 // - previous line / + proposed line
@ -623,6 +627,15 @@ func (c *Comment) LoadDepIssueDetails() (err error) {
return err return err
} }
// LoadParentIssueDetails loads Parent Issue Details
func (c *Comment) LoadParentIssueDetails() (err error) {
if c.ParentIssueID <= 0 || c.ParentIssue != nil {
return nil
}
c.ParentIssue, err = getIssueByID(db.GetEngine(db.DefaultContext), c.ParentIssueID)
return err
}
// LoadTime loads the associated time for a CommentTypeAddTimeManual // LoadTime loads the associated time for a CommentTypeAddTimeManual
func (c *Comment) LoadTime() error { func (c *Comment) LoadTime() error {
if c.Time != nil || c.TimeID == 0 { if c.Time != nil || c.TimeID == 0 {
@ -793,6 +806,7 @@ func createComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
OldRef: opts.OldRef, OldRef: opts.OldRef,
NewRef: opts.NewRef, NewRef: opts.NewRef,
DependentIssueID: opts.DependentIssueID, DependentIssueID: opts.DependentIssueID,
ParentIssueID: opts.ParentIssueID,
TreePath: opts.TreePath, TreePath: opts.TreePath,
ReviewID: opts.ReviewID, ReviewID: opts.ReviewID,
Patch: opts.Patch, Patch: opts.Patch,

67
models/issue_comment_list.go

@ -395,6 +395,69 @@ func (comments CommentList) loadDependentIssues(ctx context.Context) error {
return nil return nil
} }
func (comments CommentList) getParentIssueIDs() []int64 {
ids := make(map[int64]struct{}, len(comments))
for _, comment := range comments {
if comment.ParentIssue != nil {
continue
}
if _, ok := ids[comment.ParentIssueID]; !ok {
ids[comment.ParentIssueID] = struct{}{}
}
}
return keysInt64(ids)
}
func (comments CommentList) loadParentIssues(ctx context.Context) error {
if len(comments) == 0 {
return nil
}
e := db.GetEngine(ctx)
issueIDs := comments.getParentIssueIDs()
issues := make(map[int64]*Issue, len(issueIDs))
left := len(issueIDs)
for left > 0 {
limit := defaultMaxInSize
if left < limit {
limit = left
}
rows, err := e.
In("id", issueIDs[:limit]).
Rows(new(Issue))
if err != nil {
return err
}
for rows.Next() {
var issue Issue
err = rows.Scan(&issue)
if err != nil {
_ = rows.Close()
return err
}
issues[issue.ID] = &issue
}
_ = rows.Close()
left -= limit
issueIDs = issueIDs[limit:]
}
for _, comment := range comments {
if comment.ParentIssue == nil {
comment.ParentIssue = issues[comment.ParentIssueID]
if comment.ParentIssue != nil {
if err := comment.ParentIssue.loadRepo(ctx); err != nil {
return err
}
}
}
}
return nil
}
func (comments CommentList) loadAttachments(e db.Engine) (err error) { func (comments CommentList) loadAttachments(e db.Engine) (err error) {
if len(comments) == 0 { if len(comments) == 0 {
return nil return nil
@ -528,6 +591,10 @@ func (comments CommentList) loadAttributes(ctx context.Context) (err error) {
return return
} }
if err = comments.loadParentIssues(ctx); err != nil {
return
}
return nil return nil
} }

10
modules/convert/issue_comment.go

@ -52,6 +52,12 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo
return nil return nil
} }
err = c.LoadParentIssueDetails()
if err != nil {
log.Error("LoadParentIssueDetails: %v", err)
return nil
}
err = c.LoadTime() err = c.LoadTime()
if err != nil { if err != nil {
log.Error("LoadTime: %v", err) log.Error("LoadTime: %v", err)
@ -163,5 +169,9 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo
comment.DependentIssue = ToAPIIssue(c.DependentIssue) comment.DependentIssue = ToAPIIssue(c.DependentIssue)
} }
if c.ParentIssue != nil {
comment.ParentIssue = ToAPIIssue(c.ParentIssue)
}
return comment return comment
} }

2
modules/structs/issue_comment.go

@ -79,4 +79,6 @@ type TimelineComment struct {
ResolveDoer *User `json:"resolve_doer"` ResolveDoer *User `json:"resolve_doer"`
DependentIssue *Issue `json:"dependent_issue"` DependentIssue *Issue `json:"dependent_issue"`
ParentIssue *Issue `json:"parent_issue"`
} }

7
routers/web/repo/issue.go

@ -1473,6 +1473,13 @@ func ViewIssue(ctx *context.Context) {
return return
} }
} }
} else if comment.Type == models.CommentTypeRemoveParent || comment.Type == models.CommentTypeAddParent {
if err = comment.LoadParentIssueDetails(); err != nil {
if !models.IsErrIssueNotExist(err) {
ctx.ServerError("LoadParentIssueDetails", err)
return
}
}
} else if comment.Type == models.CommentTypeCode || comment.Type == models.CommentTypeReview || comment.Type == models.CommentTypeDismissReview { } else if comment.Type == models.CommentTypeCode || comment.Type == models.CommentTypeReview || comment.Type == models.CommentTypeDismissReview {
comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{
URLPrefix: ctx.Repo.RepoLink, URLPrefix: ctx.Repo.RepoLink,

50
templates/repo/issue/view_content/comments.tmpl

@ -831,5 +831,55 @@
{{end}} {{end}}
</span> </span>
</div> </div>
{{else if eq .Type 34}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge">{{svg "octicon-package-parents"}}</span>
<a href="{{.Poster.HomeLink}}">
{{avatar .Poster}}
</a>
<span class="text grey">
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
{{$.i18n.Tr "repo.issues.parent.added_parent" $createdStr | Safe}}
</span>
{{if .ParentIssue}}
<div class="detail">
{{svg "octicon-plus"}}
<span class="text grey">
<a href="{{.ParentIssue.HTMLURL}}">
{{if eq .ParentIssue.RepoID .Issue.RepoID}}
#{{.ParentIssue.Index}} {{.ParentIssue.Title}}
{{else}}
{{.ParentIssue.Repo.FullName}}#{{.ParentIssue.Index}} - {{.ParentIssue.Title}}
{{end}}
</a>
</span>
</div>
{{end}}
</div>
{{else if eq .Type 35}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge">{{svg "octicon-package-parents"}}</span>
<a href="{{.Poster.HomeLink}}">
{{avatar .Poster}}
</a>
<span class="text grey">
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
{{$.i18n.Tr "repo.issues.parent.removed_parent" $createdStr | Safe}}
</span>
{{if .ParentIssue}}
<div class="detail">
<span class="text grey">{{svg "octicon-trash"}}</span>
<span class="text grey">
<a href="{{.ParentIssue.HTMLURL}}">
{{if eq .ParentIssue.RepoID .Issue.RepoID}}
#{{.ParentIssue.Index}} {{.ParentIssue.Title}}
{{else}}
{{.ParentIssue.Repo.FullName}}#{{.ParentIssue.Index}} - {{.ParentIssue.Title}}
{{end}}
</a>
</span>
</div>
{{end}}
</div>
{{end}} {{end}}
{{end}} {{end}}

Loading…
Cancel
Save