Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/main/ipc/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,88 @@ describe('registerGitHubHandlers', () => {
)
})

it('broadcasts mutation notifications by repo id even when the payload path is remote', async () => {
const sendMock = vi.fn()
getAllWebContentsMock.mockReturnValue([
{ id: 1, isDestroyed: () => false, send: vi.fn() },
{ id: 2, isDestroyed: () => false, send: sendMock }
])
registerGitHubHandlers(store as never, stats as never)

const result = await handlers['gh:notifyWorkItemMutated'](
{ sender: { id: 1 } },
{
repoPath: '/home/runtime/repo',
repoId: 'repo-1',
type: 'pr',
number: 42
}
)

expect(result).toBe(true)
expect(sendMock).toHaveBeenCalledWith('gh:workItemMutated', {
repoPath: '/workspace/repo',
repoId: 'repo-1',
type: 'pr',
number: 42
})
})

it('broadcasts mutation notifications with resolved repo id when called by repo path', async () => {
const sendMock = vi.fn()
getAllWebContentsMock.mockReturnValue([
{ id: 1, isDestroyed: () => false, send: vi.fn() },
{ id: 2, isDestroyed: () => false, send: sendMock }
])
registerGitHubHandlers(store as never, stats as never)

const result = await handlers['gh:notifyWorkItemMutated'](
{ sender: { id: 1 } },
{
repoPath: '/workspace/repo',
type: 'issue',
number: 7
}
)

expect(result).toBe(true)
expect(sendMock).toHaveBeenCalledWith('gh:workItemMutated', {
repoPath: '/workspace/repo',
repoId: 'repo-1',
type: 'issue',
number: 7
})
})

it('broadcasts PR file viewed mutations with repo id for sibling cache invalidation', async () => {
const sendMock = vi.fn()
getAllWebContentsMock.mockReturnValue([
{ id: 1, isDestroyed: () => false, send: vi.fn() },
{ id: 2, isDestroyed: () => false, send: sendMock }
])
setPRFileViewedMock.mockResolvedValue(true)
registerGitHubHandlers(store as never, stats as never)

const result = await handlers['gh:setPRFileViewed'](
{ sender: { id: 1 } },
{
repoPath: '/workspace/repo',
prNumber: 42,
pullRequestId: 'PR_kw',
path: 'src/app.ts',
viewed: true
}
)

expect(result).toBe(true)
expect(sendMock).toHaveBeenCalledWith('gh:workItemMutated', {
repoPath: '/workspace/repo',
repoId: 'repo-1',
type: 'pr',
number: 42
})
})

it('rejects unknown repository paths', async () => {
registerGitHubHandlers(store as never, stats as never)

Expand Down
40 changes: 39 additions & 1 deletion src/main/ipc/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,44 @@ export function registerGitHubHandlers(store: Store, stats: StatsCollector): voi
return dispatchWorkItem(args, repo, getWorkItemDetails, localGitOptionArgs(store, repo)[0])
})

ipcMain.handle(
'gh:notifyWorkItemMutated',
(
event,
args: {
repoPath: string
repoId?: string
type: 'issue' | 'pr'
number: number
}
) => {
const repo = args.repoId
? store.getRepos().find((candidate) => candidate.id === args.repoId)
: assertRegisteredRepo(args, store)
if (!repo) {
return false
}
if (
(args.type !== 'issue' && args.type !== 'pr') ||
typeof args.number !== 'number' ||
!Number.isInteger(args.number) ||
args.number < 1
) {
return false
}
broadcastWorkItemMutated(
{
repoPath: repo.path,
repoId: repo.id,
type: args.type,
number: args.number
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
event.sender.id
)
return true
}
)

ipcMain.handle(
'gh:prFileContents',
(
Expand Down Expand Up @@ -688,7 +726,7 @@ export function registerGitHubHandlers(store: Store, stats: StatsCollector): voi
})
if (ok) {
broadcastWorkItemMutated(
{ repoPath: repo.path, type: 'pr', number: args.prNumber },
{ repoPath: repo.path, repoId: repo.id, type: 'pr', number: args.prNumber },
event.sender.id
)
}
Expand Down
6 changes: 6 additions & 0 deletions src/preload/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,12 @@ export type PreloadApi = {
type?: 'issue' | 'pr'
}
) => Promise<GitHubWorkItemDetails | null>
notifyWorkItemMutated: (args: {
repoPath: string
repoId?: string
type: 'issue' | 'pr'
number: number
}) => Promise<boolean>
prFileContents: (
args: GitHubRepoSelectorArgs & {
prNumber: number
Expand Down
7 changes: 7 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,13 @@ const api = {
type?: 'issue' | 'pr'
}): Promise<unknown> => ipcRenderer.invoke('gh:workItemDetails', args),

notifyWorkItemMutated: (args: {
repoPath: string
repoId?: string
type: 'issue' | 'pr'
number: number
}): Promise<boolean> => ipcRenderer.invoke('gh:notifyWorkItemMutated', args),

prFileContents: (args: {
repoPath: string
repoId?: string
Expand Down
Loading
Loading