Skip to content

Comments on pull files #2583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const (
CommentTypeAddTimeManual
// Cancel a stopwatch for time tracking
CommentTypeCancelTracking
// Comment on pull files
CommentTypePullFiles
)

// CommentTag defines comment tag type
Expand Down Expand Up @@ -94,7 +96,8 @@ type Comment struct {
NewTitle string

CommitID int64
Line int64
TreePath string
Line int64 // + is left; - is right
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using +/- we could go with gitea's style and add a type attribute with possible valuesaddition, deletion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want to add an extra column, so I define the line, if it's greater than zero, it should the previous code line before the pull's commits. If it's less than zero, it should the line on this pull's commits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If everyone's happy with this I won't obstruct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, if you use +/-, it should be - for previous line and + for new line.

Content string `xorm:"TEXT"`
RenderedContent string `xorm:"-"`

Expand Down Expand Up @@ -210,6 +213,16 @@ func (c *Comment) EventTag() string {
return "event-" + com.ToStr(c.ID)
}

// LoadPoster loads poster from database
func (c *Comment) LoadPoster() (err error) {
if c.Poster != nil {
return nil
}

c.Poster, err = getUserByID(x, c.PosterID)
return
}

// LoadLabel if comment.Type is CommentTypeLabel, then load Label
func (c *Comment) LoadLabel() error {
var label Label
Expand Down Expand Up @@ -415,6 +428,32 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
return comment, nil
}

// CreatePullFilesComment creates comment on pull files
func CreatePullFilesComment(doer *User, repo *Repository, issue *Issue, lineNum int64, treePath, content string) (*Comment, error) {
sess := x.NewSession()
if err := sess.Begin(); err != nil {
return nil, err
}
comment, err := createPullFilesComment(sess, doer, repo, issue, lineNum, treePath, content)
if err != nil {
return nil, err
}

return comment, sess.Commit()
}

func createPullFilesComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, lineNum int64, treePath, content string) (*Comment, error) {
return createComment(e, &CreateCommentOptions{
Type: CommentTypePullFiles,
Doer: doer,
Repo: repo,
Issue: issue,
Content: content,
TreePath: treePath,
LineNum: lineNum,
})
}

func createStatusComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue) (*Comment, error) {
cmtType := CommentTypeClose
if !issue.IsClosed {
Expand Down Expand Up @@ -502,6 +541,7 @@ type CreateCommentOptions struct {
NewTitle string
CommitID int64
CommitSHA string
TreePath string
LineNum int64
Content string
Attachments []string // UUIDs of attachments
Expand Down
37 changes: 37 additions & 0 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type PullRequest struct {
Merger *User `xorm:"-"`
Merged time.Time `xorm:"-"`
MergedUnix int64 `xorm:"INDEX"`

CodeComments map[string]map[int64][]*Comment `xorm:"-"`
}

// BeforeUpdate is invoked from XORM before updating an object of this type.
Expand Down Expand Up @@ -127,6 +129,41 @@ func (pr *PullRequest) loadIssue(e Engine) (err error) {
return err
}

// LoadCodeComments loads pull request code comments from database
func (pr *PullRequest) LoadCodeComments() error {
return pr.loadCodeComments(x)
}

func (pr *PullRequest) loadCodeComments(e Engine) error {
if err := pr.loadIssue(e); err != nil {
return err
}

if pr.CodeComments != nil {
return nil
}

pr.CodeComments = make(map[string]map[int64][]*Comment)

return e.Where("issue_id = ?", pr.Issue.ID).
And("type = ?", CommentTypePullFiles).
Iterate(new(Comment), func(i int, bean interface{}) error {
comment := bean.(*Comment)
if err := comment.LoadPoster(); err != nil {
return err
}

if _, ok := pr.CodeComments[comment.TreePath]; !ok {
pr.CodeComments[comment.TreePath] = make(map[int64][]*Comment)
}
if _, ok := pr.CodeComments[comment.TreePath][comment.Line]; !ok {
pr.CodeComments[comment.TreePath][comment.Line] = make([]*Comment, 0)
}
pr.CodeComments[comment.TreePath][comment.Line] = append(pr.CodeComments[comment.TreePath][comment.Line], comment)
return nil
})
}

// APIFormat assumes following fields have been assigned with valid values:
// Required - Issue
// Optional - Merger
Expand Down
6 changes: 6 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) {
}
}

// GetEmail returns an noreply email, if the user has set to keep his
// email address private, otherwise the primary email address.
func (u *User) GetEmail() string {
return u.getEmail()
}

// getEmail returns an noreply email, if the user has set to keep his
// email address private, otherwise the primary email address.
func (u *User) getEmail() string {
Expand Down
88 changes: 88 additions & 0 deletions public/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.ui.blue.button.code-comment {
font-size: 14px;
height: 100%;
left: 0;
padding: 0;
padding-top: 2px;
position: absolute;
top: 0;
width: 100%;
display: none;
}

.code-comment-section .single-comment .content {
padding: 10px 5px;
}

.repository .diff-file-box .code-diff .code-comment-section td {
padding: 15px 12px;
padding-top: 5px;
border: 1px solid #dddddd;
}

.repository .diff-file-box .file-body.file-code .lines-num-old {
position: relative;
}

.repository .diff-file-box .code-diff td .comment-code-cloud:before {
content: " ";
width: 0;
height: 0;
border-left: 13px solid transparent;
border-right: 13px solid transparent;
border-bottom: 13px solid #f1f1f1;
left: 49px;
position: absolute;
top: -13px;
}

.repository .diff-file-box .code-diff td .comment-code-cloud {
width: 75%;
padding: 14px 20px;
margin: 0 auto;
position: relative;
border: 1px solid #f1f1f1;
margin-top: 13px;
}

.repository .diff-file-box .code-diff td .comment-code-cloud .attached.tab {
border: none;
padding: 0;
margin: 0;
}

.repository .diff-file-box .code-diff td .comment-code-cloud .right.menu .item {
padding: 0.85714286em 0.442857em;
}

.repository .diff-file-box .code-diff .comment-code-cloud textarea {
border: 0px;
}

.comment-code-cloud .ui.attached.tabular.menu {
background: #f7f7f7;
border: 1px solid #d4d4d5;
padding-top: 5px;
padding-left: 5px;
}

.comment-code-cloud .ui.top.attached .item {
cursor: pointer;
}

.comment-code-cloud .markdown-info {
display: inline-block;
margin: 5px 0;
font-size: 12px;
}

.comment-code-cloud .preview-msg {
min-height: 168px;
}

.comment-code-cloud .footer {
padding-top: 12px;
border-top: 1px solid #f1f1f1;
margin-top: 10px;
}

Loading