Skip to content

Change request: fix diff comments#152

Merged
taoeffect merged 134 commits intomasterfrom
change-request-fix-diff-comments
Mar 3, 2026
Merged

Change request: fix diff comments#152
taoeffect merged 134 commits intomasterfrom
change-request-fix-diff-comments

Conversation

@pedrogaudencio
Copy link
Collaborator

@pedrogaudencio pedrogaudencio commented Feb 25, 2026

Fixes /issues/151
Closes /issues/91

Notes: depends on /pull/147


Open with Devin

* set fork-related context data
* show submit button based on permissions
* add ForkAndEdit field to EditRepoFileForm
* modify EditFilePost to handle fork creation and commit to fork
* reuse existing fork if user already has one
* query repos by owner and subject
* check for existing user repo for subject
* disable edit/fork buttons when user already has a repo for the subject
* show message in edit view explaining why editing is disabled
* fix wrong error condition (returned on any error, not just 'not found')
* fix double increment bug (i++ in loop body + loop increment)
* optimise from O(n) queries to single query with hash set lookup O(1)
* add proper error logging
* run subject ownership check and fork detection concurrently
* add error for subject ownership violations
* validate subject ownership before forking
* fix POST handler to validate subject ownership
* create IDX_repository_owner_subject and IDX_repository_owner_fork
* optimizes GetRepositoryByOwnerIDAndSubjectID() and GetForkedRepo() queries
* replace 'Cannot Edit' button with 'Edit Your Article' action link
* add translation keys for fork-on-edit error messages
* link users to their existing article when subject ownership blocks editing
* simplify fork_and_edit hidden field to only use .NeedsFork
* extract repeated nil-guard pattern into $subjectName template variable
* add Playwright tests for modal appearance, cancel actions, and tooltip
* test modal shows correct header, content, and button text
* verify cancel button and Escape key close modal without action
* verify fork button has tooltip with confirmation message
* add repository owner tests for Submit Changes button behavior
* add non-owner tests for Fork button and disabled submit button
* add unauthenticated user test for sign-in button
* accessibility tests verify Enter opens modal, Tab navigates buttons, and buttons have proper accessible text content
* unique name tests verify suffix generation when base name is taken
* use RepoOperationsLink instead of RepoLink in form action url
* bypass fork_and_edit in CanWriteToBranch middleware to allow non-owners to reach the EditFilePost handler
* skip NeedFork workflow when ForkAndEdit is true to prevent conflicting fork creation attempts
* CheckForkOnEditPermissions for owner/non-owner/unauthenticated
* CanWriteToBranch middleware bypass with fork_and_edit=true
* existing fork detection using fixture data (repo11/repo10)
* subject ownership blocking prevents duplicate forks
* form action URL uses RepoOperationsLink not RepoLink
* slug generation migration covering basic slugs, mixed-case deduplication, special characters, unique constraint verification, and empty table handling
* index creation, idempotency, and index type verification
…order

* fork API behavior when user already owns a repository for the same subject
* fork blocked by subject ownership (403), fork succeeds for user without subject repo (202), fork blocked even with custom name (403)
* fix error handling order in CreateFork
* update GetForkedRepo signature to return (*Repository, error)
* update all callers to handle the new error return value
* fixes silent error swallowing
* fix modal promise resolution pattern
* add PathEscapeSegments to article template URL
* update test comment to list all removed special characters
@pedrogaudencio
Copy link
Collaborator Author

pedrogaudencio commented Feb 26, 2026

/crush_fast


AI review started.

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Advanced AI Review

  • Type: Agentic (crush)
  • Model: glm-5
Click to expand review

Review Summary

The changes look correct and implement defensive programming improvements. I found no bugs or security issues in the modified code. The changes are:

  1. Type assertion safety fixes - Using the comma-ok idiom to prevent potential panics
  2. UX improvement - Always showing the review button (with disabled state and counter) when on PR files page

1. 🔵 Type Assertion Fix in pull.go

  • Addressed
  • Dismissed

Location: routers/web/repo/pull.go:791

showOutdatedComments, _ := ctx.Data["ShowOutdatedComments"].(bool)

This is a good defensive fix. The middleware SetShowOutdatedComments is always applied before this handler, so the type assertion should always succeed. However, using the comma-ok idiom is still safer and prevents potential panics if there's ever a bug in routing.


2. 🔵 Type Assertion Fix in pull_review.go

  • Addressed
  • Dismissed

Location: routers/web/repo/pull_review.go:172-173

showOutdatedComments, _ := ctx.Data["ShowOutdatedComments"].(bool)
showOutdatedComments = origin == "timeline" || showOutdatedComments

This is semantically equivalent to the original code but safer. The fallback to false when the value isn't set is a safe default (don't show outdated comments if uncertain).


3. 🔵 Template Change in box.tmpl

  • Addressed
  • Dismissed

Location: templates/repo/diff/box.tmpl:41

{{if and .PageIsPullFiles (not $.Repository.IsArchived)}}
    {{template "repo/diff/review_submit" .}}
{{end}}

This removes the IsShowingAllCommits condition, so the review button is now always rendered when viewing PR files (if repo isn't archived). The review_submit template internally handles the logic:

  • review_submit.tmpl:2-4 - Button is disabled when not showing all commits
  • review_submit.tmpl:10 - Modal is only rendered when showing all commits

This is a reasonable UX improvement: users can always see their pending comment count and understand that they need to view the full diff to submit.


Note: Pre-existing Pattern Outside PR Scope

  • Addressed
  • Dismissed

Location: routers/web/repo/issue_view.go:535

if !ctx.Data["IsStopwatchRunning"].(bool) {

This is a similar unsafe type assertion pattern, though in this case the value is set on the immediately preceding line (534), so it's guaranteed to exist. This is outside the scope of this PR but could benefit from the same defensive pattern for consistency.


Conclusion

No issues found that require fixes. The changes are well-implemented defensive programming improvements that fix the referenced issues without introducing bugs or security vulnerabilities.


Review generated using glm-5 via Z.AI. Comment /review to re-run.

@pedrogaudencio
Copy link
Collaborator Author

pedrogaudencio commented Feb 27, 2026

  1. Type Assertion Fix in pull.go: comma-ok idiom applied - safe fallback to false if middleware doesn't set the value
  2. Type Assertion Fix in pull_review.go: comma-ok idiom applied - semantically equivalent but prevents potential panics
  3. Template Change in box.tmpl: UX improvement to always show review button - review_submit template already handles disabled state internally
  4. Pre-existing Pattern Outside PR Scope: value is set on the immediately preceding line

pedrogaudencio and others added 12 commits February 27, 2026 09:00
…th check

- Make navbar-pill-active conditional on PageIsPullList so it's only
  highlighted on PR-related pages (fixes always-active pill bug)
- Add $.SignedUserID check to review submit button condition to prevent
  showing it to unauthenticated users
- Fix split/unified view toggle (replace broken JS onclick with server-side
  rendered <a> tag)
- Add mobile default to unified view
- Add CSS overrides for conversation-holder comments and PR diff styling
Remove .IsShowingAllCommits from the outer condition in box.tmpl since
review_submit.tmpl already handles the disabled state internally when
not showing all commits. This matches the master behavior where the
review button is always rendered for signed-in users on PR file pages.

Fixes TestPullDiff_SingleCommitPRDiff and TestPullDiff_CommitRangePRDiff
which expect .js-btn-review to exist with a disabled class.
The JavaScript in article-editor.ts reads data-fork-confirm-body2 to
display a second paragraph in the fork confirmation modal, but the
template was missing this attribute. The locale key already exists.

Fixes AI Review Issue #1.
The backend SubmitReviewForm struct has no Title field, so the title
input was silently discarded. This removes it to avoid misleading users.

Fixes AI Review Issue #2.
Remove large blocks of commented-out CSS for .issue-content-* classes
and .labels-list, plus the orphaned media query that referenced deleted
classes. Git history preserves these styles if needed.

Fixes AI Review Issues #3 and #9.
Move inline onclick handlers to addEventListener calls for CSP
compatibility. Affects the diff info banner dismiss button in box.tmpl
and the PR back link in view_title.tmpl.

Fixes AI Review Issue #4.
The review modal could only be closed by clicking the X button or the
overlay. Add a keydown listener so pressing Escape also closes it.

Fixes AI Review Issue #5.
Replace 'Post immediately', 'Save draft', and 'Click a paragraph to
add a comment.' with ctx.Locale.Tr calls. Add corresponding keys to
the custom locale file.

Fixes AI Review Issue #6.
Add sessionStorage guard so the automatic redirect from split to
unified view on mobile only fires once per session. Previously, if
a user switched back to split view, they'd be immediately redirected
again.

Fixes AI Review Issue #7.
This was referenced Mar 3, 2026
Base automatically changed from update-fork-design to master March 3, 2026 16:03
@taoeffect
Copy link
Member

taoeffect commented Mar 3, 2026

/crush_fast


AI review started.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

Advanced AI Review

  • Type: Agentic (crush)
  • Model: glm-5
Click to expand review

Code Review: Fix Diff Comments

Issue 1: 🟡 Safe Type Assertion Improvement - routers/web/repo/pull.go:791-792

  • Addressed
  • Dismissed

Context: The change from:

if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil {

to:

showOutdatedComments, _ := ctx.Data["ShowOutdatedComments"].(bool)
if err = diff.LoadComments(ctx, issue, ctx.Doer, showOutdatedComments); err != nil {

Assessment: This is a correct bug fix. The original code could panic if ctx.Data["ShowOutdatedComments"] is nil (not set) or contains a non-bool value. The safe comma-ok idiom prevents this by defaulting to false when the value is not present or not a bool.

While the middleware SetShowOutdatedComments should always set this value before this handler runs (as seen in web.go:1241, 1249, 1250), this defensive coding is appropriate for robustness against future code changes where someone might forget to add the middleware.

No changes needed - this is a good fix.


Issue 2: 🟡 Safe Type Assertion Improvement - routers/web/repo/pull_review.go:172-173

  • Addressed
  • Dismissed

Context: The change from:

showOutdatedComments := origin == "timeline" || ctx.Data["ShowOutdatedComments"].(bool)

to:

showOutdatedComments, _ := ctx.Data["ShowOutdatedComments"].(bool)
showOutdatedComments = origin == "timeline" || showOutdatedComments

Assessment: This is also a correct bug fix with the same reasoning as Issue 1. The logic is preserved:

Scenario Before After
origin == "timeline", value is true true (short-circuit) true
origin == "timeline", value is false true (short-circuit) true
origin == "timeline", value is nil PANIC true
origin != "timeline", value is true true true
origin != "timeline", value is false false false
origin != "timeline", value is nil PANIC false

The test at routers/web/repo/pull_review_test.go:70-74 confirms this behavior is expected:

run("timeline is not affected by ShowOutdatedComments=false", func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder) {
    ctx.Data["ShowOutdatedComments"] = false
    renderConversation(ctx, preparedComment, "timeline")
    assert.Contains(t, resp.Body.String(), `<div id="code-comments-`)
})

No changes needed - this is a good fix.


Summary

These are both valid bug fixes that prevent potential runtime panics from failed type assertions. The changes:

  1. Are safe: Use the comma-ok idiom to prevent panics when ctx.Data["ShowOutdatedComments"] is unset or not a bool
  2. Preserve behavior: The logical behavior is unchanged in all scenarios where the value is properly set
  3. Improve robustness: Even though middleware should set these values, defensive coding protects against future code paths that might skip the middleware

No issues found that require changes. The PR is ready to merge.


Review generated using glm-5 via Z.AI. Comment /crush_fast to re-run.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Great work @pedrogaudencio !

@taoeffect taoeffect merged commit cc5bf53 into master Mar 3, 2026
33 checks passed
@taoeffect taoeffect deleted the change-request-fix-diff-comments branch March 3, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix error adding comment in diff view Add change-request review workflow

3 participants