From c8c1e704edcfdb83a0a3db39f9ddbf1ff266cbcb Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Thu, 31 May 2018 15:23:15 +0200 Subject: [PATCH] Add 'Reply' as translatable Add CODE_COMMENT_LINES setting Signed-off-by: Jonas Franz --- custom/conf/app.ini.sample | 2 ++ models/issue_comment.go | 17 +++++++++-------- modules/setting/setting.go | 2 ++ options/locale/locale_en-US.ini | 1 + templates/repo/diff/comment_form.tmpl | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index ef88e5c32..fe11a9ee2 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -67,6 +67,8 @@ EXPLORE_PAGING_NUM = 20 ISSUE_PAGING_NUM = 10 ; Number of maximum commits displayed in one activity feed FEED_MAX_COMMIT_NUM = 5 +; Number of line of codes shown for a code comment +CODE_COMMENT_LINES = 4 ; Value of `theme-color` meta tag, used by Android >= 5.0 ; An invalid color like "none" or "disable" will have the default style ; More info: https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android diff --git a/models/issue_comment.go b/models/issue_comment.go index e30964df4..1328543c4 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -396,7 +396,7 @@ func (c *Comment) AsDiff() (*Diff, error) { if len(diff.Files) == 0 { return nil, fmt.Errorf("no file found for comment ID: %d", c.ID) } - // Limit to 4 lines around comment line + // Limit to CODE_COMMENT_LINES lines around comment line for _, sec := range diff.Files[0].Sections { var searchedLineIdx int for lineIdx, line := range sec.Lines { @@ -409,9 +409,9 @@ func (c *Comment) AsDiff() (*Diff, error) { break } } - if searchedLineIdx >= 3 { - first := searchedLineIdx-3 - last := searchedLineIdx+1 + if searchedLineIdx >= setting.UI.CodeCommentLines - 1 { + first := searchedLineIdx - setting.UI.CodeCommentLines + 1 + last := searchedLineIdx + 1 sec.Lines = sec.Lines[first:last] diff.Files[0].Sections = []*DiffSection{sec} break @@ -428,11 +428,12 @@ func (c *Comment) AsDiff() (*Diff, error) { func (c *Comment) MustAsDiff() *Diff { diff, err := c.AsDiff() if err != nil { - log.Warn( "MustAsDiff: %v", err) + log.Warn("MustAsDiff: %v", err) } return diff } +// CodeCommentURL returns the url to a comment in code func (c *Comment) CodeCommentURL() string { err := c.LoadIssue() if err != nil { // Silently dropping errors :unamused: @@ -465,7 +466,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err NewTitle: opts.NewTitle, TreePath: opts.TreePath, ReviewID: opts.ReviewID, - Patch: opts.Patch, + Patch: opts.Patch, } if _, err = e.Insert(comment); err != nil { return nil, err @@ -683,7 +684,7 @@ type CreateCommentOptions struct { NewTitle string CommitID int64 CommitSHA string - Patch string + Patch string LineNum int64 TreePath string ReviewID int64 @@ -786,7 +787,7 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree TreePath: treePath, CommitSHA: commit.ID.String(), ReviewID: reviewID, - Patch: patchBuf.String(), + Patch: patchBuf.String(), }) } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index c8add5fd3..fc21724d2 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -270,6 +270,7 @@ var ( IssuePagingNum int RepoSearchPagingNum int FeedMaxCommitNum int + CodeCommentLines int ReactionMaxUserNum int ThemeColorMetaTag string MaxDisplayFileSize int64 @@ -294,6 +295,7 @@ var ( IssuePagingNum: 10, RepoSearchPagingNum: 10, FeedMaxCommitNum: 5, + CodeCommentLines: 4, ReactionMaxUserNum: 10, ThemeColorMetaTag: `#6cc644`, MaxDisplayFileSize: 8388608, diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index caa211232..1f9c846ab 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1126,6 +1126,7 @@ diff.comment.markdown_info = Styling with markdown is supported. diff.comment.add_single_comment = Add single comment diff.comment.add_review_comment = Add comment diff.comment.start_review = Start review +diff.comment.reply = Reply diff.review = Review diff.review.header = Submit review diff.review.placeholder = Review comment diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index b4edb5545..afb30a368 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -1,6 +1,6 @@ {{if $.root.SignedUserID}} {{if $.hidden}} - + {{end}}
{{$.root.CsrfTokenHtml}}