From 2dac9bab74f9dd1710a85c04055bdd4e0e05246d Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Thu, 25 May 2023 20:41:55 +0200 Subject: [PATCH 01/25] Add octicon-alert-fill svg --- web_src/js/svg.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web_src/js/svg.js b/web_src/js/svg.js index 49376c16434a8..14fe1f2591c9f 100644 --- a/web_src/js/svg.js +++ b/web_src/js/svg.js @@ -3,6 +3,7 @@ import giteaDoubleChevronLeft from '../../public/img/svg/gitea-double-chevron-le import giteaDoubleChevronRight from '../../public/img/svg/gitea-double-chevron-right.svg'; import giteaEmptyCheckbox from '../../public/img/svg/gitea-empty-checkbox.svg'; import giteaExclamation from '../../public/img/svg/gitea-exclamation.svg'; +import octiconAlertFill from '../../public/img/svg/octicon-alert-fill.svg'; import octiconArchive from '../../public/img/svg/octicon-archive.svg'; import octiconArrowSwitch from '../../public/img/svg/octicon-arrow-switch.svg'; import octiconBlocked from '../../public/img/svg/octicon-blocked.svg'; @@ -71,6 +72,7 @@ const svgs = { 'gitea-double-chevron-right': giteaDoubleChevronRight, 'gitea-empty-checkbox': giteaEmptyCheckbox, 'gitea-exclamation': giteaExclamation, + 'octicon-alert-fill': octiconAlertFill, 'octicon-archive': octiconArchive, 'octicon-arrow-switch': octiconArrowSwitch, 'octicon-blocked': octiconBlocked, From f7be42ec7907d066abd6d2c5e9c7fc5c8ff67cc2 Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Thu, 25 May 2023 20:51:39 +0200 Subject: [PATCH 02/25] Show outdated comments in files changed view --- models/issues/comment_code.go | 5 ---- options/locale/locale_en-US.ini | 2 ++ templates/repo/diff/conversation.tmpl | 34 +++++++++++++++++++++------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go index 304ac4569f86e..5a551ea67cf4e 100644 --- a/models/issues/comment_code.go +++ b/models/issues/comment_code.go @@ -10,8 +10,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" - - "xorm.io/builder" ) // CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS @@ -53,9 +51,6 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu review = &Review{ID: 0} } conds := opts.ToConds() - if review.ID == 0 { - conds = conds.And(builder.Eq{"invalidated": false}) - } e := db.GetEngine(ctx) if err := e.Where(conds). Asc("comment.created_unix"). diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 1026a13e3338a..a3de572635f7b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1604,6 +1604,8 @@ issues.review.show_outdated = Show outdated issues.review.hide_outdated = Hide outdated issues.review.show_resolved = Show resolved issues.review.hide_resolved = Hide resolved +issues.review.comment_points_to_modified_line = Points to a modified code fragment. +issues.review.show_original_comment = Show original issues.review.resolve_conversation = Resolve conversation issues.review.un_resolve_conversation = Unresolve conversation issues.review.resolved_by = marked this conversation as resolved diff --git a/templates/repo/diff/conversation.tmpl b/templates/repo/diff/conversation.tmpl index 8d4064967e178..c5835202f22f2 100644 --- a/templates/repo/diff/conversation.tmpl +++ b/templates/repo/diff/conversation.tmpl @@ -1,21 +1,41 @@ {{$resolved := (index .comments 0).IsResolved}} +{{$invalid := (index .comments 0).Invalidated}} {{$resolveDoer := (index .comments 0).ResolveDoer}} {{$isNotPending := (not (eq (index .comments 0).Review.Type 0))}} +{{$referenceUrl := printf "%s#%s" $.Issue.Link (index .comments 0).HashTag}}
- {{if $resolved}} + {{if or $invalid $resolved}}
- {{svg "octicon-check" 16 "icon gt-mr-2"}} - {{$resolveDoer.Name}} {{$.locale.Tr "repo.issues.review.resolved_by"}} + {{if $resolved}} + {{svg "octicon-check" 16 "icon gt-mr-2"}} + {{$resolveDoer.Name}} {{$.locale.Tr "repo.issues.review.resolved_by"}} + {{end}} + {{if $invalid}} + {{if $resolved}} + | + {{else}} + {{svg "octicon-alert-fill" 16 "icon gt-mr-2"}} + {{end}} + {{$.locale.Tr "repo.issues.review.comment_points_to_modified_line"}} {{$.locale.Tr "repo.issues.review.show_original_comment"}} + {{end}}
- -
From 86fb8bf14e5428990b955f79305eff6e67bd2015 Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Thu, 25 May 2023 21:59:10 +0200 Subject: [PATCH 03/25] Fix unit tests --- services/gitdiff/gitdiff_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index 389f787dfc442..cb07add8f8ff0 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -601,7 +601,7 @@ func TestDiff_LoadComments(t *testing.T) { user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) diff := setupDefaultDiff() assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user)) - assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2) + assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 3) } func TestDiffLine_CanComment(t *testing.T) { From a3489228989f76910a9956cff2374442e50751a2 Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Sat, 27 May 2023 13:03:12 +0200 Subject: [PATCH 04/25] Use outdated label and address review comments --- options/locale/locale_en-US.ini | 2 +- templates/repo/diff/conversation.tmpl | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a3de572635f7b..09579f26b15c0 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1600,11 +1600,11 @@ issues.review.pending.tooltip = This comment is not currently visible to other u issues.review.review = Review issues.review.reviewers = Reviewers issues.review.outdated = Outdated +issues.review.outdated.tooltip = The code this comment refers to has changed since the comment was made issues.review.show_outdated = Show outdated issues.review.hide_outdated = Hide outdated issues.review.show_resolved = Show resolved issues.review.hide_resolved = Hide resolved -issues.review.comment_points_to_modified_line = Points to a modified code fragment. issues.review.show_original_comment = Show original issues.review.resolve_conversation = Resolve conversation issues.review.un_resolve_conversation = Unresolve conversation diff --git a/templates/repo/diff/conversation.tmpl b/templates/repo/diff/conversation.tmpl index c5835202f22f2..219fe49181fd3 100644 --- a/templates/repo/diff/conversation.tmpl +++ b/templates/repo/diff/conversation.tmpl @@ -6,22 +6,20 @@
{{if or $invalid $resolved}}
-
+
{{if $resolved}} {{svg "octicon-check" 16 "icon gt-mr-2"}} {{$resolveDoer.Name}} {{$.locale.Tr "repo.issues.review.resolved_by"}} {{end}} {{if $invalid}} - {{if $resolved}} - | - {{else}} + {{if not $resolved}} {{svg "octicon-alert-fill" 16 "icon gt-mr-2"}} {{end}} - {{$.locale.Tr "repo.issues.review.comment_points_to_modified_line"}} {{$.locale.Tr "repo.issues.review.show_original_comment"}} +
{{$.locale.Tr "repo.issues.review.outdated"}}
{{$.locale.Tr "repo.issues.review.show_original_comment"}} {{end}}
- -
From a8babc57987b3748804e6fadc0c479b2a1585e9e Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 27 May 2023 21:43:18 +0200 Subject: [PATCH 06/25] various tweaks --- options/locale/locale_en-US.ini | 4 ++-- templates/repo/diff/conversation.tmpl | 11 ++++++++--- templates/repo/issue/view_content/comments.tmpl | 2 +- web_src/css/repo.css | 4 ++++ web_src/css/review.css | 3 ++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0e7a62f1132ea..421e3af26cc80 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1600,7 +1600,7 @@ issues.review.pending.tooltip = This comment is not currently visible to other u issues.review.review = Review issues.review.reviewers = Reviewers issues.review.outdated = Outdated -issues.review.outdated.tooltip = The code this comment refers to has changed since the comment was made +issues.review.outdated.tooltip = The code has changed since this comment was made issues.review.show_outdated = Show outdated issues.review.hide_outdated = Hide outdated issues.review.show_resolved = Show resolved @@ -1608,7 +1608,7 @@ issues.review.hide_resolved = Hide resolved issues.review.show_original_comment = Show original issues.review.resolve_conversation = Resolve conversation issues.review.un_resolve_conversation = Unresolve conversation -issues.review.resolved_by = marked this conversation as resolved. +issues.review.resolved_by = marked this conversation as resolved issues.assignee.error = Not all assignees was added due to an unexpected error. issues.reference_issue.body = Body issues.content_history.deleted = deleted diff --git a/templates/repo/diff/conversation.tmpl b/templates/repo/diff/conversation.tmpl index 1c8971c879787..be320d3d74092 100644 --- a/templates/repo/diff/conversation.tmpl +++ b/templates/repo/diff/conversation.tmpl @@ -15,11 +15,16 @@ {{if not $resolved}} {{svg "octicon-alert-fill" 16 "icon gt-mr-2"}} {{end}} - {{$.locale.Tr "repo.issues.review.show_original_comment"}} -
{{$.locale.Tr "repo.issues.review.outdated"}}
+
{{$.locale.Tr "repo.issues.review.outdated"}}
{{end}}
-
+
+ {{if $invalid}} + + {{svg "octicon-comment" 16 "gt-mr-3"}} + {{$.locale.Tr "repo.issues.review.show_original_comment"}} + + {{end}} -
From feebb5eb93d02981c8d9bc4fab6517cbcd1d40da Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Wed, 31 May 2023 21:35:44 +0200 Subject: [PATCH 19/25] Add user setting / option to show outdated comments in PR --- models/issues/comment_code.go | 21 ++++++++++++------- models/issues/comment_test.go | 4 ++-- models/issues/review.go | 2 +- models/user/setting_keys.go | 2 ++ options/locale/locale_en-US.ini | 2 ++ routers/web/repo/middlewares.go | 25 +++++++++++++++++++++++ routers/web/repo/pull.go | 2 +- routers/web/repo/pull_review.go | 2 +- routers/web/web.go | 6 +++--- services/gitdiff/gitdiff.go | 4 ++-- services/gitdiff/gitdiff_test.go | 14 +++++++++++-- templates/repo/diff/options_dropdown.tmpl | 15 ++++++++++++++ 12 files changed, 80 insertions(+), 19 deletions(-) diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go index 5a551ea67cf4e..1438abc392088 100644 --- a/models/issues/comment_code.go +++ b/models/issues/comment_code.go @@ -10,17 +10,19 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" + + "xorm.io/builder" ) // CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS type CodeComments map[string]map[int64][]*Comment // FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line -func FetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User) (CodeComments, error) { - return fetchCodeCommentsByReview(ctx, issue, currentUser, nil) +func FetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User, showOutdatedComments bool) (CodeComments, error) { + return fetchCodeCommentsByReview(ctx, issue, currentUser, nil, showOutdatedComments) } -func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *user_model.User, review *Review) (CodeComments, error) { +func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *user_model.User, review *Review, showOutdatedComments bool) (CodeComments, error) { pathToLineToComment := make(CodeComments) if review == nil { review = &Review{ID: 0} @@ -31,7 +33,7 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u ReviewID: review.ID, } - comments, err := findCodeComments(ctx, opts, issue, currentUser, review) + comments, err := findCodeComments(ctx, opts, issue, currentUser, review, showOutdatedComments) if err != nil { return nil, err } @@ -45,12 +47,17 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u return pathToLineToComment, nil } -func findCodeComments(ctx context.Context, 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, showOutdatedComments bool) ([]*Comment, error) { var comments CommentList if review == nil { review = &Review{ID: 0} } conds := opts.ToConds() + + if !showOutdatedComments { + conds = conds.And(builder.Eq{"invalidated": false}) + } + e := db.GetEngine(ctx) if err := e.Where(conds). Asc("comment.created_unix"). @@ -113,12 +120,12 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu } // FetchCodeCommentsByLine fetches the code comments for a given treePath and line number -func FetchCodeCommentsByLine(ctx context.Context, issue *Issue, currentUser *user_model.User, treePath string, line int64) ([]*Comment, error) { +func FetchCodeCommentsByLine(ctx context.Context, issue *Issue, currentUser *user_model.User, treePath string, line int64, showOutdatedComments bool) ([]*Comment, error) { opts := FindCommentsOptions{ Type: CommentTypeCode, IssueID: issue.ID, TreePath: treePath, Line: line, } - return findCodeComments(ctx, opts, issue, currentUser, nil) + return findCodeComments(ctx, opts, issue, currentUser, nil, showOutdatedComments) } diff --git a/models/issues/comment_test.go b/models/issues/comment_test.go index 43bad1660f1f5..d766625be3dc8 100644 --- a/models/issues/comment_test.go +++ b/models/issues/comment_test.go @@ -50,7 +50,7 @@ func TestFetchCodeComments(t *testing.T) { issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) - res, err := issues_model.FetchCodeComments(db.DefaultContext, issue, user) + res, err := issues_model.FetchCodeComments(db.DefaultContext, issue, user, false) assert.NoError(t, err) assert.Contains(t, res, "README.md") assert.Contains(t, res["README.md"], int64(4)) @@ -58,7 +58,7 @@ func TestFetchCodeComments(t *testing.T) { assert.Equal(t, int64(4), res["README.md"][4][0].ID) user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - res, err = issues_model.FetchCodeComments(db.DefaultContext, issue, user2) + res, err = issues_model.FetchCodeComments(db.DefaultContext, issue, user2, false) assert.NoError(t, err) assert.Len(t, res, 1) } diff --git a/models/issues/review.go b/models/issues/review.go index 06cf132a48a3a..85f3e738380d6 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -141,7 +141,7 @@ func (r *Review) LoadCodeComments(ctx context.Context) (err error) { if err = r.loadIssue(ctx); err != nil { return } - r.CodeComments, err = fetchCodeCommentsByReview(ctx, r.Issue, nil, r) + r.CodeComments, err = fetchCodeCommentsByReview(ctx, r.Issue, nil, r, false) return err } diff --git a/models/user/setting_keys.go b/models/user/setting_keys.go index 10255735b3177..72b3974eee435 100644 --- a/models/user/setting_keys.go +++ b/models/user/setting_keys.go @@ -8,6 +8,8 @@ const ( SettingsKeyHiddenCommentTypes = "issue.hidden_comment_types" // SettingsKeyDiffWhitespaceBehavior is the setting key for whitespace behavior of diff SettingsKeyDiffWhitespaceBehavior = "diff.whitespace_behaviour" + // SettingsKeyShowOutdatedComments is the setting key wether or not to show outdated comments in PRs + SettingsKeyShowOutdatedComments = "comment_code.show_outdated" // UserActivityPubPrivPem is user's private key UserActivityPubPrivPem = "activitypub.priv_pem" // UserActivityPubPubPem is user's public key diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4c952e78ad140..9aeb5fd464e39 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1599,6 +1599,8 @@ issues.review.review = Review issues.review.reviewers = Reviewers issues.review.outdated = Outdated issues.review.outdated_description = Content has changed since this comment was made +issues.review.option.show_outdated_comments = Show outdated comments +issues.review.option.hide_outdated_comments = Hide outdated comments issues.review.show_outdated = Show outdated issues.review.hide_outdated = Hide outdated issues.review.show_resolved = Show resolved diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go index 5c38b31154fe3..216550ca996c6 100644 --- a/routers/web/repo/middlewares.go +++ b/routers/web/repo/middlewares.go @@ -5,6 +5,7 @@ package repo import ( "fmt" + "strconv" system_model "code.gitea.io/gitea/models/system" user_model "code.gitea.io/gitea/models/user" @@ -88,3 +89,27 @@ func SetWhitespaceBehavior(ctx *context.Context) { ctx.Data["WhitespaceBehavior"] = whitespaceBehavior } } + +// SetShowOutdatedComments set the show outdated comments option as context variable +func SetShowOutdatedComments(ctx *context.Context) { + showOutdatedCommentsValue := ctx.FormString("show-outdated") + // var showOutdatedCommentsValue string + + if showOutdatedCommentsValue != "true" && showOutdatedCommentsValue != "false" { + // invalid or no value for this form string -> use default or stored user setting + if ctx.IsSigned { + showOutdatedCommentsValue, _ = user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, "false") + } else { + // not logged in user -> use the default value + showOutdatedCommentsValue = "false" + } + } else { + // valid value -> update user setting if user is logged in + if ctx.IsSigned { + _ = user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyShowOutdatedComments, showOutdatedCommentsValue) + } + } + + showOutdatedComments, _ := strconv.ParseBool(showOutdatedCommentsValue) + ctx.Data["ShowOutdatedComments"] = showOutdatedComments +} diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 09dbc23eac2cc..0127edb5a6eff 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -762,7 +762,7 @@ func ViewPullFiles(ctx *context.Context) { "numberOfViewedFiles": diff.NumViewedFiles, } - if err = diff.LoadComments(ctx, issue, ctx.Doer); err != nil { + if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil { ctx.ServerError("LoadComments", err) return } diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go index 90cfd5bfcdb3a..0ff0d7b739641 100644 --- a/routers/web/repo/pull_review.go +++ b/routers/web/repo/pull_review.go @@ -159,7 +159,7 @@ func UpdateResolveConversation(ctx *context.Context) { } func renderConversation(ctx *context.Context, comment *issues_model.Comment) { - comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line) + comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, ctx.Data["ShowOutdatedComments"].(bool)) if err != nil { ctx.ServerError("FetchCodeCommentsByLine", err) return diff --git a/routers/web/web.go b/routers/web/web.go index da6064257bd20..d6ac08077441d 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1023,7 +1023,7 @@ func registerRoutes(m *web.Route) { m.Post("/request_review", reqRepoIssuesOrPullsReader, repo.UpdatePullReviewRequest) m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview) m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus) - m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.UpdateResolveConversation) + m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.SetShowOutdatedComments, repo.UpdateResolveConversation) m.Post("/attachments", repo.UploadIssueAttachment) m.Post("/attachments/remove", repo.DeleteAttachment) m.Delete("/unpin/{index}", reqRepoAdmin, repo.IssueUnpin) @@ -1271,10 +1271,10 @@ func registerRoutes(m *web.Route) { m.Post("/set_allow_maintainer_edit", web.Bind(forms.UpdateAllowEditsForm{}), repo.SetAllowEdits) m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest) m.Group("/files", func() { - m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.ViewPullFiles) + m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFiles) m.Group("/reviews", func() { m.Get("/new_comment", repo.RenderNewCodeCommentForm) - m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.CreateCodeComment) + m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.SetShowOutdatedComments, repo.CreateCodeComment) m.Post("/submit", web.Bind(forms.SubmitReviewForm{}), repo.SubmitReview) }, context.RepoMustNotBeArchived()) }) diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index b6a75f60982f2..9adf3b940093e 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -450,8 +450,8 @@ type Diff struct { } // LoadComments loads comments into each line -func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User) error { - allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser) +func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error { + allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments) if err != nil { return err } diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index cb07add8f8ff0..e270e46fd453f 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -594,13 +594,23 @@ func setupDefaultDiff() *Diff { } } -func TestDiff_LoadComments(t *testing.T) { +func TestDiff_LoadCommentsNoOutdated(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) diff := setupDefaultDiff() - assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user)) + assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user, false)) + assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2) +} + +func TestDiff_LoadCommentsWithOutdated(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + diff := setupDefaultDiff() + assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user, true)) assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 3) } diff --git a/templates/repo/diff/options_dropdown.tmpl b/templates/repo/diff/options_dropdown.tmpl index ced0e060467e1..1b6aff9d689e3 100644 --- a/templates/repo/diff/options_dropdown.tmpl +++ b/templates/repo/diff/options_dropdown.tmpl @@ -14,5 +14,20 @@ {{end}} {{.locale.Tr "repo.pulls.expand_files"}} {{.locale.Tr "repo.pulls.collapse_files"}} + {{if .Issue.Index}} + {{if .ShowOutdatedComments}} + + + {{else}} + + + {{end}} + {{end}}
From 7582ac9cb14b4f08eba0173858047652622e52e5 Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Wed, 31 May 2023 22:18:24 +0200 Subject: [PATCH 20/25] Fix integration tests --- models/issues/comment_code.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go index 1438abc392088..d447d7542cd26 100644 --- a/models/issues/comment_code.go +++ b/models/issues/comment_code.go @@ -54,7 +54,7 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu } conds := opts.ToConds() - if !showOutdatedComments { + if !showOutdatedComments && review.ID == 0 { conds = conds.And(builder.Eq{"invalidated": false}) } From 8aec1475a95522a195e539e6d882e54cec82ebfa Mon Sep 17 00:00:00 2001 From: sebastian-sauer Date: Tue, 20 Jun 2023 15:50:17 +0000 Subject: [PATCH 21/25] Fix format of web.go --- routers/web/web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/web.go b/routers/web/web.go index c2a0f12f00c82..348b468a0c3a0 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1025,7 +1025,7 @@ func registerRoutes(m *web.Route) { m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview) m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus) m.Post("/delete", reqRepoAdmin, repo.BatchDeleteIssues) - m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.SetShowOutdatedComments, repo.UpdateResolveConversation) + m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.SetShowOutdatedComments, repo.UpdateResolveConversation) m.Post("/attachments", repo.UploadIssueAttachment) m.Post("/attachments/remove", repo.DeleteAttachment) m.Delete("/unpin/{index}", reqRepoAdmin, repo.IssueUnpin) From d77ab8af2cf2f3ab05bf548d9efbc938e175d9de Mon Sep 17 00:00:00 2001 From: sebastian-sauer Date: Tue, 20 Jun 2023 16:01:30 +0000 Subject: [PATCH 22/25] Add comments for conversation.tmpl and fix small html markup bug --- templates/repo/diff/conversation.tmpl | 4 ++++ templates/repo/diff/options_dropdown.tmpl | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/templates/repo/diff/conversation.tmpl b/templates/repo/diff/conversation.tmpl index 2256c38b0160b..36162fd1021c5 100644 --- a/templates/repo/diff/conversation.tmpl +++ b/templates/repo/diff/conversation.tmpl @@ -10,6 +10,10 @@ {{svg "octicon-check" 16 "icon gt-mr-2"}} {{$resolveDoer.Name}} {{$.locale.Tr "repo.issues.review.resolved_by"}} {{if $invalid}} + {{$.locale.Tr "repo.issues.review.outdated"}} diff --git a/templates/repo/diff/options_dropdown.tmpl b/templates/repo/diff/options_dropdown.tmpl index 1b6aff9d689e3..6a866fa2654a1 100644 --- a/templates/repo/diff/options_dropdown.tmpl +++ b/templates/repo/diff/options_dropdown.tmpl @@ -19,13 +19,13 @@ {{else}} {{end}} {{end}} From 593e07510b58188587eaa879f077cdb475e5ebbc Mon Sep 17 00:00:00 2001 From: sebastian-sauer Date: Tue, 20 Jun 2023 16:15:59 +0000 Subject: [PATCH 23/25] Fix indentation in conversation.tmpl --- templates/repo/diff/conversation.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/diff/conversation.tmpl b/templates/repo/diff/conversation.tmpl index 36162fd1021c5..ce344794ea782 100644 --- a/templates/repo/diff/conversation.tmpl +++ b/templates/repo/diff/conversation.tmpl @@ -10,7 +10,7 @@ {{svg "octicon-check" 16 "icon gt-mr-2"}} {{$resolveDoer.Name}} {{$.locale.Tr "repo.issues.review.resolved_by"}} {{if $invalid}} - From fbbb87acd6f7dcbf8f9acb8bb204ec3675fd63d8 Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Tue, 20 Jun 2023 19:51:59 +0200 Subject: [PATCH 24/25] Always add all query params to url --- templates/repo/diff/options_dropdown.tmpl | 4 ++-- templates/repo/diff/whitespace_dropdown.tmpl | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/repo/diff/options_dropdown.tmpl b/templates/repo/diff/options_dropdown.tmpl index 6a866fa2654a1..26159e481e0e7 100644 --- a/templates/repo/diff/options_dropdown.tmpl +++ b/templates/repo/diff/options_dropdown.tmpl @@ -16,13 +16,13 @@ {{.locale.Tr "repo.pulls.collapse_files"}} {{if .Issue.Index}} {{if .ShowOutdatedComments}} - + {{else}} - + diff --git a/templates/repo/diff/whitespace_dropdown.tmpl b/templates/repo/diff/whitespace_dropdown.tmpl index 2b27a56c047fc..0572dbb707163 100644 --- a/templates/repo/diff/whitespace_dropdown.tmpl +++ b/templates/repo/diff/whitespace_dropdown.tmpl @@ -2,25 +2,25 @@ {{svg "gitea-whitespace"}} {{svg "octicon-triangle-down" 14 "dropdown icon"}}
-{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}} +{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}} From 9557893ab9b3d3e068e39b6c9caa5197202afe87 Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Tue, 20 Jun 2023 23:32:56 +0200 Subject: [PATCH 25/25] Make all query params have same order --- templates/repo/diff/whitespace_dropdown.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/repo/diff/whitespace_dropdown.tmpl b/templates/repo/diff/whitespace_dropdown.tmpl index 0572dbb707163..1c7b9f3c8d36b 100644 --- a/templates/repo/diff/whitespace_dropdown.tmpl +++ b/templates/repo/diff/whitespace_dropdown.tmpl @@ -2,25 +2,25 @@ {{svg "gitea-whitespace"}} {{svg "octicon-triangle-down" 14 "dropdown icon"}}