@@ -39,11 +39,22 @@ import type {
3939import { summarizeProjectActivityEvents } from "./projectActivity.mjs" ;
4040import type { ProjectIssue } from "./projectIssues.mjs" ;
4141import { projectIssueEventsToIssues } from "./projectIssues.mjs" ;
42- import type { ProjectPullRequest } from "./projectPullRequests.mjs" ;
43- import { projectPullRequestEventsToPullRequests } from "./projectPullRequests.mjs" ;
42+ import type {
43+ ProjectPullRequest ,
44+ ProjectPullRequestCommentAnchor ,
45+ } from "./projectPullRequests.mjs" ;
46+ import {
47+ normalizeProjectPullRequestCommentAnchor ,
48+ PR_INLINE_COMMENT_LABEL ,
49+ projectPullRequestEventsToPullRequests ,
50+ } from "./projectPullRequests.mjs" ;
4451import { fetchProjectsWorkItems } from "./projectWorkItems" ;
4552
46- export type { ProjectIssue , ProjectPullRequest } ;
53+ export type {
54+ ProjectIssue ,
55+ ProjectPullRequest ,
56+ ProjectPullRequestCommentAnchor ,
57+ } ;
4758
4859const HIDDEN_PROJECT_CARDS_KEY = "buzz.projects.hidden-cards.v1" ;
4960
@@ -391,12 +402,14 @@ async function fetchProjectPullRequests(
391402// features/pulse/lib/projectComments.ts). If the relay ever allowlists
392403// 1111, migrate these to NIP-22 comments and drop that filter.
393404async function createProjectPullRequestComment ( {
405+ anchor,
394406 content,
395407 mediaTags,
396408 mentionPubkeys = [ ] ,
397409 project,
398410 pullRequest,
399411} : {
412+ anchor ?: ProjectPullRequestCommentAnchor ;
400413 content : string ;
401414 mediaTags ?: string [ ] [ ] ;
402415 mentionPubkeys ?: string [ ] ;
@@ -407,6 +420,15 @@ async function createProjectPullRequestComment({
407420 if ( ! body ) {
408421 throw new Error ( "Comment cannot be empty." ) ;
409422 }
423+ const normalizedAnchor = anchor
424+ ? normalizeProjectPullRequestCommentAnchor ( anchor )
425+ : null ;
426+ if ( anchor && ! normalizedAnchor ) {
427+ throw new Error ( "Comment location is invalid." ) ;
428+ }
429+ if ( normalizedAnchor && ! pullRequest . commit ) {
430+ throw new Error ( "Pull request commit is required for inline comments." ) ;
431+ }
410432
411433 const recipients = new Set ( [
412434 project . owner . toLowerCase ( ) ,
@@ -418,6 +440,15 @@ async function createProjectPullRequestComment({
418440 [ "e" , pullRequest . id , "" , "root" ] ,
419441 [ "a" , project . repoAddress ] ,
420442 ...[ ...recipients ] . map ( ( recipient ) => [ "p" , recipient ] ) ,
443+ ...( normalizedAnchor
444+ ? [
445+ [ "t" , PR_INLINE_COMMENT_LABEL ] ,
446+ [ "c" , pullRequest . commit as string ] ,
447+ [ "file" , normalizedAnchor . path ] ,
448+ [ "side" , normalizedAnchor . side ] ,
449+ [ "line" , String ( normalizedAnchor . line ) ] ,
450+ ]
451+ : [ ] ) ,
421452 ...( mediaTags ?? [ ] ) ,
422453 ] ;
423454
@@ -826,18 +857,21 @@ export function useCreateProjectPullRequestCommentMutation(
826857
827858 return useMutation ( {
828859 mutationFn : ( {
860+ anchor,
829861 content,
830862 mediaTags,
831863 mentionPubkeys,
832864 pullRequest,
833865 } : {
866+ anchor ?: ProjectPullRequestCommentAnchor ;
834867 content : string ;
835868 mediaTags ?: string [ ] [ ] ;
836869 mentionPubkeys ?: string [ ] ;
837870 pullRequest : ProjectPullRequest ;
838871 } ) => {
839872 if ( ! project ) throw new Error ( "No project selected." ) ;
840873 return createProjectPullRequestComment ( {
874+ anchor,
841875 content,
842876 mediaTags,
843877 mentionPubkeys,
0 commit comments