-
Notifications
You must be signed in to change notification settings - Fork 497
feat(pr-comments): address PR comments from sidebar #2384
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ export type PullRequestDescriptionItem = { | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export type PullRequestConversationItem = PullRequestDescriptionItem | PullRequestComment; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export type AddressablePullRequestComment = PullRequestComment; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function descriptionItemForPr(pr: PullRequest): PullRequestDescriptionItem | null { | ||||||||||||||||||||||||||||||||||||||||||
| const body = pr.description?.trim(); | ||||||||||||||||||||||||||||||||||||||||||
| if (!body) return null; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -57,3 +59,49 @@ export function buildPullRequestConversationItems( | |||||||||||||||||||||||||||||||||||||||||
| const description = descriptionItemForPr(pr); | ||||||||||||||||||||||||||||||||||||||||||
| return [...(description ? [description] : []), ...comments]; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export function isAddressablePullRequestComment( | ||||||||||||||||||||||||||||||||||||||||||
| item: PullRequestConversationItem | ||||||||||||||||||||||||||||||||||||||||||
| ): item is AddressablePullRequestComment { | ||||||||||||||||||||||||||||||||||||||||||
| return item.kind !== 'description'; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function commentAuthorLabel(comment: AddressablePullRequestComment): string { | ||||||||||||||||||||||||||||||||||||||||||
| return comment.author?.displayName ?? comment.author?.userName ?? 'Unknown author'; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function commentLocationLabel(comment: AddressablePullRequestComment): string | null { | ||||||||||||||||||||||||||||||||||||||||||
| if (!comment.path) return null; | ||||||||||||||||||||||||||||||||||||||||||
| return comment.line ? `${comment.path}:${comment.line}` : comment.path; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function escapeXmlText(value: string): string { | ||||||||||||||||||||||||||||||||||||||||||
| return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function metadataLine(label: string, value: string): string { | ||||||||||||||||||||||||||||||||||||||||||
| return `${label}: ${escapeXmlText(value)}`; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export function formatPullRequestCommentForAgent( | ||||||||||||||||||||||||||||||||||||||||||
| pr: PullRequest, | ||||||||||||||||||||||||||||||||||||||||||
| comment: AddressablePullRequestComment | ||||||||||||||||||||||||||||||||||||||||||
| ): string { | ||||||||||||||||||||||||||||||||||||||||||
| const prLabel = pr.identifier ? `${pr.identifier} ${pr.title}` : pr.title; | ||||||||||||||||||||||||||||||||||||||||||
| const location = commentLocationLabel(comment); | ||||||||||||||||||||||||||||||||||||||||||
| const metadata = [ | ||||||||||||||||||||||||||||||||||||||||||
| metadataLine('Pull request', prLabel), | ||||||||||||||||||||||||||||||||||||||||||
| metadataLine('Pull request URL', pr.url), | ||||||||||||||||||||||||||||||||||||||||||
| metadataLine('Comment URL', comment.url), | ||||||||||||||||||||||||||||||||||||||||||
| metadataLine('Author', commentAuthorLabel(comment)), | ||||||||||||||||||||||||||||||||||||||||||
| metadataLine('Created', comment.createdAt), | ||||||||||||||||||||||||||||||||||||||||||
| location ? metadataLine('Location', location) : null, | ||||||||||||||||||||||||||||||||||||||||||
| comment.isResolved ? 'Status: resolved' : null, | ||||||||||||||||||||||||||||||||||||||||||
| comment.isOutdated ? 'Status: outdated' : null, | ||||||||||||||||||||||||||||||||||||||||||
| ].filter((line): line is string => line !== null); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+92
to
+101
Contributor
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.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/renderer/features/tasks/diff-view/changes-panel/components/pr-entry/pull-request-conversation.ts
Line: 92-101
Comment:
`metadataLine` applies `escapeXmlText` to every value, including URL fields. Any URL containing `&` in query parameters (common in GitLab/Bitbucket merge-request URLs, redirect links, etc.) will arrive in the agent's prompt as `&`, making the URL unusable as-is. URL metadata lines should skip HTML entity escaping.
```suggestion
const metadata = [
metadataLine('Pull request', prLabel),
`Pull request URL: ${pr.url}`,
`Comment URL: ${comment.url}`,
metadataLine('Author', commentAuthorLabel(comment)),
metadataLine('Created', comment.createdAt),
location ? metadataLine('Location', location) : null,
comment.isResolved ? 'Status: resolved' : null,
comment.isOutdated ? 'Status: outdated' : null,
].filter((line): line is string => line !== null);
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return `${metadata.join('\n')} | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Body: | ||||||||||||||||||||||||||||||||||||||||||
| ${escapeXmlText(comment.body.trim())}`; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
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.
ContextMenuis rendered for every addressable comment regardless of whether either handler is provided. When bothonAddressInActiveChatandonAddressInNewChatareundefined(no active session and no available provider), right-clicking any comment shows a context menu whose two items are both disabled — a dead-end UX with no actionable option. Skipping the context menu wrapper when no action is available avoids presenting useless UI.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!