-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add inline code comments on commits (#4898) #35589
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,8 @@ const ( | |
CommentTypeUnpin // 37 unpin Issue/PullRequest | ||
|
||
CommentTypeChangeTimeEstimate // 38 Change time estimate | ||
|
||
CommentTypeCommitCode // 39 Comment a line of code in a commit (not part of a pull request) | ||
) | ||
|
||
var commentStrings = []string{ | ||
|
@@ -157,6 +159,7 @@ var commentStrings = []string{ | |
"pin", | ||
"unpin", | ||
"change_time_estimate", | ||
"commit_code", | ||
} | ||
|
||
func (t CommentType) String() string { | ||
|
@@ -174,23 +177,23 @@ func AsCommentType(typeName string) CommentType { | |
|
||
func (t CommentType) HasContentSupport() bool { | ||
switch t { | ||
case CommentTypeComment, CommentTypeCode, CommentTypeReview, CommentTypeDismissReview: | ||
case CommentTypeComment, CommentTypeCode, CommentTypeReview, CommentTypeDismissReview, CommentTypeCommitCode: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (t CommentType) HasAttachmentSupport() bool { | ||
switch t { | ||
case CommentTypeComment, CommentTypeCode, CommentTypeReview: | ||
case CommentTypeComment, CommentTypeCode, CommentTypeReview, CommentTypeCommitCode: | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (t CommentType) HasMailReplySupport() bool { | ||
switch t { | ||
case CommentTypeComment, CommentTypeCode, CommentTypeReview, CommentTypeDismissReview, CommentTypeReopen, CommentTypeClose, CommentTypeMergePull, CommentTypeAssignees: | ||
case CommentTypeComment, CommentTypeCode, CommentTypeReview, CommentTypeDismissReview, CommentTypeReopen, CommentTypeClose, CommentTypeMergePull, CommentTypeAssignees, CommentTypeCommitCode: | ||
return true | ||
} | ||
return false | ||
|
@@ -447,6 +450,9 @@ func (c *Comment) hashLink(ctx context.Context) string { | |
return "/files#" + c.HashTag() | ||
} | ||
} | ||
if c.Type == CommentTypeCommitCode { | ||
return "/files#" + c.HashTag() | ||
} | ||
return "#" + c.HashTag() | ||
} | ||
|
||
|
@@ -657,9 +663,9 @@ func (c *Comment) LoadAssigneeUserAndTeam(ctx context.Context) error { | |
return nil | ||
} | ||
|
||
// LoadResolveDoer if comment.Type is CommentTypeCode and ResolveDoerID not zero, then load resolveDoer | ||
// LoadResolveDoer if comment.Type is CommentTypeCode or CommentTypeCommitCode and ResolveDoerID not zero, then load resolveDoer | ||
func (c *Comment) LoadResolveDoer(ctx context.Context) (err error) { | ||
if c.ResolveDoerID == 0 || c.Type != CommentTypeCode { | ||
if c.ResolveDoerID == 0 || (c.Type != CommentTypeCode && c.Type != CommentTypeCommitCode) { | ||
return nil | ||
} | ||
c.ResolveDoer, err = user_model.GetUserByID(ctx, c.ResolveDoerID) | ||
|
@@ -674,7 +680,7 @@ func (c *Comment) LoadResolveDoer(ctx context.Context) (err error) { | |
|
||
// IsResolved check if an code comment is resolved | ||
func (c *Comment) IsResolved() bool { | ||
return c.ResolveDoerID != 0 && c.Type == CommentTypeCode | ||
return c.ResolveDoerID != 0 && (c.Type == CommentTypeCode || c.Type == CommentTypeCommitCode) | ||
} | ||
|
||
// LoadDepIssueDetails loads Dependent Issue Details | ||
|
@@ -862,6 +868,12 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment | |
if err = UpdateCommentAttachments(ctx, comment, opts.Attachments); err != nil { | ||
return err | ||
} | ||
case CommentTypeCommitCode: | ||
if err = UpdateCommentAttachments(ctx, comment, opts.Attachments); err != nil { | ||
return err | ||
} | ||
// Commit comments don't have an associated issue, so just return here | ||
return nil | ||
case CommentTypeReopen, CommentTypeClose: | ||
if err = repo_model.UpdateRepoIssueNumbers(ctx, opts.Issue.RepoID, opts.Issue.IsPull, true); err != nil { | ||
return err | ||
|
@@ -1076,6 +1088,42 @@ func CountComments(ctx context.Context, opts *FindCommentsOptions) (int64, error | |
return sess.Count(&Comment{}) | ||
} | ||
|
||
// FindCommitComments finds all code comments for a specific commit | ||
func FindCommitComments(ctx context.Context, repoID int64, commitSHA string) (CommentList, error) { | ||
comments := make([]*Comment, 0, 10) | ||
return comments, db.GetEngine(ctx). | ||
Where("commit_sha = ?", commitSHA). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Currently, commit comments don't have a We have a few options:
What would you prefer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think this is accepted. So that I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good - a separate New
Then when querying, we'd join with this table to filter by repo. This keeps the comment table unchanged and makes the commit-specific metadata explicit. Should I proceed with implementing this approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds better than before. But I don't know wether it could be accepted by other @go-gitea/maintainers . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see - this is a deeper architectural issue. The attachment system expects bindings to issues/releases, so commit comment attachments (without Given the complexity here, I'll wait for maintainer consensus on the best approach before proceeding. Please tag me when there's a decision on how to handle this properly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @delvh Dude.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm out. Solve it for yourself There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good luck! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the misunderstanding. Maybe some messages read too like "vibe coding" and there were a lot of AI PRs from other contributors 🤣 Apologize again. By the way I am not a native speaker, so please point out if my comment doesn't read good. By your analysis, I think I can see a potential feasible approach now, although not completely clear yet, share some points:
|
||
And("type = ?", CommentTypeCommitCode). | ||
Asc("created_unix"). | ||
Asc("id"). | ||
Find(&comments) | ||
} | ||
|
||
// FindCommitLineComments finds code comments for a specific file and line in a commit | ||
func FindCommitLineComments(ctx context.Context, commitSHA, treePath string) (CommentList, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to filter by tree path and line in the memory otherwise, we need a new index for the database. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need a new composite index There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently the Comment table doesn't have a
Should I proceed with creating this migration? |
||
// Fetch all commit code comments for this commit (filter by tree path in memory to avoid needing a new index) | ||
allComments := make([]*Comment, 0, 10) | ||
err := db.GetEngine(ctx). | ||
Where("commit_sha = ?", commitSHA). | ||
And("type = ?", CommentTypeCommitCode). | ||
Asc("created_unix"). | ||
Asc("id"). | ||
Find(&allComments) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Filter in memory by tree path | ||
comments := make(CommentList, 0, len(allComments)) | ||
for _, comment := range allComments { | ||
if comment.TreePath == treePath { | ||
comments = append(comments, comment) | ||
} | ||
} | ||
|
||
return comments, nil | ||
} | ||
|
||
// UpdateCommentInvalidate updates comment invalidated column | ||
func UpdateCommentInvalidate(ctx context.Context, c *Comment) error { | ||
_, err := db.GetEngine(ctx).ID(c.ID).Cols("invalidated").Update(c) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an index for the query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently there's an index on
type
but not oncommit_sha
. This function would benefit from an index oncommit_sha
(or a composite index on(commit_sha, type)
) since it queries by that field directly. Should I add one in a migration?