Add web GitLab runtime parity (#2614)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import type { MRListState } from '../../shared/types'
|
||||
|
||||
export type GitLabIssueListState = 'opened' | 'closed' | 'all'
|
||||
|
||||
export function normalizeGitLabPositiveInteger(
|
||||
value: unknown,
|
||||
fallback: number,
|
||||
max: number
|
||||
): number {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
||||
return fallback
|
||||
}
|
||||
return Math.min(Math.max(1, Math.trunc(value)), max)
|
||||
}
|
||||
|
||||
export function normalizeGitLabMRListState(value: unknown): MRListState {
|
||||
return value === 'merged' || value === 'closed' || value === 'all' ? value : 'opened'
|
||||
}
|
||||
|
||||
export function normalizeGitLabIssueListState(value: unknown): GitLabIssueListState {
|
||||
return value === 'closed' || value === 'all' ? value : 'opened'
|
||||
}
|
||||
|
||||
export function normalizeGitLabIssueAssignee(value: unknown): '@me' | undefined {
|
||||
// Why: the renderer only exposes "Assigned to me"; accepting arbitrary
|
||||
// values would turn preload/RPC boundaries into a generic glab flag surface.
|
||||
return value === '@me' ? '@me' : undefined
|
||||
}
|
||||
|
||||
export function normalizeGitLabIssueListArgs(args: {
|
||||
state?: unknown
|
||||
assignee?: unknown
|
||||
limit?: unknown
|
||||
}): {
|
||||
state: GitLabIssueListState
|
||||
assignee: '@me' | undefined
|
||||
limit: number
|
||||
} {
|
||||
return {
|
||||
state: normalizeGitLabIssueListState(args.state),
|
||||
assignee: normalizeGitLabIssueAssignee(args.assignee),
|
||||
limit: normalizeGitLabPositiveInteger(args.limit, 20, 100)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { GlobalSettings } from '../../shared/types'
|
||||
import { computeNextGitLabRecents } from '../../shared/gitlab-projects'
|
||||
|
||||
export type GitLabProjectRecentsStore = {
|
||||
getSettings(): Pick<GlobalSettings, 'gitlabProjects'>
|
||||
updateSettings(updates: Pick<GlobalSettings, 'gitlabProjects'>): unknown
|
||||
}
|
||||
|
||||
export function recordGitLabProjectRecent(
|
||||
store: GitLabProjectRecentsStore,
|
||||
host: string,
|
||||
path: string
|
||||
): void {
|
||||
const settings = store.getSettings()
|
||||
const existing = settings.gitlabProjects ?? { pinned: [], recent: [] }
|
||||
store.updateSettings({
|
||||
gitlabProjects: {
|
||||
pinned: existing.pinned,
|
||||
recent: computeNextGitLabRecents(existing.recent, host, path)
|
||||
}
|
||||
})
|
||||
}
|
||||
+18
-46
@@ -3,8 +3,15 @@ GitLab IPC handlers co-located keeps the repo-path validation pattern
|
||||
reviewable as one surface. */
|
||||
import { ipcMain } from 'electron'
|
||||
import { resolve } from 'path'
|
||||
import type { GitLabIssueUpdate, GitLabWorkItem, MRListState, Repo } from '../../shared/types'
|
||||
import type { GitLabIssueUpdate, GitLabWorkItem, Repo } from '../../shared/types'
|
||||
import type { Store } from '../persistence'
|
||||
import {
|
||||
normalizeGitLabIssueAssignee,
|
||||
normalizeGitLabIssueListState,
|
||||
normalizeGitLabMRListState,
|
||||
normalizeGitLabPositiveInteger
|
||||
} from '../gitlab/gitlab-preload-args'
|
||||
import { recordGitLabProjectRecent } from '../gitlab/gitlab-project-recents'
|
||||
import {
|
||||
addIssueComment,
|
||||
addMRComment,
|
||||
@@ -27,7 +34,6 @@ import {
|
||||
updateIssue
|
||||
} from '../gitlab/client'
|
||||
import { getWorkItemDetails } from '../gitlab/work-item-details'
|
||||
import { computeNextGitLabRecents } from '../../shared/gitlab-projects'
|
||||
import type { ProjectRef } from '../gitlab/gl-utils'
|
||||
|
||||
// Why: mirror github.ts assertRegisteredRepo — main-process handlers
|
||||
@@ -42,29 +48,6 @@ function assertRegisteredRepo(repoPath: string, store: Store): Repo {
|
||||
return repo
|
||||
}
|
||||
|
||||
function normalizePositiveInteger(value: unknown, fallback: number, max: number): number {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
||||
return fallback
|
||||
}
|
||||
return Math.min(Math.max(1, Math.trunc(value)), max)
|
||||
}
|
||||
|
||||
function normalizeMRListState(value: unknown): MRListState {
|
||||
return value === 'merged' || value === 'closed' || value === 'all' ? value : 'opened'
|
||||
}
|
||||
|
||||
type GitLabIssueListState = 'opened' | 'closed' | 'all'
|
||||
|
||||
function normalizeIssueListState(value: unknown): GitLabIssueListState {
|
||||
return value === 'closed' || value === 'all' ? value : 'opened'
|
||||
}
|
||||
|
||||
function normalizeIssueAssignee(value: unknown): '@me' | undefined {
|
||||
// Why: the renderer only exposes "Assigned to me"; accepting arbitrary
|
||||
// values here would turn this IPC boundary into a generic glab flag surface.
|
||||
return value === '@me' ? '@me' : undefined
|
||||
}
|
||||
|
||||
function repoConnectionId(repo: Repo): string | null {
|
||||
return repo.connectionId ?? null
|
||||
}
|
||||
@@ -109,9 +92,9 @@ export function registerGitLabHandlers(store: Store): void {
|
||||
}
|
||||
) => {
|
||||
const repo = assertRegisteredRepo(args.repoPath, store)
|
||||
const state = normalizeMRListState(args.state)
|
||||
const page = normalizePositiveInteger(args.page, 1, 10_000)
|
||||
const perPage = normalizePositiveInteger(args.perPage, 20, 100)
|
||||
const state = normalizeGitLabMRListState(args.state)
|
||||
const page = normalizeGitLabPositiveInteger(args.page, 1, 10_000)
|
||||
const perPage = normalizeGitLabPositiveInteger(args.perPage, 20, 100)
|
||||
return listMergeRequests(
|
||||
repo.path,
|
||||
state,
|
||||
@@ -141,9 +124,9 @@ export function registerGitLabHandlers(store: Store): void {
|
||||
}
|
||||
) => {
|
||||
const repo = assertRegisteredRepo(args.repoPath, store)
|
||||
const limit = normalizePositiveInteger(args.limit, 20, 100)
|
||||
const state = normalizeIssueListState(args.state)
|
||||
const assignee = normalizeIssueAssignee(args.assignee)
|
||||
const limit = normalizeGitLabPositiveInteger(args.limit, 20, 100)
|
||||
const state = normalizeGitLabIssueListState(args.state)
|
||||
const assignee = normalizeGitLabIssueAssignee(args.assignee)
|
||||
const result = await listIssues(
|
||||
repo.path,
|
||||
limit,
|
||||
@@ -240,9 +223,9 @@ export function registerGitLabHandlers(store: Store): void {
|
||||
const repo = assertRegisteredRepo(args.repoPath, store)
|
||||
return listWorkItems(
|
||||
repo.path,
|
||||
normalizeMRListState(args.state),
|
||||
normalizePositiveInteger(args.page, 1, 10_000),
|
||||
normalizePositiveInteger(args.perPage, 20, 100),
|
||||
normalizeGitLabMRListState(args.state),
|
||||
normalizeGitLabPositiveInteger(args.page, 1, 10_000),
|
||||
normalizeGitLabPositiveInteger(args.perPage, 20, 100),
|
||||
repo.issueSourcePreference,
|
||||
undefined,
|
||||
repoConnectionId(repo)
|
||||
@@ -344,20 +327,9 @@ export function registerGitLabHandlers(store: Store): void {
|
||||
// produced an item. A 404 / auth failure shouldn't pollute the
|
||||
// user's recents list with project paths they can't read.
|
||||
if (result) {
|
||||
addGitLabProjectToRecent(store, args.host, args.path)
|
||||
recordGitLabProjectRecent(store, args.host, args.path)
|
||||
}
|
||||
return result
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function addGitLabProjectToRecent(store: Store, host: string, path: string): void {
|
||||
const settings = store.getSettings()
|
||||
const existing = settings.gitlabProjects ?? { pinned: [], recent: [] }
|
||||
store.updateSettings({
|
||||
gitlabProjects: {
|
||||
pinned: existing.pinned,
|
||||
recent: computeNextGitLabRecents(existing.recent, host, path)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -50,9 +50,12 @@ const {
|
||||
createHostedReviewMock,
|
||||
getHostedReviewCreationEligibilityMock,
|
||||
getPRForBranchMock,
|
||||
listGitHubIssuesMock,
|
||||
detectInstalledAgentsMock,
|
||||
detectRemoteAgentsMock,
|
||||
listGitLabMergeRequestsMock,
|
||||
listGitLabWorkItemsMock,
|
||||
listGitLabIssuesMock,
|
||||
listGitLabTodosMock,
|
||||
getGitLabProjectRefForRemoteMock,
|
||||
getGitLabWorkItemByProjectRefMock,
|
||||
@@ -99,9 +102,12 @@ const {
|
||||
createHostedReviewMock: vi.fn(),
|
||||
getHostedReviewCreationEligibilityMock: vi.fn(),
|
||||
getPRForBranchMock: vi.fn().mockResolvedValue(null),
|
||||
listGitHubIssuesMock: vi.fn(),
|
||||
detectInstalledAgentsMock: vi.fn(),
|
||||
detectRemoteAgentsMock: vi.fn(),
|
||||
listGitLabMergeRequestsMock: vi.fn(),
|
||||
listGitLabWorkItemsMock: vi.fn(),
|
||||
listGitLabIssuesMock: vi.fn(),
|
||||
listGitLabTodosMock: vi.fn(),
|
||||
getGitLabProjectRefForRemoteMock: vi.fn(),
|
||||
getGitLabWorkItemByProjectRefMock: vi.fn(),
|
||||
@@ -195,7 +201,8 @@ vi.mock('../github/client', async (importOriginal) => {
|
||||
const actual = (await importOriginal()) as Record<string, unknown>
|
||||
return {
|
||||
...actual,
|
||||
getPRForBranch: getPRForBranchMock
|
||||
getPRForBranch: getPRForBranchMock,
|
||||
listIssues: listGitHubIssuesMock
|
||||
}
|
||||
})
|
||||
|
||||
@@ -203,7 +210,9 @@ vi.mock('../gitlab/client', async (importOriginal) => {
|
||||
const actual = (await importOriginal()) as Record<string, unknown>
|
||||
return {
|
||||
...actual,
|
||||
listMergeRequests: listGitLabMergeRequestsMock,
|
||||
listWorkItems: listGitLabWorkItemsMock,
|
||||
listIssues: listGitLabIssuesMock,
|
||||
listTodos: listGitLabTodosMock,
|
||||
getProjectRefForRemote: getGitLabProjectRefForRemoteMock,
|
||||
getWorkItemByProjectRef: getGitLabWorkItemByProjectRefMock,
|
||||
@@ -318,12 +327,18 @@ afterEach(() => {
|
||||
})
|
||||
getPRForBranchMock.mockReset()
|
||||
getPRForBranchMock.mockResolvedValue(null)
|
||||
listGitHubIssuesMock.mockReset()
|
||||
listGitHubIssuesMock.mockResolvedValue({ items: [] })
|
||||
detectInstalledAgentsMock.mockReset()
|
||||
detectInstalledAgentsMock.mockResolvedValue([])
|
||||
detectRemoteAgentsMock.mockReset()
|
||||
detectRemoteAgentsMock.mockResolvedValue([])
|
||||
listGitLabMergeRequestsMock.mockReset()
|
||||
listGitLabMergeRequestsMock.mockResolvedValue({ items: [] })
|
||||
listGitLabWorkItemsMock.mockReset()
|
||||
listGitLabWorkItemsMock.mockResolvedValue({ items: [] })
|
||||
listGitLabIssuesMock.mockReset()
|
||||
listGitLabIssuesMock.mockResolvedValue({ items: [] })
|
||||
listGitLabTodosMock.mockReset()
|
||||
listGitLabTodosMock.mockResolvedValue([])
|
||||
getGitLabProjectRefForRemoteMock.mockReset()
|
||||
@@ -1618,6 +1633,9 @@ describe('OrcaRuntimeService', () => {
|
||||
|
||||
it('allows host integration slug helpers for SSH repos through provider-aware GitHub clients', async () => {
|
||||
getIssueMock.mockResolvedValueOnce({ number: 12, title: 'Remote issue' })
|
||||
listGitHubIssuesMock.mockResolvedValueOnce({
|
||||
items: [{ number: 7, title: 'Remote issue list item' }]
|
||||
})
|
||||
const remoteStore = {
|
||||
...store,
|
||||
getRepos: () => [
|
||||
@@ -1638,7 +1656,11 @@ describe('OrcaRuntimeService', () => {
|
||||
number: 12,
|
||||
title: 'Remote issue'
|
||||
})
|
||||
await expect(runtime.listRepoIssues('id:repo-1', 10)).resolves.toEqual([
|
||||
{ number: 7, title: 'Remote issue list item' }
|
||||
])
|
||||
expect(getIssueMock).toHaveBeenCalledWith('/remote/repo', 12, 'ssh-1')
|
||||
expect(listGitHubIssuesMock).toHaveBeenCalledWith('/remote/repo', 10, undefined, 'ssh-1')
|
||||
})
|
||||
|
||||
it('rejects hosted review worktree selectors outside the selected repo', async () => {
|
||||
@@ -7200,8 +7222,27 @@ describe('OrcaRuntimeService', () => {
|
||||
})
|
||||
|
||||
it('passes SSH connection ids through GitLab task operations', async () => {
|
||||
listGitLabMergeRequestsMock.mockResolvedValue({ items: [] })
|
||||
listGitLabWorkItemsMock.mockResolvedValue({ items: [] })
|
||||
listGitLabIssuesMock.mockResolvedValue({
|
||||
items: [
|
||||
{
|
||||
number: 7,
|
||||
title: 'Issue title',
|
||||
state: 'opened',
|
||||
url: 'https://gitlab.example/issues/7',
|
||||
labels: ['bug'],
|
||||
updatedAt: '2026-05-22T00:00:00Z',
|
||||
author: 'alex'
|
||||
}
|
||||
]
|
||||
})
|
||||
listGitLabTodosMock.mockResolvedValue([])
|
||||
getGitLabWorkItemByProjectRefMock.mockResolvedValue({
|
||||
id: 'gitlab-issue-7',
|
||||
type: 'issue',
|
||||
number: 7
|
||||
})
|
||||
createGitLabIssueMock.mockResolvedValue({
|
||||
ok: true,
|
||||
number: 1,
|
||||
@@ -7231,7 +7272,9 @@ describe('OrcaRuntimeService', () => {
|
||||
}
|
||||
const runtime = new OrcaRuntimeService(runtimeStore as never)
|
||||
|
||||
await runtime.listGitLabRepoMRs(TEST_REPO_ID, 'closed', 2, 25, 'ambiguous selector')
|
||||
await runtime.listGitLabRepoWorkItems(TEST_REPO_ID, 'closed', 2, 25, 'ambiguous selector')
|
||||
const issues = await runtime.listGitLabRepoIssues(TEST_REPO_ID, 'opened', '@me', 50)
|
||||
await runtime.listGitLabRepoTodos(TEST_REPO_ID)
|
||||
await runtime.createGitLabRepoIssue(TEST_REPO_ID, 'New issue', 'Body')
|
||||
await runtime.updateGitLabRepoIssue(TEST_REPO_ID, 7, { state: 'closed' })
|
||||
@@ -7241,7 +7284,22 @@ describe('OrcaRuntimeService', () => {
|
||||
await runtime.updateGitLabRepoMRState(TEST_REPO_ID, 8, 'closed')
|
||||
await runtime.updateGitLabRepoMRState(TEST_REPO_ID, 8, 'opened')
|
||||
await runtime.getGitLabRepoWorkItemDetails(TEST_REPO_ID, 8, 'mr')
|
||||
await runtime.getGitLabRepoWorkItemByPath(
|
||||
TEST_REPO_ID,
|
||||
{ host: 'gitlab.example.com', path: 'group/project' },
|
||||
7,
|
||||
'issue'
|
||||
)
|
||||
|
||||
expect(listGitLabMergeRequestsMock).toHaveBeenCalledWith(
|
||||
'/remote/repo',
|
||||
'closed',
|
||||
2,
|
||||
25,
|
||||
'origin',
|
||||
'ambiguous selector',
|
||||
'ssh-1'
|
||||
)
|
||||
expect(listGitLabWorkItemsMock).toHaveBeenCalledWith(
|
||||
'/remote/repo',
|
||||
'closed',
|
||||
@@ -7251,6 +7309,28 @@ describe('OrcaRuntimeService', () => {
|
||||
'ambiguous selector',
|
||||
'ssh-1'
|
||||
)
|
||||
expect(listGitLabIssuesMock).toHaveBeenCalledWith(
|
||||
'/remote/repo',
|
||||
50,
|
||||
'origin',
|
||||
'opened',
|
||||
'@me',
|
||||
'ssh-1'
|
||||
)
|
||||
expect(issues.items).toEqual([
|
||||
{
|
||||
id: `gitlab-issue-${TEST_REPO_ID}-7`,
|
||||
type: 'issue',
|
||||
number: 7,
|
||||
title: 'Issue title',
|
||||
state: 'opened',
|
||||
url: 'https://gitlab.example/issues/7',
|
||||
labels: ['bug'],
|
||||
updatedAt: '2026-05-22T00:00:00Z',
|
||||
author: 'alex',
|
||||
repoId: TEST_REPO_ID
|
||||
}
|
||||
])
|
||||
expect(listGitLabTodosMock).toHaveBeenCalledWith('/remote/repo', 'ssh-1')
|
||||
expect(createGitLabIssueMock).toHaveBeenCalledWith(
|
||||
'/remote/repo',
|
||||
@@ -7301,6 +7381,104 @@ describe('OrcaRuntimeService', () => {
|
||||
'ssh-1',
|
||||
undefined
|
||||
)
|
||||
expect(getGitLabWorkItemByProjectRefMock).toHaveBeenCalledWith(
|
||||
'/remote/repo',
|
||||
{ host: 'gitlab.example.com', path: 'group/project' },
|
||||
7,
|
||||
'issue',
|
||||
'ssh-1'
|
||||
)
|
||||
})
|
||||
|
||||
it('normalizes runtime GitLab issue list arguments like the desktop IPC path', async () => {
|
||||
const runtime = new OrcaRuntimeService(store as never)
|
||||
|
||||
await runtime.listGitLabRepoIssues(TEST_REPO_ID, 'closed', 'someone-else' as never, 250.8)
|
||||
await runtime.listGitLabRepoIssues(TEST_REPO_ID, 'all', '@me', 0.7)
|
||||
await runtime.listGitLabRepoIssues(TEST_REPO_ID, 'unexpected' as never, '@me', Number.NaN)
|
||||
|
||||
expect(listGitLabIssuesMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
TEST_REPO_PATH,
|
||||
100,
|
||||
undefined,
|
||||
'closed',
|
||||
undefined,
|
||||
null
|
||||
)
|
||||
expect(listGitLabIssuesMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
TEST_REPO_PATH,
|
||||
1,
|
||||
undefined,
|
||||
'all',
|
||||
'@me',
|
||||
null
|
||||
)
|
||||
expect(listGitLabIssuesMock).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
TEST_REPO_PATH,
|
||||
20,
|
||||
undefined,
|
||||
'opened',
|
||||
'@me',
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
it('records GitLab pasted-project recents only after successful runtime lookup', async () => {
|
||||
let settings = {
|
||||
...store.getSettings(),
|
||||
gitlabProjects: {
|
||||
pinned: [{ host: 'gitlab.example.com', path: 'group/pinned' }],
|
||||
recent: []
|
||||
}
|
||||
}
|
||||
const updateSettings = vi.fn((updates: Record<string, unknown>) => {
|
||||
settings = { ...settings, ...updates } as typeof settings
|
||||
})
|
||||
const runtimeStore = {
|
||||
...store,
|
||||
getSettings: () => settings,
|
||||
updateSettings
|
||||
}
|
||||
const runtime = new OrcaRuntimeService(runtimeStore as never)
|
||||
|
||||
getGitLabWorkItemByProjectRefMock.mockResolvedValueOnce({
|
||||
id: 'gitlab-issue-7',
|
||||
type: 'issue',
|
||||
number: 7
|
||||
})
|
||||
await runtime.getGitLabRepoWorkItemByPath(
|
||||
TEST_REPO_ID,
|
||||
{ host: 'gitlab.example.com', path: 'group/project' },
|
||||
7,
|
||||
'issue'
|
||||
)
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({
|
||||
gitlabProjects: {
|
||||
pinned: [{ host: 'gitlab.example.com', path: 'group/pinned' }],
|
||||
recent: [
|
||||
expect.objectContaining({
|
||||
host: 'gitlab.example.com',
|
||||
path: 'group/project',
|
||||
lastOpenedAt: expect.any(String)
|
||||
})
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
updateSettings.mockClear()
|
||||
getGitLabWorkItemByProjectRefMock.mockResolvedValueOnce(null)
|
||||
await runtime.getGitLabRepoWorkItemByPath(
|
||||
TEST_REPO_ID,
|
||||
{ host: 'gitlab.example.com', path: 'group/missing' },
|
||||
404,
|
||||
'issue'
|
||||
)
|
||||
|
||||
expect(updateSettings).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('resolves local GitLab fork MR bases from the target project MR head ref', async () => {
|
||||
|
||||
@@ -134,6 +134,7 @@ import {
|
||||
getPRForBranch,
|
||||
getRepoSlug,
|
||||
getWorkItem,
|
||||
listIssues as listGitHubIssues,
|
||||
listWorkItems,
|
||||
countWorkItems,
|
||||
getPRChecks,
|
||||
@@ -169,6 +170,8 @@ import {
|
||||
addIssueComment as addGitLabIssueComment,
|
||||
addMRComment as addGitLabMRComment,
|
||||
listTodos as listGitLabTodos,
|
||||
listIssues as listGitLabIssues,
|
||||
listMergeRequests as listGitLabMergeRequests,
|
||||
listWorkItems as listGitLabWorkItems,
|
||||
mergeMR as mergeGitLabMR,
|
||||
reopenMR as reopenGitLabMR,
|
||||
@@ -177,6 +180,13 @@ import {
|
||||
} from '../gitlab/client'
|
||||
import { getGlabKnownHosts } from '../gitlab/gl-utils'
|
||||
import { getWorkItemDetails as getGitLabWorkItemDetails } from '../gitlab/work-item-details'
|
||||
import {
|
||||
normalizeGitLabIssueListArgs,
|
||||
normalizeGitLabMRListState,
|
||||
normalizeGitLabPositiveInteger,
|
||||
type GitLabIssueListState
|
||||
} from '../gitlab/gitlab-preload-args'
|
||||
import { recordGitLabProjectRecent } from '../gitlab/gitlab-project-recents'
|
||||
import type {
|
||||
GitHubIssueUpdate,
|
||||
GitHubPullRequestStateUpdate,
|
||||
@@ -184,6 +194,7 @@ import type {
|
||||
GitHubPRReviewCommentInput,
|
||||
GitLabIssueUpdate,
|
||||
GitLabProjectRef,
|
||||
GitLabWorkItem,
|
||||
MRListState
|
||||
} from '../../shared/types'
|
||||
import { inspectSetupScriptImportCandidates } from '../../shared/setup-script-imports'
|
||||
@@ -406,6 +417,7 @@ type RuntimeStore = {
|
||||
defaultRepoSelection?: GlobalSettings['defaultRepoSelection']
|
||||
defaultLinearTeamSelection?: GlobalSettings['defaultLinearTeamSelection']
|
||||
githubProjects?: GlobalSettings['githubProjects']
|
||||
gitlabProjects?: GlobalSettings['gitlabProjects']
|
||||
experimentalWorktreeSymlinks?: boolean
|
||||
mobileAutoRestoreFitMs?: number | null
|
||||
voice?: VoiceSettings
|
||||
@@ -5344,6 +5356,20 @@ export class OrcaRuntimeService {
|
||||
)
|
||||
}
|
||||
|
||||
async listRepoIssues(
|
||||
repoSelector: string,
|
||||
limit?: number
|
||||
): Promise<Awaited<ReturnType<typeof listGitHubIssues>>['items']> {
|
||||
const repo = await this.resolveRepoSelector(repoSelector)
|
||||
const result = await listGitHubIssues(
|
||||
repo.path,
|
||||
limit,
|
||||
repo.issueSourcePreference,
|
||||
repo.connectionId ?? null
|
||||
)
|
||||
return result.items
|
||||
}
|
||||
|
||||
async getRepoWorkItem(
|
||||
repoSelector: string,
|
||||
number: number,
|
||||
@@ -5515,6 +5541,61 @@ export class OrcaRuntimeService {
|
||||
)
|
||||
}
|
||||
|
||||
async listGitLabRepoMRs(
|
||||
repoSelector: string,
|
||||
state?: MRListState,
|
||||
page?: number,
|
||||
perPage?: number,
|
||||
query?: string
|
||||
): Promise<Awaited<ReturnType<typeof listGitLabMergeRequests>>> {
|
||||
const repo = await this.resolveRepoSelector(repoSelector)
|
||||
return listGitLabMergeRequests(
|
||||
repo.path,
|
||||
normalizeGitLabMRListState(state),
|
||||
normalizeGitLabPositiveInteger(page, 1, 10_000),
|
||||
normalizeGitLabPositiveInteger(perPage, 20, 100),
|
||||
repo.issueSourcePreference,
|
||||
query,
|
||||
repo.connectionId ?? null
|
||||
)
|
||||
}
|
||||
|
||||
async listGitLabRepoIssues(
|
||||
repoSelector: string,
|
||||
state?: GitLabIssueListState,
|
||||
assignee?: string,
|
||||
limit?: number
|
||||
): Promise<{
|
||||
items: GitLabWorkItem[]
|
||||
error?: Awaited<ReturnType<typeof listGitLabIssues>>['error']
|
||||
}> {
|
||||
const repo = await this.resolveRepoSelector(repoSelector)
|
||||
const normalized = normalizeGitLabIssueListArgs({ state, assignee, limit })
|
||||
const result = await listGitLabIssues(
|
||||
repo.path,
|
||||
normalized.limit,
|
||||
repo.issueSourcePreference,
|
||||
normalized.state,
|
||||
normalized.assignee,
|
||||
repo.connectionId ?? null
|
||||
)
|
||||
// Why: web runtime mirrors the desktop preload contract, where GitLab
|
||||
// issue rows share the GitLabWorkItem shape with MRs on TaskPage.
|
||||
const items: GitLabWorkItem[] = result.items.map((issue) => ({
|
||||
id: `gitlab-issue-${repo.id}-${issue.number}`,
|
||||
type: 'issue' as const,
|
||||
number: issue.number,
|
||||
title: issue.title,
|
||||
state: issue.state,
|
||||
url: issue.url,
|
||||
labels: issue.labels,
|
||||
updatedAt: issue.updatedAt ?? '',
|
||||
author: issue.author ?? null,
|
||||
repoId: repo.id
|
||||
}))
|
||||
return { items, ...(result.error ? { error: result.error } : {}) }
|
||||
}
|
||||
|
||||
async listGitLabRepoTodos(
|
||||
repoSelector: string
|
||||
): Promise<Awaited<ReturnType<typeof listGitLabTodos>>> {
|
||||
@@ -5663,6 +5744,36 @@ export class OrcaRuntimeService {
|
||||
)
|
||||
}
|
||||
|
||||
async getGitLabRepoWorkItemByPath(
|
||||
repoSelector: string,
|
||||
projectRef: GitLabProjectRef,
|
||||
iid: number,
|
||||
type: 'issue' | 'mr'
|
||||
): Promise<Awaited<ReturnType<typeof getGitLabWorkItemByProjectRef>>> {
|
||||
const repo = await this.resolveRepoSelector(repoSelector)
|
||||
const result = await getGitLabWorkItemByProjectRef(
|
||||
repo.path,
|
||||
projectRef,
|
||||
iid,
|
||||
type,
|
||||
repo.connectionId ?? null
|
||||
)
|
||||
// Why: remote pasted-URL lookups should update GitLab recents exactly
|
||||
// like the desktop IPC path, but only after a successful lookup.
|
||||
if (result && this.store?.updateSettings) {
|
||||
const store = this.store
|
||||
recordGitLabProjectRecent(
|
||||
{
|
||||
getSettings: () => store.getSettings(),
|
||||
updateSettings: (updates) => store.updateSettings?.(updates)
|
||||
},
|
||||
projectRef.host,
|
||||
projectRef.path
|
||||
)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
async getRepoIssue(
|
||||
repoSelector: string,
|
||||
number: number
|
||||
|
||||
@@ -54,6 +54,21 @@ describe('github RPC methods', () => {
|
||||
expect(response).toMatchObject({ ok: true, result: { items: [] } })
|
||||
})
|
||||
|
||||
it('lists issues on the runtime server', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
listRepoIssues: vi.fn().mockResolvedValue([{ number: 7, title: 'Bug' }])
|
||||
} as unknown as OrcaRuntimeService
|
||||
const dispatcher = new RpcDispatcher({ runtime, methods: GITHUB_METHODS })
|
||||
|
||||
const response = await dispatcher.dispatch(
|
||||
makeRequest('github.listIssues', { repo: 'repo-1', limit: 10 })
|
||||
)
|
||||
|
||||
expect(runtime.listRepoIssues).toHaveBeenCalledWith('repo-1', 10)
|
||||
expect(response).toMatchObject({ ok: true, result: [{ number: 7, title: 'Bug' }] })
|
||||
})
|
||||
|
||||
it('looks up a single work item on the runtime server', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
|
||||
@@ -13,6 +13,10 @@ const WorkItemsList = RepoSelector.extend({
|
||||
before: OptionalString
|
||||
})
|
||||
|
||||
const IssuesList = RepoSelector.extend({
|
||||
limit: OptionalFiniteNumber
|
||||
})
|
||||
|
||||
const WorkItem = RepoSelector.extend({
|
||||
number: z.number().int().positive(),
|
||||
type: z.enum(['issue', 'pr']).optional()
|
||||
@@ -281,6 +285,11 @@ export const GITHUB_METHODS: RpcMethod[] = [
|
||||
handler: async (params, { runtime }) =>
|
||||
runtime.listRepoWorkItems(params.repo, params.limit, params.query, params.before)
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'github.listIssues',
|
||||
params: IssuesList,
|
||||
handler: async (params, { runtime }) => runtime.listRepoIssues(params.repo, params.limit)
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'github.countWorkItems',
|
||||
params: WorkItemsCount,
|
||||
|
||||
@@ -12,7 +12,9 @@ describe('gitlab RPC methods', () => {
|
||||
it('routes GitLab task queries and mutations to the runtime server', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
listGitLabRepoMRs: vi.fn().mockResolvedValue({ items: [] }),
|
||||
listGitLabRepoWorkItems: vi.fn().mockResolvedValue({ items: [] }),
|
||||
listGitLabRepoIssues: vi.fn().mockResolvedValue({ items: [] }),
|
||||
listGitLabRepoTodos: vi.fn().mockResolvedValue([{ id: 1 }]),
|
||||
createGitLabRepoIssue: vi.fn().mockResolvedValue({ ok: true, number: 7 }),
|
||||
updateGitLabRepoIssue: vi.fn().mockResolvedValue({ ok: true }),
|
||||
@@ -21,11 +23,21 @@ describe('gitlab RPC methods', () => {
|
||||
mergeGitLabRepoMR: vi.fn().mockResolvedValue({ ok: true }),
|
||||
updateGitLabRepoMRState: vi.fn().mockResolvedValue({ ok: true }),
|
||||
updateGitLabRepoMR: vi.fn().mockResolvedValue({ ok: true }),
|
||||
getGitLabRepoWorkItemDetails: vi.fn().mockResolvedValue({ body: 'Details' })
|
||||
getGitLabRepoWorkItemDetails: vi.fn().mockResolvedValue({ body: 'Details' }),
|
||||
getGitLabRepoWorkItemByPath: vi.fn().mockResolvedValue({ id: 'gitlab-issue-7' })
|
||||
} as unknown as OrcaRuntimeService
|
||||
const dispatcher = new RpcDispatcher({ runtime, methods: GITLAB_METHODS })
|
||||
const projectRef = { host: 'gitlab.example.com', path: 'group/project' }
|
||||
|
||||
await dispatcher.dispatch(
|
||||
makeRequest('gitlab.listMRs', {
|
||||
repo: 'id:repo-1',
|
||||
state: 'opened',
|
||||
page: 1,
|
||||
perPage: 25,
|
||||
query: 'bug'
|
||||
})
|
||||
)
|
||||
await dispatcher.dispatch(
|
||||
makeRequest('gitlab.listWorkItems', {
|
||||
repo: 'id:repo-1',
|
||||
@@ -35,6 +47,14 @@ describe('gitlab RPC methods', () => {
|
||||
query: 'bug'
|
||||
})
|
||||
)
|
||||
await dispatcher.dispatch(
|
||||
makeRequest('gitlab.listIssues', {
|
||||
repo: 'id:repo-1',
|
||||
state: 'opened',
|
||||
assignee: '@me',
|
||||
limit: 50
|
||||
})
|
||||
)
|
||||
await dispatcher.dispatch(
|
||||
makeRequest('gitlab.createIssue', {
|
||||
repo: 'id:repo-1',
|
||||
@@ -99,7 +119,17 @@ describe('gitlab RPC methods', () => {
|
||||
projectRef
|
||||
})
|
||||
)
|
||||
await dispatcher.dispatch(
|
||||
makeRequest('gitlab.workItemByPath', {
|
||||
repo: 'id:repo-1',
|
||||
host: 'gitlab.example.com',
|
||||
path: 'group/project',
|
||||
iid: 7,
|
||||
type: 'issue'
|
||||
})
|
||||
)
|
||||
|
||||
expect(runtime.listGitLabRepoMRs).toHaveBeenCalledWith('id:repo-1', 'opened', 1, 25, 'bug')
|
||||
expect(runtime.listGitLabRepoWorkItems).toHaveBeenCalledWith(
|
||||
'id:repo-1',
|
||||
'opened',
|
||||
@@ -107,6 +137,7 @@ describe('gitlab RPC methods', () => {
|
||||
25,
|
||||
'bug'
|
||||
)
|
||||
expect(runtime.listGitLabRepoIssues).toHaveBeenCalledWith('id:repo-1', 'opened', '@me', 50)
|
||||
expect(runtime.createGitLabRepoIssue).toHaveBeenCalledWith('id:repo-1', 'Fix bug', 'Details')
|
||||
expect(runtime.listGitLabRepoTodos).toHaveBeenCalledWith('id:repo-1')
|
||||
expect(runtime.updateGitLabRepoIssue).toHaveBeenCalledWith(
|
||||
@@ -154,5 +185,45 @@ describe('gitlab RPC methods', () => {
|
||||
'mr',
|
||||
projectRef
|
||||
)
|
||||
expect(runtime.getGitLabRepoWorkItemByPath).toHaveBeenCalledWith(
|
||||
'id:repo-1',
|
||||
{ host: 'gitlab.example.com', path: 'group/project' },
|
||||
7,
|
||||
'issue'
|
||||
)
|
||||
})
|
||||
|
||||
it('normalizes GitLab issue list arguments to match desktop preload behavior', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
listGitLabRepoIssues: vi.fn().mockResolvedValue({ items: [] })
|
||||
} as unknown as OrcaRuntimeService
|
||||
const dispatcher = new RpcDispatcher({ runtime, methods: GITLAB_METHODS })
|
||||
|
||||
await dispatcher.dispatch(
|
||||
makeRequest('gitlab.listIssues', {
|
||||
repo: 'id:repo-1',
|
||||
state: 'closed',
|
||||
assignee: 'someone-else',
|
||||
limit: 250.8
|
||||
})
|
||||
)
|
||||
await dispatcher.dispatch(
|
||||
makeRequest('gitlab.listIssues', {
|
||||
repo: 'id:repo-1',
|
||||
state: 'unexpected',
|
||||
assignee: '@me',
|
||||
limit: -4
|
||||
})
|
||||
)
|
||||
|
||||
expect(runtime.listGitLabRepoIssues).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'id:repo-1',
|
||||
'closed',
|
||||
undefined,
|
||||
100
|
||||
)
|
||||
expect(runtime.listGitLabRepoIssues).toHaveBeenNthCalledWith(2, 'id:repo-1', 'opened', '@me', 1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { z } from 'zod'
|
||||
import { defineMethod, type RpcMethod } from '../core'
|
||||
import { OptionalFiniteNumber, OptionalString, requiredString } from '../schemas'
|
||||
import { normalizeGitLabIssueListArgs } from '../../../gitlab/gitlab-preload-args'
|
||||
|
||||
const RepoSelector = z.object({
|
||||
repo: requiredString('Missing repo selector')
|
||||
@@ -20,6 +21,12 @@ const WorkItemsList = RepoSelector.extend({
|
||||
query: OptionalString
|
||||
})
|
||||
|
||||
const IssuesList = RepoSelector.extend({
|
||||
state: z.unknown().optional(),
|
||||
assignee: OptionalString,
|
||||
limit: OptionalFiniteNumber
|
||||
})
|
||||
|
||||
const CreateIssue = RepoSelector.extend({
|
||||
title: requiredString('Missing title'),
|
||||
body: z.string()
|
||||
@@ -82,7 +89,26 @@ const WorkItemDetails = RepoSelector.extend({
|
||||
projectRef: GitLabProjectRef
|
||||
})
|
||||
|
||||
const WorkItemByPath = RepoSelector.extend({
|
||||
host: requiredString('Missing GitLab host'),
|
||||
path: requiredString('Missing GitLab project path'),
|
||||
iid: z.number().int().positive(),
|
||||
type: z.enum(['issue', 'mr'])
|
||||
})
|
||||
|
||||
export const GITLAB_METHODS: RpcMethod[] = [
|
||||
defineMethod({
|
||||
name: 'gitlab.listMRs',
|
||||
params: WorkItemsList,
|
||||
handler: async (params, { runtime }) =>
|
||||
runtime.listGitLabRepoMRs(
|
||||
params.repo,
|
||||
params.state,
|
||||
params.page,
|
||||
params.perPage,
|
||||
params.query
|
||||
)
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'gitlab.listWorkItems',
|
||||
params: WorkItemsList,
|
||||
@@ -95,6 +121,19 @@ export const GITLAB_METHODS: RpcMethod[] = [
|
||||
params.query
|
||||
)
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'gitlab.listIssues',
|
||||
params: IssuesList,
|
||||
handler: async (params, { runtime }) => {
|
||||
const normalized = normalizeGitLabIssueListArgs(params)
|
||||
return runtime.listGitLabRepoIssues(
|
||||
params.repo,
|
||||
normalized.state,
|
||||
normalized.assignee,
|
||||
normalized.limit
|
||||
)
|
||||
}
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'gitlab.todos',
|
||||
params: RepoSelector,
|
||||
@@ -147,5 +186,16 @@ export const GITLAB_METHODS: RpcMethod[] = [
|
||||
params: WorkItemDetails,
|
||||
handler: async (params, { runtime }) =>
|
||||
runtime.getGitLabRepoWorkItemDetails(params.repo, params.iid, params.type, params.projectRef)
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'gitlab.workItemByPath',
|
||||
params: WorkItemByPath,
|
||||
handler: async (params, { runtime }) =>
|
||||
runtime.getGitLabRepoWorkItemByPath(
|
||||
params.repo,
|
||||
{ host: params.host, path: params.path },
|
||||
params.iid,
|
||||
params.type
|
||||
)
|
||||
})
|
||||
]
|
||||
|
||||
@@ -276,17 +276,17 @@ export function RuntimePairingUrlGenerator({
|
||||
{showGeneratorForm ? (
|
||||
<>
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-3 sm:grid-cols-[minmax(0,220px)_minmax(0,1fr)]">
|
||||
<div className="grid gap-3 sm:grid-cols-[minmax(0,260px)_minmax(0,1fr)]">
|
||||
<div className="space-y-1">
|
||||
<Label id="runtime-pairing-address-label" htmlFor="runtime-pairing-address">
|
||||
Connection address
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<Select value={selectedAddress} onValueChange={updateSelectedAddress}>
|
||||
<SelectTrigger
|
||||
id="runtime-pairing-address"
|
||||
size="sm"
|
||||
className="min-w-[220px]"
|
||||
className="min-w-0 flex-1"
|
||||
aria-labelledby="runtime-pairing-address-label"
|
||||
>
|
||||
<SelectValue />
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* eslint-disable max-lines -- Why: web preload parity tests share module-reset
|
||||
global setup across namespaces so browser API installation stays realistic. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { PreloadApi } from '../../../preload/api-types'
|
||||
import type { RuntimeRpcResponse } from '../../../shared/runtime-rpc-envelope'
|
||||
|
||||
class MemoryStorage implements Storage {
|
||||
private readonly values = new Map<string, string>()
|
||||
@@ -65,6 +68,31 @@ async function installApi(userAgent?: string): Promise<{
|
||||
}
|
||||
}
|
||||
|
||||
function writeStoredRuntimeEnvironment(storage: Storage): void {
|
||||
storage.setItem(
|
||||
'orca.web.runtimeEnvironment.v1',
|
||||
JSON.stringify({
|
||||
id: 'web-env-1',
|
||||
name: 'Test runtime',
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
lastUsedAt: null,
|
||||
runtimeId: null,
|
||||
preferredEndpointId: 'ws-web-env-1',
|
||||
endpoints: [
|
||||
{
|
||||
id: 'ws-web-env-1',
|
||||
kind: 'websocket',
|
||||
label: 'WebSocket',
|
||||
endpoint: 'ws://127.0.0.1:1234',
|
||||
deviceToken: 'token',
|
||||
publicKeyB64: 'public-key'
|
||||
}
|
||||
]
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
describe('web keybindings preload API', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
@@ -141,3 +169,762 @@ describe('web keybindings preload API', () => {
|
||||
unsubscribe()
|
||||
})
|
||||
})
|
||||
|
||||
describe('web GitHub preload API', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
vi.doUnmock('./web-runtime-client')
|
||||
})
|
||||
|
||||
it('keeps the web GitHub preload key set in parity with the preload contract', async () => {
|
||||
const { api } = await installApi('Linux')
|
||||
|
||||
expect(Object.keys(api.gh).sort()).toEqual(
|
||||
[
|
||||
'addIssueComment',
|
||||
'addIssueCommentBySlug',
|
||||
'addPRReviewComment',
|
||||
'addPRReviewCommentReply',
|
||||
'checkOrcaStarred',
|
||||
'clearProjectItemField',
|
||||
'countWorkItems',
|
||||
'createIssue',
|
||||
'deleteIssueCommentBySlug',
|
||||
'diagnoseAuth',
|
||||
'enqueuePRRefresh',
|
||||
'getProjectViewTable',
|
||||
'issue',
|
||||
'listAccessibleProjects',
|
||||
'listAssignableUsers',
|
||||
'listAssignableUsersBySlug',
|
||||
'listIssueTypesBySlug',
|
||||
'listIssues',
|
||||
'listLabels',
|
||||
'listLabelsBySlug',
|
||||
'listProjectViews',
|
||||
'listWorkItems',
|
||||
'mergePR',
|
||||
'onPRRefreshEvent',
|
||||
'onWorkItemMutated',
|
||||
'prCheckDetails',
|
||||
'prChecks',
|
||||
'prComments',
|
||||
'prFileContents',
|
||||
'prForBranch',
|
||||
'projectWorkItemDetailsBySlug',
|
||||
'rateLimit',
|
||||
'refreshPRNow',
|
||||
'removePRReviewers',
|
||||
'repoSlug',
|
||||
'reportVisiblePRRefreshCandidates',
|
||||
'rerunPRChecks',
|
||||
'requestPRReviewers',
|
||||
'resolveProjectRef',
|
||||
'resolveReviewThread',
|
||||
'setPRFileViewed',
|
||||
'starOrca',
|
||||
'updateIssue',
|
||||
'updateIssueBySlug',
|
||||
'updateIssueCommentBySlug',
|
||||
'updateIssueTypeBySlug',
|
||||
'updatePRState',
|
||||
'updatePRTitle',
|
||||
'updateProjectItemField',
|
||||
'updatePullRequestBySlug',
|
||||
'viewer',
|
||||
'workItem',
|
||||
'workItemByOwnerRepo',
|
||||
'workItemDetails'
|
||||
].sort()
|
||||
)
|
||||
})
|
||||
|
||||
it('routes every runtime-backed GitHub method through the expected RPC method', async () => {
|
||||
type GitHubApi = NonNullable<PreloadApi['gh']>
|
||||
const runtimeCalls: { method: string; params: unknown }[] = []
|
||||
vi.doMock('./web-runtime-client', () => ({
|
||||
WebRuntimeClient: class {
|
||||
call(method: string, params?: unknown): Promise<RuntimeRpcResponse<unknown>> {
|
||||
runtimeCalls.push({ method, params })
|
||||
return Promise.resolve({
|
||||
id: `call-${runtimeCalls.length}`,
|
||||
ok: true,
|
||||
result: { ok: true, items: [], count: 0 },
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
})
|
||||
}
|
||||
|
||||
close(): void {}
|
||||
}
|
||||
}))
|
||||
|
||||
const globals = installBrowserGlobals('Linux')
|
||||
writeStoredRuntimeEnvironment(globals.storage)
|
||||
const { GITHUB_WEB_RPC_METHODS, installWebPreloadApi } = await import('./web-preload-api')
|
||||
installWebPreloadApi()
|
||||
const api = globals.window.api
|
||||
const repoPath = '/workspace/repo'
|
||||
const withRepo = (params: Record<string, unknown>): Record<string, unknown> => ({
|
||||
...params,
|
||||
repo: repoPath
|
||||
})
|
||||
|
||||
const routeCases: {
|
||||
key: keyof GitHubApi
|
||||
args?: unknown
|
||||
expectedMethod: string
|
||||
expectedParams: unknown
|
||||
}[] = [
|
||||
{
|
||||
key: 'repoSlug',
|
||||
args: { repoPath },
|
||||
expectedMethod: 'github.repoSlug',
|
||||
expectedParams: withRepo({ repoPath })
|
||||
},
|
||||
{
|
||||
key: 'prForBranch',
|
||||
args: { repoPath, branch: 'feature', linkedPRNumber: 3, fallbackPRNumber: null },
|
||||
expectedMethod: 'github.prForBranch',
|
||||
expectedParams: withRepo({
|
||||
repoPath,
|
||||
branch: 'feature',
|
||||
linkedPRNumber: 3,
|
||||
fallbackPRNumber: null
|
||||
})
|
||||
},
|
||||
{
|
||||
key: 'issue',
|
||||
args: { repoPath, number: 7 },
|
||||
expectedMethod: 'github.issue',
|
||||
expectedParams: withRepo({ repoPath, number: 7 })
|
||||
},
|
||||
{
|
||||
key: 'workItem',
|
||||
args: { repoPath, number: 7, type: 'issue' },
|
||||
expectedMethod: 'github.workItem',
|
||||
expectedParams: withRepo({ repoPath, number: 7, type: 'issue' })
|
||||
},
|
||||
{
|
||||
key: 'workItemByOwnerRepo',
|
||||
args: { repoPath, owner: 'acme', repo: 'orca', number: 7, type: 'pr' },
|
||||
expectedMethod: 'github.workItemByOwnerRepo',
|
||||
expectedParams: withRepo({
|
||||
repoPath,
|
||||
owner: 'acme',
|
||||
ownerRepo: 'orca',
|
||||
number: 7,
|
||||
type: 'pr'
|
||||
})
|
||||
},
|
||||
{
|
||||
key: 'workItemDetails',
|
||||
args: { repoPath, number: 7, type: 'issue' },
|
||||
expectedMethod: 'github.workItemDetails',
|
||||
expectedParams: withRepo({ repoPath, number: 7, type: 'issue' })
|
||||
},
|
||||
{
|
||||
key: 'prFileContents',
|
||||
args: {
|
||||
repoPath,
|
||||
prNumber: 7,
|
||||
path: 'src/app.ts',
|
||||
status: 'modified',
|
||||
headSha: 'head',
|
||||
baseSha: 'base'
|
||||
},
|
||||
expectedMethod: 'github.prFileContents',
|
||||
expectedParams: withRepo({
|
||||
repoPath,
|
||||
prNumber: 7,
|
||||
path: 'src/app.ts',
|
||||
status: 'modified',
|
||||
headSha: 'head',
|
||||
baseSha: 'base'
|
||||
})
|
||||
},
|
||||
{
|
||||
key: 'listIssues',
|
||||
args: { repoPath, limit: 10 },
|
||||
expectedMethod: 'github.listIssues',
|
||||
expectedParams: withRepo({ repoPath, limit: 10 })
|
||||
},
|
||||
{
|
||||
key: 'createIssue',
|
||||
args: { repoPath, title: 'Bug', body: 'Details' },
|
||||
expectedMethod: 'github.createIssue',
|
||||
expectedParams: withRepo({ repoPath, title: 'Bug', body: 'Details' })
|
||||
},
|
||||
{
|
||||
key: 'countWorkItems',
|
||||
args: { repoPath, query: 'is:open' },
|
||||
expectedMethod: 'github.countWorkItems',
|
||||
expectedParams: withRepo({ repoPath, query: 'is:open' })
|
||||
},
|
||||
{
|
||||
key: 'listWorkItems',
|
||||
args: { repoPath, limit: 20, query: 'is:pr', before: 'cursor' },
|
||||
expectedMethod: 'github.listWorkItems',
|
||||
expectedParams: withRepo({ repoPath, limit: 20, query: 'is:pr', before: 'cursor' })
|
||||
},
|
||||
{
|
||||
key: 'prChecks',
|
||||
args: { repoPath, prNumber: 7, headSha: 'head', noCache: true },
|
||||
expectedMethod: 'github.prChecks',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, headSha: 'head', noCache: true })
|
||||
},
|
||||
{
|
||||
key: 'prCheckDetails',
|
||||
args: { repoPath, checkRunId: 1, checkName: 'test' },
|
||||
expectedMethod: 'github.prCheckDetails',
|
||||
expectedParams: withRepo({ repoPath, checkRunId: 1, checkName: 'test' })
|
||||
},
|
||||
{
|
||||
key: 'rerunPRChecks',
|
||||
args: { repoPath, prNumber: 7, failedOnly: true },
|
||||
expectedMethod: 'github.rerunPRChecks',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, failedOnly: true })
|
||||
},
|
||||
{
|
||||
key: 'prComments',
|
||||
args: { repoPath, prNumber: 7, noCache: true },
|
||||
expectedMethod: 'github.prComments',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, noCache: true })
|
||||
},
|
||||
{
|
||||
key: 'resolveReviewThread',
|
||||
args: { repoPath, threadId: 'thread-1', resolve: true },
|
||||
expectedMethod: 'github.resolveReviewThread',
|
||||
expectedParams: withRepo({ repoPath, threadId: 'thread-1', resolve: true })
|
||||
},
|
||||
{
|
||||
key: 'setPRFileViewed',
|
||||
args: { repoPath, prNumber: 7, pullRequestId: 'PR_kw', path: 'src/app.ts', viewed: true },
|
||||
expectedMethod: 'github.setPRFileViewed',
|
||||
expectedParams: withRepo({
|
||||
repoPath,
|
||||
prNumber: 7,
|
||||
pullRequestId: 'PR_kw',
|
||||
path: 'src/app.ts',
|
||||
viewed: true
|
||||
})
|
||||
},
|
||||
{
|
||||
key: 'updatePRTitle',
|
||||
args: { repoPath, prNumber: 7, title: 'New title' },
|
||||
expectedMethod: 'github.updatePRTitle',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, title: 'New title' })
|
||||
},
|
||||
{
|
||||
key: 'mergePR',
|
||||
args: { repoPath, prNumber: 7, method: 'squash' },
|
||||
expectedMethod: 'github.mergePR',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, method: 'squash' })
|
||||
},
|
||||
{
|
||||
key: 'updatePRState',
|
||||
args: { repoPath, prNumber: 7, updates: { state: 'closed' } },
|
||||
expectedMethod: 'github.updatePRState',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, updates: { state: 'closed' } })
|
||||
},
|
||||
{
|
||||
key: 'requestPRReviewers',
|
||||
args: { repoPath, prNumber: 7, reviewers: ['alice'] },
|
||||
expectedMethod: 'github.requestPRReviewers',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, reviewers: ['alice'] })
|
||||
},
|
||||
{
|
||||
key: 'removePRReviewers',
|
||||
args: { repoPath, prNumber: 7, reviewers: ['alice'] },
|
||||
expectedMethod: 'github.removePRReviewers',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, reviewers: ['alice'] })
|
||||
},
|
||||
{
|
||||
key: 'updateIssue',
|
||||
args: { repoPath, number: 7, updates: { state: 'closed' } },
|
||||
expectedMethod: 'github.updateIssue',
|
||||
expectedParams: withRepo({ repoPath, number: 7, updates: { state: 'closed' } })
|
||||
},
|
||||
{
|
||||
key: 'addIssueComment',
|
||||
args: { repoPath, number: 7, body: 'Fixed', type: 'issue' },
|
||||
expectedMethod: 'github.addIssueComment',
|
||||
expectedParams: withRepo({ repoPath, number: 7, body: 'Fixed', type: 'issue' })
|
||||
},
|
||||
{
|
||||
key: 'addPRReviewCommentReply',
|
||||
args: { repoPath, prNumber: 7, commentId: 9, body: 'Reply' },
|
||||
expectedMethod: 'github.addPRReviewCommentReply',
|
||||
expectedParams: withRepo({ repoPath, prNumber: 7, commentId: 9, body: 'Reply' })
|
||||
},
|
||||
{
|
||||
key: 'addPRReviewComment',
|
||||
args: {
|
||||
repoPath,
|
||||
prNumber: 7,
|
||||
commitId: 'head',
|
||||
path: 'src/app.ts',
|
||||
line: 12,
|
||||
body: 'Fix'
|
||||
},
|
||||
expectedMethod: 'github.addPRReviewComment',
|
||||
expectedParams: withRepo({
|
||||
repoPath,
|
||||
prNumber: 7,
|
||||
commitId: 'head',
|
||||
path: 'src/app.ts',
|
||||
line: 12,
|
||||
body: 'Fix'
|
||||
})
|
||||
},
|
||||
{
|
||||
key: 'listLabels',
|
||||
args: { repoPath },
|
||||
expectedMethod: 'github.listLabels',
|
||||
expectedParams: withRepo({ repoPath })
|
||||
},
|
||||
{
|
||||
key: 'listAssignableUsers',
|
||||
args: { repoPath },
|
||||
expectedMethod: 'github.listAssignableUsers',
|
||||
expectedParams: withRepo({ repoPath })
|
||||
},
|
||||
{
|
||||
key: 'rateLimit',
|
||||
args: { force: true },
|
||||
expectedMethod: 'github.rateLimit',
|
||||
expectedParams: { force: true }
|
||||
},
|
||||
{
|
||||
key: 'listAccessibleProjects',
|
||||
expectedMethod: 'github.project.listAccessible',
|
||||
expectedParams: undefined
|
||||
},
|
||||
{
|
||||
key: 'resolveProjectRef',
|
||||
args: { input: 'acme/1' },
|
||||
expectedMethod: 'github.project.resolveRef',
|
||||
expectedParams: { input: 'acme/1' }
|
||||
},
|
||||
{
|
||||
key: 'listProjectViews',
|
||||
args: { owner: 'acme', ownerType: 'organization', projectNumber: 1 },
|
||||
expectedMethod: 'github.project.listViews',
|
||||
expectedParams: { owner: 'acme', ownerType: 'organization', projectNumber: 1 }
|
||||
},
|
||||
{
|
||||
key: 'getProjectViewTable',
|
||||
args: { owner: 'acme', ownerType: 'organization', projectNumber: 1 },
|
||||
expectedMethod: 'github.project.viewTable',
|
||||
expectedParams: { owner: 'acme', ownerType: 'organization', projectNumber: 1 }
|
||||
},
|
||||
{
|
||||
key: 'projectWorkItemDetailsBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', number: 7, type: 'issue' },
|
||||
expectedMethod: 'github.project.workItemDetailsBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', number: 7, type: 'issue' }
|
||||
},
|
||||
{
|
||||
key: 'updateProjectItemField',
|
||||
args: { projectId: 'PVT', itemId: 'PVTI', fieldId: 'field', value: 'done' },
|
||||
expectedMethod: 'github.project.updateItemField',
|
||||
expectedParams: { projectId: 'PVT', itemId: 'PVTI', fieldId: 'field', value: 'done' }
|
||||
},
|
||||
{
|
||||
key: 'clearProjectItemField',
|
||||
args: { projectId: 'PVT', itemId: 'PVTI', fieldId: 'field' },
|
||||
expectedMethod: 'github.project.clearItemField',
|
||||
expectedParams: { projectId: 'PVT', itemId: 'PVTI', fieldId: 'field' }
|
||||
},
|
||||
{
|
||||
key: 'updateIssueBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', number: 7, updates: { title: 'New' } },
|
||||
expectedMethod: 'github.project.updateIssueBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', number: 7, updates: { title: 'New' } }
|
||||
},
|
||||
{
|
||||
key: 'updatePullRequestBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', number: 7, updates: { title: 'New' } },
|
||||
expectedMethod: 'github.project.updatePullRequestBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', number: 7, updates: { title: 'New' } }
|
||||
},
|
||||
{
|
||||
key: 'addIssueCommentBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', number: 7, body: 'Fixed' },
|
||||
expectedMethod: 'github.project.addIssueCommentBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', number: 7, body: 'Fixed' }
|
||||
},
|
||||
{
|
||||
key: 'updateIssueCommentBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', commentId: 9, body: 'Edited' },
|
||||
expectedMethod: 'github.project.updateIssueCommentBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', commentId: 9, body: 'Edited' }
|
||||
},
|
||||
{
|
||||
key: 'deleteIssueCommentBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', commentId: 9 },
|
||||
expectedMethod: 'github.project.deleteIssueCommentBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', commentId: 9 }
|
||||
},
|
||||
{
|
||||
key: 'listLabelsBySlug',
|
||||
args: { owner: 'acme', repo: 'orca' },
|
||||
expectedMethod: 'github.project.listLabelsBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca' }
|
||||
},
|
||||
{
|
||||
key: 'listAssignableUsersBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', seedLogins: ['alice'] },
|
||||
expectedMethod: 'github.project.listAssignableUsersBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', seedLogins: ['alice'] }
|
||||
},
|
||||
{
|
||||
key: 'listIssueTypesBySlug',
|
||||
args: { owner: 'acme', repo: 'orca' },
|
||||
expectedMethod: 'github.project.listIssueTypesBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca' }
|
||||
},
|
||||
{
|
||||
key: 'updateIssueTypeBySlug',
|
||||
args: { owner: 'acme', repo: 'orca', number: 7, issueTypeId: 'it-1' },
|
||||
expectedMethod: 'github.project.updateIssueTypeBySlug',
|
||||
expectedParams: { owner: 'acme', repo: 'orca', number: 7, issueTypeId: 'it-1' }
|
||||
}
|
||||
]
|
||||
|
||||
expect(routeCases.map((routeCase) => routeCase.key).sort()).toEqual(
|
||||
Object.keys(GITHUB_WEB_RPC_METHODS).sort()
|
||||
)
|
||||
|
||||
for (const routeCase of routeCases) {
|
||||
const method = api.gh[routeCase.key] as (args?: unknown) => Promise<unknown>
|
||||
await method(routeCase.args)
|
||||
}
|
||||
|
||||
await api.gh.refreshPRNow({
|
||||
candidate: {
|
||||
cacheKey: 'repo-1:feature',
|
||||
repoKind: 'git',
|
||||
repoId: 'repo-1',
|
||||
repoPath,
|
||||
branch: 'feature',
|
||||
linkedPRNumber: null,
|
||||
fallbackPRNumber: 9,
|
||||
fallbackPRSource: 'pr-cache'
|
||||
}
|
||||
})
|
||||
|
||||
expect(runtimeCalls).toEqual([
|
||||
...routeCases.map((routeCase) => ({
|
||||
method: routeCase.expectedMethod,
|
||||
params: routeCase.expectedParams
|
||||
})),
|
||||
{
|
||||
method: 'github.prForBranch',
|
||||
params: {
|
||||
repoPath,
|
||||
repoId: 'repo-1',
|
||||
repo: 'id:repo-1',
|
||||
branch: 'feature',
|
||||
linkedPRNumber: null,
|
||||
fallbackPRNumber: 9
|
||||
}
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('web GitLab preload API', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
vi.doUnmock('./web-runtime-client')
|
||||
vi.doUnmock('electron')
|
||||
})
|
||||
|
||||
it('keeps the web GitLab preload key set in parity with desktop preload', async () => {
|
||||
vi.doMock('electron', () => ({
|
||||
ipcRenderer: { invoke: vi.fn() }
|
||||
}))
|
||||
const globals = installBrowserGlobals('Linux')
|
||||
const { glApi } = (await import(
|
||||
new URL('../../../preload/gitlab.ts', import.meta.url).href
|
||||
)) as {
|
||||
glApi: Record<string, unknown>
|
||||
}
|
||||
const { installWebPreloadApi } = await import('./web-preload-api')
|
||||
|
||||
installWebPreloadApi()
|
||||
|
||||
expect(Object.keys(globals.window.api.gl).sort()).toEqual(Object.keys(glApi).sort())
|
||||
})
|
||||
|
||||
it('routes every runtime-backed GitLab method through the expected RPC method', async () => {
|
||||
type GitLabApi = NonNullable<PreloadApi['gl']>
|
||||
const runtimeCalls: { method: string; params: unknown }[] = []
|
||||
vi.doMock('./web-runtime-client', () => ({
|
||||
WebRuntimeClient: class {
|
||||
call(method: string, params?: unknown): Promise<RuntimeRpcResponse<unknown>> {
|
||||
runtimeCalls.push({ method, params })
|
||||
return Promise.resolve({
|
||||
id: `call-${runtimeCalls.length}`,
|
||||
ok: true,
|
||||
result: { ok: true, items: [] },
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
})
|
||||
}
|
||||
|
||||
close(): void {}
|
||||
}
|
||||
}))
|
||||
|
||||
const globals = installBrowserGlobals('Linux')
|
||||
writeStoredRuntimeEnvironment(globals.storage)
|
||||
const { GITLAB_WEB_RPC_METHODS, installWebPreloadApi } = await import('./web-preload-api')
|
||||
installWebPreloadApi()
|
||||
const api = globals.window.api
|
||||
const repoPath = '/workspace/repo'
|
||||
|
||||
const routeCases: {
|
||||
key: keyof typeof GITLAB_WEB_RPC_METHODS
|
||||
invoke: (gl: GitLabApi) => Promise<unknown>
|
||||
expectedMethod: string
|
||||
expectedParams: unknown
|
||||
}[] = [
|
||||
{
|
||||
key: 'listMRs',
|
||||
invoke: (gl) => gl.listMRs({ repoPath, state: 'opened', page: 1, perPage: 50 }),
|
||||
expectedMethod: 'gitlab.listMRs',
|
||||
expectedParams: { repoPath, repo: repoPath, state: 'opened', page: 1, perPage: 50 }
|
||||
},
|
||||
{
|
||||
key: 'listWorkItems',
|
||||
invoke: (gl) => gl.listWorkItems({ repoPath, state: 'closed', page: 2, perPage: 25 }),
|
||||
expectedMethod: 'gitlab.listWorkItems',
|
||||
expectedParams: { repoPath, repo: repoPath, state: 'closed', page: 2, perPage: 25 }
|
||||
},
|
||||
{
|
||||
key: 'listIssues',
|
||||
invoke: (gl) => gl.listIssues({ repoPath, state: 'all', assignee: '@me', limit: 30 }),
|
||||
expectedMethod: 'gitlab.listIssues',
|
||||
expectedParams: { repoPath, repo: repoPath, state: 'all', assignee: '@me', limit: 30 }
|
||||
},
|
||||
{
|
||||
key: 'createIssue',
|
||||
invoke: (gl) => gl.createIssue({ repoPath, title: 'Bug', body: 'Details' }),
|
||||
expectedMethod: 'gitlab.createIssue',
|
||||
expectedParams: { repoPath, repo: repoPath, title: 'Bug', body: 'Details' }
|
||||
},
|
||||
{
|
||||
key: 'updateIssue',
|
||||
invoke: (gl) => gl.updateIssue({ repoPath, number: 7, updates: { state: 'closed' } }),
|
||||
expectedMethod: 'gitlab.updateIssue',
|
||||
expectedParams: { repoPath, repo: repoPath, number: 7, updates: { state: 'closed' } }
|
||||
},
|
||||
{
|
||||
key: 'addIssueComment',
|
||||
invoke: (gl) => gl.addIssueComment({ repoPath, number: 7, body: 'Fixed' }),
|
||||
expectedMethod: 'gitlab.addIssueComment',
|
||||
expectedParams: { repoPath, repo: repoPath, number: 7, body: 'Fixed' }
|
||||
},
|
||||
{
|
||||
key: 'todos',
|
||||
invoke: (gl) => gl.todos({ repoPath }),
|
||||
expectedMethod: 'gitlab.todos',
|
||||
expectedParams: { repoPath, repo: repoPath }
|
||||
},
|
||||
{
|
||||
key: 'workItemDetails',
|
||||
invoke: (gl) => gl.workItemDetails({ repoPath, iid: 8, type: 'mr' }),
|
||||
expectedMethod: 'gitlab.workItemDetails',
|
||||
expectedParams: { repoPath, repo: repoPath, iid: 8, type: 'mr' }
|
||||
},
|
||||
{
|
||||
key: 'closeMR',
|
||||
invoke: (gl) => gl.closeMR({ repoPath, iid: 8 }),
|
||||
expectedMethod: 'gitlab.updateMRState',
|
||||
expectedParams: { repoPath, repo: repoPath, iid: 8, state: 'closed' }
|
||||
},
|
||||
{
|
||||
key: 'reopenMR',
|
||||
invoke: (gl) => gl.reopenMR({ repoPath, iid: 8 }),
|
||||
expectedMethod: 'gitlab.updateMRState',
|
||||
expectedParams: { repoPath, repo: repoPath, iid: 8, state: 'opened' }
|
||||
},
|
||||
{
|
||||
key: 'mergeMR',
|
||||
invoke: (gl) => gl.mergeMR({ repoPath, iid: 8, method: 'squash' }),
|
||||
expectedMethod: 'gitlab.mergeMR',
|
||||
expectedParams: { repoPath, repo: repoPath, iid: 8, method: 'squash' }
|
||||
},
|
||||
{
|
||||
key: 'addMRComment',
|
||||
invoke: (gl) => gl.addMRComment({ repoPath, iid: 8, body: 'Ship it' }),
|
||||
expectedMethod: 'gitlab.addMRComment',
|
||||
expectedParams: { repoPath, repo: repoPath, iid: 8, body: 'Ship it' }
|
||||
},
|
||||
{
|
||||
key: 'workItemByPath',
|
||||
invoke: (gl) =>
|
||||
gl.workItemByPath({
|
||||
repoPath,
|
||||
host: 'gitlab.example.com',
|
||||
path: 'group/project',
|
||||
iid: 7,
|
||||
type: 'issue'
|
||||
}),
|
||||
expectedMethod: 'gitlab.workItemByPath',
|
||||
expectedParams: {
|
||||
repoPath,
|
||||
repo: repoPath,
|
||||
host: 'gitlab.example.com',
|
||||
path: 'group/project',
|
||||
iid: 7,
|
||||
type: 'issue'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
expect(routeCases.map((routeCase) => routeCase.key).sort()).toEqual(
|
||||
Object.keys(GITLAB_WEB_RPC_METHODS).sort()
|
||||
)
|
||||
|
||||
for (const routeCase of routeCases) {
|
||||
await routeCase.invoke(api.gl)
|
||||
}
|
||||
|
||||
expect(runtimeCalls).toEqual(
|
||||
routeCases.map((routeCase) => ({
|
||||
method: routeCase.expectedMethod,
|
||||
params: routeCase.expectedParams
|
||||
}))
|
||||
)
|
||||
})
|
||||
|
||||
it('exposes the GitLab task methods used by the shared Tasks page', async () => {
|
||||
const runtimeCalls: { method: string; params: unknown }[] = []
|
||||
vi.doMock('./web-runtime-client', () => ({
|
||||
WebRuntimeClient: class {
|
||||
call(method: string, params?: unknown): Promise<RuntimeRpcResponse<unknown>> {
|
||||
runtimeCalls.push({ method, params })
|
||||
if (method === 'gitlab.listMRs') {
|
||||
return Promise.resolve({
|
||||
id: `call-${runtimeCalls.length}`,
|
||||
ok: true,
|
||||
result: {
|
||||
items: [{ id: 'mr-1', type: 'mr', number: 1 }]
|
||||
},
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
})
|
||||
}
|
||||
if (method === 'gitlab.listIssues') {
|
||||
return Promise.resolve({
|
||||
id: `call-${runtimeCalls.length}`,
|
||||
ok: true,
|
||||
result: {
|
||||
items: [{ id: 'issue-2', type: 'issue', number: 2 }]
|
||||
},
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
})
|
||||
}
|
||||
if (method === 'gitlab.workItemByPath') {
|
||||
return Promise.resolve({
|
||||
id: `call-${runtimeCalls.length}`,
|
||||
ok: true,
|
||||
result: { id: 'issue-7', type: 'issue', number: 7 },
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
})
|
||||
}
|
||||
return Promise.resolve({
|
||||
id: `call-${runtimeCalls.length}`,
|
||||
ok: true,
|
||||
result: { ok: true },
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
})
|
||||
}
|
||||
|
||||
close(): void {}
|
||||
}
|
||||
}))
|
||||
|
||||
const globals = installBrowserGlobals('Linux')
|
||||
writeStoredRuntimeEnvironment(globals.storage)
|
||||
const { installWebPreloadApi } = await import('./web-preload-api')
|
||||
installWebPreloadApi()
|
||||
const api = globals.window.api
|
||||
|
||||
const mergeRequests = await api.gl.listMRs({
|
||||
repoPath: '/workspace/repo',
|
||||
state: 'opened',
|
||||
page: 1,
|
||||
perPage: 50
|
||||
})
|
||||
const issues = await api.gl.listIssues({
|
||||
repoPath: '/workspace/repo',
|
||||
state: 'opened',
|
||||
assignee: '@me',
|
||||
limit: 50
|
||||
})
|
||||
const item = await api.gl.workItemByPath({
|
||||
repoPath: '/workspace/repo',
|
||||
host: 'gitlab.example.com',
|
||||
path: 'group/project',
|
||||
iid: 7,
|
||||
type: 'issue'
|
||||
})
|
||||
await api.gl.closeMR({ repoPath: '/workspace/repo', iid: 7 })
|
||||
|
||||
expect(mergeRequests.items).toEqual([{ id: 'mr-1', type: 'mr', number: 1 }])
|
||||
expect(issues.items).toEqual([{ id: 'issue-2', type: 'issue', number: 2 }])
|
||||
expect(item).toEqual({ id: 'issue-7', type: 'issue', number: 7 })
|
||||
expect(runtimeCalls.map((call) => call.method)).not.toContain('gitlab.listWorkItems')
|
||||
expect(runtimeCalls).toEqual([
|
||||
{
|
||||
method: 'gitlab.listMRs',
|
||||
params: {
|
||||
repoPath: '/workspace/repo',
|
||||
repo: '/workspace/repo',
|
||||
state: 'opened',
|
||||
page: 1,
|
||||
perPage: 50
|
||||
}
|
||||
},
|
||||
{
|
||||
method: 'gitlab.listIssues',
|
||||
params: {
|
||||
repoPath: '/workspace/repo',
|
||||
repo: '/workspace/repo',
|
||||
state: 'opened',
|
||||
assignee: '@me',
|
||||
limit: 50
|
||||
}
|
||||
},
|
||||
{
|
||||
method: 'gitlab.workItemByPath',
|
||||
params: {
|
||||
repoPath: '/workspace/repo',
|
||||
repo: '/workspace/repo',
|
||||
host: 'gitlab.example.com',
|
||||
path: 'group/project',
|
||||
iid: 7,
|
||||
type: 'issue'
|
||||
}
|
||||
},
|
||||
{
|
||||
method: 'gitlab.updateMRState',
|
||||
params: {
|
||||
repoPath: '/workspace/repo',
|
||||
repo: '/workspace/repo',
|
||||
iid: 7,
|
||||
state: 'closed'
|
||||
}
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -72,12 +72,199 @@ const runtimeCallQueuePool = new RuntimeRpcCallQueuePool()
|
||||
|
||||
type WebSettingsApi = NonNullable<PreloadApi['settings']>
|
||||
type WebKeybindingsApi = NonNullable<PreloadApi['keybindings']>
|
||||
type WebGitHubApi = NonNullable<PreloadApi['gh']>
|
||||
type WebGitHubResult<K extends keyof WebGitHubApi> = Awaited<ReturnType<WebGitHubApi[K]>>
|
||||
type WebGitHubRouteKey =
|
||||
| 'repoSlug'
|
||||
| 'prForBranch'
|
||||
| 'issue'
|
||||
| 'workItem'
|
||||
| 'workItemByOwnerRepo'
|
||||
| 'workItemDetails'
|
||||
| 'prFileContents'
|
||||
| 'listIssues'
|
||||
| 'createIssue'
|
||||
| 'countWorkItems'
|
||||
| 'listWorkItems'
|
||||
| 'prChecks'
|
||||
| 'prCheckDetails'
|
||||
| 'rerunPRChecks'
|
||||
| 'prComments'
|
||||
| 'resolveReviewThread'
|
||||
| 'setPRFileViewed'
|
||||
| 'updatePRTitle'
|
||||
| 'mergePR'
|
||||
| 'updatePRState'
|
||||
| 'requestPRReviewers'
|
||||
| 'removePRReviewers'
|
||||
| 'updateIssue'
|
||||
| 'addIssueComment'
|
||||
| 'addPRReviewCommentReply'
|
||||
| 'addPRReviewComment'
|
||||
| 'listLabels'
|
||||
| 'listAssignableUsers'
|
||||
| 'rateLimit'
|
||||
| 'listAccessibleProjects'
|
||||
| 'resolveProjectRef'
|
||||
| 'listProjectViews'
|
||||
| 'getProjectViewTable'
|
||||
| 'projectWorkItemDetailsBySlug'
|
||||
| 'updateProjectItemField'
|
||||
| 'clearProjectItemField'
|
||||
| 'updateIssueBySlug'
|
||||
| 'updatePullRequestBySlug'
|
||||
| 'addIssueCommentBySlug'
|
||||
| 'updateIssueCommentBySlug'
|
||||
| 'deleteIssueCommentBySlug'
|
||||
| 'listLabelsBySlug'
|
||||
| 'listAssignableUsersBySlug'
|
||||
| 'listIssueTypesBySlug'
|
||||
| 'updateIssueTypeBySlug'
|
||||
type WebGitHubRuntimeMethod =
|
||||
| 'github.repoSlug'
|
||||
| 'github.prForBranch'
|
||||
| 'github.issue'
|
||||
| 'github.workItem'
|
||||
| 'github.workItemByOwnerRepo'
|
||||
| 'github.workItemDetails'
|
||||
| 'github.prFileContents'
|
||||
| 'github.listIssues'
|
||||
| 'github.createIssue'
|
||||
| 'github.countWorkItems'
|
||||
| 'github.listWorkItems'
|
||||
| 'github.prChecks'
|
||||
| 'github.prCheckDetails'
|
||||
| 'github.rerunPRChecks'
|
||||
| 'github.prComments'
|
||||
| 'github.resolveReviewThread'
|
||||
| 'github.setPRFileViewed'
|
||||
| 'github.updatePRTitle'
|
||||
| 'github.mergePR'
|
||||
| 'github.updatePRState'
|
||||
| 'github.requestPRReviewers'
|
||||
| 'github.removePRReviewers'
|
||||
| 'github.updateIssue'
|
||||
| 'github.addIssueComment'
|
||||
| 'github.addPRReviewCommentReply'
|
||||
| 'github.addPRReviewComment'
|
||||
| 'github.listLabels'
|
||||
| 'github.listAssignableUsers'
|
||||
| 'github.rateLimit'
|
||||
| 'github.project.listAccessible'
|
||||
| 'github.project.resolveRef'
|
||||
| 'github.project.listViews'
|
||||
| 'github.project.viewTable'
|
||||
| 'github.project.workItemDetailsBySlug'
|
||||
| 'github.project.updateItemField'
|
||||
| 'github.project.clearItemField'
|
||||
| 'github.project.updateIssueBySlug'
|
||||
| 'github.project.updatePullRequestBySlug'
|
||||
| 'github.project.addIssueCommentBySlug'
|
||||
| 'github.project.updateIssueCommentBySlug'
|
||||
| 'github.project.deleteIssueCommentBySlug'
|
||||
| 'github.project.listLabelsBySlug'
|
||||
| 'github.project.listAssignableUsersBySlug'
|
||||
| 'github.project.listIssueTypesBySlug'
|
||||
| 'github.project.updateIssueTypeBySlug'
|
||||
type WebGitLabApi = NonNullable<PreloadApi['gl']>
|
||||
type WebGitLabResult<K extends keyof WebGitLabApi> = Awaited<ReturnType<WebGitLabApi[K]>>
|
||||
type WebGitLabRouteKey =
|
||||
| 'listMRs'
|
||||
| 'listWorkItems'
|
||||
| 'listIssues'
|
||||
| 'createIssue'
|
||||
| 'updateIssue'
|
||||
| 'addIssueComment'
|
||||
| 'todos'
|
||||
| 'workItemDetails'
|
||||
| 'closeMR'
|
||||
| 'reopenMR'
|
||||
| 'mergeMR'
|
||||
| 'addMRComment'
|
||||
| 'workItemByPath'
|
||||
type WebGitLabRuntimeMethod =
|
||||
| 'gitlab.listMRs'
|
||||
| 'gitlab.listWorkItems'
|
||||
| 'gitlab.listIssues'
|
||||
| 'gitlab.createIssue'
|
||||
| 'gitlab.updateIssue'
|
||||
| 'gitlab.addIssueComment'
|
||||
| 'gitlab.todos'
|
||||
| 'gitlab.workItemDetails'
|
||||
| 'gitlab.updateMRState'
|
||||
| 'gitlab.mergeMR'
|
||||
| 'gitlab.addMRComment'
|
||||
| 'gitlab.workItemByPath'
|
||||
type WebKeybindingDocument = {
|
||||
version: 1
|
||||
keybindings: KeybindingOverrides
|
||||
platforms: Partial<Record<KeybindingPlatform, KeybindingOverrides>>
|
||||
}
|
||||
|
||||
export const GITHUB_WEB_RPC_METHODS = {
|
||||
repoSlug: 'github.repoSlug',
|
||||
prForBranch: 'github.prForBranch',
|
||||
issue: 'github.issue',
|
||||
workItem: 'github.workItem',
|
||||
workItemByOwnerRepo: 'github.workItemByOwnerRepo',
|
||||
workItemDetails: 'github.workItemDetails',
|
||||
prFileContents: 'github.prFileContents',
|
||||
listIssues: 'github.listIssues',
|
||||
createIssue: 'github.createIssue',
|
||||
countWorkItems: 'github.countWorkItems',
|
||||
listWorkItems: 'github.listWorkItems',
|
||||
prChecks: 'github.prChecks',
|
||||
prCheckDetails: 'github.prCheckDetails',
|
||||
rerunPRChecks: 'github.rerunPRChecks',
|
||||
prComments: 'github.prComments',
|
||||
resolveReviewThread: 'github.resolveReviewThread',
|
||||
setPRFileViewed: 'github.setPRFileViewed',
|
||||
updatePRTitle: 'github.updatePRTitle',
|
||||
mergePR: 'github.mergePR',
|
||||
updatePRState: 'github.updatePRState',
|
||||
requestPRReviewers: 'github.requestPRReviewers',
|
||||
removePRReviewers: 'github.removePRReviewers',
|
||||
updateIssue: 'github.updateIssue',
|
||||
addIssueComment: 'github.addIssueComment',
|
||||
addPRReviewCommentReply: 'github.addPRReviewCommentReply',
|
||||
addPRReviewComment: 'github.addPRReviewComment',
|
||||
listLabels: 'github.listLabels',
|
||||
listAssignableUsers: 'github.listAssignableUsers',
|
||||
rateLimit: 'github.rateLimit',
|
||||
listAccessibleProjects: 'github.project.listAccessible',
|
||||
resolveProjectRef: 'github.project.resolveRef',
|
||||
listProjectViews: 'github.project.listViews',
|
||||
getProjectViewTable: 'github.project.viewTable',
|
||||
projectWorkItemDetailsBySlug: 'github.project.workItemDetailsBySlug',
|
||||
updateProjectItemField: 'github.project.updateItemField',
|
||||
clearProjectItemField: 'github.project.clearItemField',
|
||||
updateIssueBySlug: 'github.project.updateIssueBySlug',
|
||||
updatePullRequestBySlug: 'github.project.updatePullRequestBySlug',
|
||||
addIssueCommentBySlug: 'github.project.addIssueCommentBySlug',
|
||||
updateIssueCommentBySlug: 'github.project.updateIssueCommentBySlug',
|
||||
deleteIssueCommentBySlug: 'github.project.deleteIssueCommentBySlug',
|
||||
listLabelsBySlug: 'github.project.listLabelsBySlug',
|
||||
listAssignableUsersBySlug: 'github.project.listAssignableUsersBySlug',
|
||||
listIssueTypesBySlug: 'github.project.listIssueTypesBySlug',
|
||||
updateIssueTypeBySlug: 'github.project.updateIssueTypeBySlug'
|
||||
} as const satisfies Record<WebGitHubRouteKey, WebGitHubRuntimeMethod>
|
||||
|
||||
export const GITLAB_WEB_RPC_METHODS = {
|
||||
listMRs: 'gitlab.listMRs',
|
||||
listWorkItems: 'gitlab.listWorkItems',
|
||||
listIssues: 'gitlab.listIssues',
|
||||
createIssue: 'gitlab.createIssue',
|
||||
updateIssue: 'gitlab.updateIssue',
|
||||
addIssueComment: 'gitlab.addIssueComment',
|
||||
todos: 'gitlab.todos',
|
||||
workItemDetails: 'gitlab.workItemDetails',
|
||||
closeMR: 'gitlab.updateMRState',
|
||||
reopenMR: 'gitlab.updateMRState',
|
||||
mergeMR: 'gitlab.mergeMR',
|
||||
addMRComment: 'gitlab.addMRComment',
|
||||
workItemByPath: 'gitlab.workItemByPath'
|
||||
} as const satisfies Record<WebGitLabRouteKey, WebGitLabRuntimeMethod>
|
||||
|
||||
const WEB_KEYBINDING_PLATFORMS: readonly KeybindingPlatform[] = ['darwin', 'linux', 'win32']
|
||||
const webKeybindingListeners = new Set<(snapshot: KeybindingFileSnapshot) => void>()
|
||||
|
||||
@@ -206,6 +393,7 @@ function createWebPreloadApi(): Partial<PreloadApi> {
|
||||
git: createGitApi(),
|
||||
browser: createBrowserApi(),
|
||||
gh: createGitHubApi(),
|
||||
gl: createGitLabApi(),
|
||||
hostedReview: createRuntimeNamespaceApi('hostedReview'),
|
||||
linear: createRuntimeNamespaceApi('linear'),
|
||||
hooks: createHooksApi(),
|
||||
@@ -1015,17 +1203,18 @@ function createBrowserApi(): NonNullable<Partial<PreloadApi>['browser']> {
|
||||
} as unknown as NonNullable<Partial<PreloadApi>['browser']>
|
||||
}
|
||||
|
||||
function createGitHubApi(): NonNullable<Partial<PreloadApi>['gh']> {
|
||||
const direct = (method: string) => (args?: unknown) =>
|
||||
callRuntimeResult(method, mapRepoPathArg(args))
|
||||
return {
|
||||
function createGitHubApi(): WebGitHubApi {
|
||||
const route = <Result>(method: WebGitHubRuntimeMethod, args?: unknown): Promise<Result> =>
|
||||
callRuntimeResult<Result>(method, mapRepoPathArg(args))
|
||||
const githubApi = {
|
||||
viewer: () => Promise.resolve(null),
|
||||
repoSlug: direct('github.repoSlug'),
|
||||
prForBranch: direct('github.prForBranch'),
|
||||
repoSlug: (args) => route<WebGitHubResult<'repoSlug'>>(GITHUB_WEB_RPC_METHODS.repoSlug, args),
|
||||
prForBranch: (args) =>
|
||||
route<WebGitHubResult<'prForBranch'>>(GITHUB_WEB_RPC_METHODS.prForBranch, args),
|
||||
refreshPRNow: async ({ candidate }) => {
|
||||
const pr = await callRuntimeResult('github.prForBranch', {
|
||||
repo: candidate.repoId || candidate.repoPath,
|
||||
const pr = await route<WebGitHubResult<'prForBranch'>>(GITHUB_WEB_RPC_METHODS.prForBranch, {
|
||||
repoPath: candidate.repoPath,
|
||||
repoId: candidate.repoId,
|
||||
branch: candidate.branch,
|
||||
linkedPRNumber: candidate.linkedPRNumber ?? null,
|
||||
fallbackPRNumber: candidate.fallbackPRNumber ?? null
|
||||
@@ -1037,55 +1226,189 @@ function createGitHubApi(): NonNullable<Partial<PreloadApi>['gh']> {
|
||||
enqueuePRRefresh: () => Promise.resolve(false),
|
||||
reportVisiblePRRefreshCandidates: () => Promise.resolve(false),
|
||||
onPRRefreshEvent: () => noopUnsubscribe,
|
||||
issue: direct('github.issue'),
|
||||
workItem: direct('github.workItem'),
|
||||
workItemByOwnerRepo: direct('github.workItemByOwnerRepo'),
|
||||
workItemDetails: direct('github.workItemDetails'),
|
||||
prFileContents: direct('github.prFileContents'),
|
||||
listIssues: async () => [],
|
||||
createIssue: direct('github.createIssue'),
|
||||
countWorkItems: direct('github.countWorkItems'),
|
||||
listWorkItems: direct('github.listWorkItems'),
|
||||
prChecks: direct('github.prChecks'),
|
||||
prCheckDetails: direct('github.prCheckDetails'),
|
||||
rerunPRChecks: direct('github.rerunPRChecks'),
|
||||
prComments: direct('github.prComments'),
|
||||
resolveReviewThread: direct('github.resolveReviewThread'),
|
||||
setPRFileViewed: direct('github.setPRFileViewed'),
|
||||
updatePRTitle: direct('github.updatePRTitle'),
|
||||
mergePR: direct('github.mergePR'),
|
||||
updatePRState: direct('github.updatePRState'),
|
||||
requestPRReviewers: direct('github.requestPRReviewers'),
|
||||
removePRReviewers: direct('github.removePRReviewers'),
|
||||
updateIssue: direct('github.updateIssue'),
|
||||
addIssueComment: direct('github.addIssueComment'),
|
||||
addPRReviewCommentReply: direct('github.addPRReviewCommentReply'),
|
||||
addPRReviewComment: direct('github.addPRReviewComment'),
|
||||
listLabels: direct('github.listLabels'),
|
||||
listAssignableUsers: direct('github.listAssignableUsers'),
|
||||
issue: (args) => route<WebGitHubResult<'issue'>>(GITHUB_WEB_RPC_METHODS.issue, args),
|
||||
workItem: (args) => route<WebGitHubResult<'workItem'>>(GITHUB_WEB_RPC_METHODS.workItem, args),
|
||||
workItemByOwnerRepo: ({ repo: ownerRepo, ...args }) =>
|
||||
route<WebGitHubResult<'workItemByOwnerRepo'>>(GITHUB_WEB_RPC_METHODS.workItemByOwnerRepo, {
|
||||
...args,
|
||||
ownerRepo
|
||||
}),
|
||||
workItemDetails: (args) =>
|
||||
route<WebGitHubResult<'workItemDetails'>>(GITHUB_WEB_RPC_METHODS.workItemDetails, args),
|
||||
prFileContents: (args) =>
|
||||
route<WebGitHubResult<'prFileContents'>>(GITHUB_WEB_RPC_METHODS.prFileContents, args),
|
||||
listIssues: (args) =>
|
||||
route<WebGitHubResult<'listIssues'>>(GITHUB_WEB_RPC_METHODS.listIssues, args),
|
||||
createIssue: (args) =>
|
||||
route<WebGitHubResult<'createIssue'>>(GITHUB_WEB_RPC_METHODS.createIssue, args),
|
||||
countWorkItems: (args) =>
|
||||
route<WebGitHubResult<'countWorkItems'>>(GITHUB_WEB_RPC_METHODS.countWorkItems, args),
|
||||
listWorkItems: (args) =>
|
||||
route<WebGitHubResult<'listWorkItems'>>(GITHUB_WEB_RPC_METHODS.listWorkItems, args),
|
||||
prChecks: (args) => route<WebGitHubResult<'prChecks'>>(GITHUB_WEB_RPC_METHODS.prChecks, args),
|
||||
prCheckDetails: (args) =>
|
||||
route<WebGitHubResult<'prCheckDetails'>>(GITHUB_WEB_RPC_METHODS.prCheckDetails, args),
|
||||
rerunPRChecks: (args) =>
|
||||
route<WebGitHubResult<'rerunPRChecks'>>(GITHUB_WEB_RPC_METHODS.rerunPRChecks, args),
|
||||
prComments: (args) =>
|
||||
route<WebGitHubResult<'prComments'>>(GITHUB_WEB_RPC_METHODS.prComments, args),
|
||||
resolveReviewThread: (args) =>
|
||||
route<WebGitHubResult<'resolveReviewThread'>>(
|
||||
GITHUB_WEB_RPC_METHODS.resolveReviewThread,
|
||||
args
|
||||
),
|
||||
setPRFileViewed: (args) =>
|
||||
route<WebGitHubResult<'setPRFileViewed'>>(GITHUB_WEB_RPC_METHODS.setPRFileViewed, args),
|
||||
updatePRTitle: (args) =>
|
||||
route<WebGitHubResult<'updatePRTitle'>>(GITHUB_WEB_RPC_METHODS.updatePRTitle, args),
|
||||
mergePR: (args) => route<WebGitHubResult<'mergePR'>>(GITHUB_WEB_RPC_METHODS.mergePR, args),
|
||||
updatePRState: (args) =>
|
||||
route<WebGitHubResult<'updatePRState'>>(GITHUB_WEB_RPC_METHODS.updatePRState, args),
|
||||
requestPRReviewers: (args) =>
|
||||
route<WebGitHubResult<'requestPRReviewers'>>(GITHUB_WEB_RPC_METHODS.requestPRReviewers, args),
|
||||
removePRReviewers: (args) =>
|
||||
route<WebGitHubResult<'removePRReviewers'>>(GITHUB_WEB_RPC_METHODS.removePRReviewers, args),
|
||||
updateIssue: (args) =>
|
||||
route<WebGitHubResult<'updateIssue'>>(GITHUB_WEB_RPC_METHODS.updateIssue, args),
|
||||
addIssueComment: (args) =>
|
||||
route<WebGitHubResult<'addIssueComment'>>(GITHUB_WEB_RPC_METHODS.addIssueComment, args),
|
||||
addPRReviewCommentReply: (args) =>
|
||||
route<WebGitHubResult<'addPRReviewCommentReply'>>(
|
||||
GITHUB_WEB_RPC_METHODS.addPRReviewCommentReply,
|
||||
args
|
||||
),
|
||||
addPRReviewComment: (args) =>
|
||||
route<WebGitHubResult<'addPRReviewComment'>>(GITHUB_WEB_RPC_METHODS.addPRReviewComment, args),
|
||||
listLabels: (args) =>
|
||||
route<WebGitHubResult<'listLabels'>>(GITHUB_WEB_RPC_METHODS.listLabels, args),
|
||||
listAssignableUsers: (args) =>
|
||||
route<WebGitHubResult<'listAssignableUsers'>>(
|
||||
GITHUB_WEB_RPC_METHODS.listAssignableUsers,
|
||||
args
|
||||
),
|
||||
onWorkItemMutated: () => noopUnsubscribe,
|
||||
checkOrcaStarred: () => Promise.resolve(null),
|
||||
starOrca: () => Promise.resolve(false),
|
||||
rateLimit: direct('github.rateLimit'),
|
||||
rateLimit: (args) =>
|
||||
route<WebGitHubResult<'rateLimit'>>(GITHUB_WEB_RPC_METHODS.rateLimit, args),
|
||||
diagnoseAuth: () =>
|
||||
Promise.resolve({ ok: false, message: 'Unavailable in the web client.' } as never),
|
||||
listAccessibleProjects: direct('github.project.listAccessible'),
|
||||
resolveProjectRef: direct('github.project.resolveRef'),
|
||||
listProjectViews: direct('github.project.listViews'),
|
||||
getProjectViewTable: direct('github.project.viewTable'),
|
||||
projectWorkItemDetailsBySlug: direct('github.project.workItemDetailsBySlug'),
|
||||
updateProjectItemField: direct('github.project.updateItemField'),
|
||||
clearProjectItemField: direct('github.project.clearItemField'),
|
||||
updateIssueBySlug: direct('github.project.updateIssueBySlug'),
|
||||
updatePullRequestBySlug: direct('github.project.updatePullRequestBySlug'),
|
||||
addIssueCommentBySlug: direct('github.project.addIssueCommentBySlug'),
|
||||
updateIssueCommentBySlug: direct('github.project.updateIssueCommentBySlug'),
|
||||
deleteIssueCommentBySlug: direct('github.project.deleteIssueCommentBySlug'),
|
||||
listLabelsBySlug: direct('github.project.listLabelsBySlug'),
|
||||
listAssignableUsersBySlug: direct('github.project.listAssignableUsersBySlug'),
|
||||
listIssueTypesBySlug: direct('github.project.listIssueTypesBySlug'),
|
||||
updateIssueTypeBySlug: direct('github.project.updateIssueTypeBySlug')
|
||||
} as NonNullable<Partial<PreloadApi>['gh']>
|
||||
listAccessibleProjects: () =>
|
||||
route<WebGitHubResult<'listAccessibleProjects'>>(
|
||||
GITHUB_WEB_RPC_METHODS.listAccessibleProjects
|
||||
),
|
||||
resolveProjectRef: (args) =>
|
||||
route<WebGitHubResult<'resolveProjectRef'>>(GITHUB_WEB_RPC_METHODS.resolveProjectRef, args),
|
||||
listProjectViews: (args) =>
|
||||
route<WebGitHubResult<'listProjectViews'>>(GITHUB_WEB_RPC_METHODS.listProjectViews, args),
|
||||
getProjectViewTable: (args) =>
|
||||
route<WebGitHubResult<'getProjectViewTable'>>(
|
||||
GITHUB_WEB_RPC_METHODS.getProjectViewTable,
|
||||
args
|
||||
),
|
||||
projectWorkItemDetailsBySlug: (args) =>
|
||||
route<WebGitHubResult<'projectWorkItemDetailsBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.projectWorkItemDetailsBySlug,
|
||||
args
|
||||
),
|
||||
updateProjectItemField: (args) =>
|
||||
route<WebGitHubResult<'updateProjectItemField'>>(
|
||||
GITHUB_WEB_RPC_METHODS.updateProjectItemField,
|
||||
args
|
||||
),
|
||||
clearProjectItemField: (args) =>
|
||||
route<WebGitHubResult<'clearProjectItemField'>>(
|
||||
GITHUB_WEB_RPC_METHODS.clearProjectItemField,
|
||||
args
|
||||
),
|
||||
updateIssueBySlug: (args) =>
|
||||
route<WebGitHubResult<'updateIssueBySlug'>>(GITHUB_WEB_RPC_METHODS.updateIssueBySlug, args),
|
||||
updatePullRequestBySlug: (args) =>
|
||||
route<WebGitHubResult<'updatePullRequestBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.updatePullRequestBySlug,
|
||||
args
|
||||
),
|
||||
addIssueCommentBySlug: (args) =>
|
||||
route<WebGitHubResult<'addIssueCommentBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.addIssueCommentBySlug,
|
||||
args
|
||||
),
|
||||
updateIssueCommentBySlug: (args) =>
|
||||
route<WebGitHubResult<'updateIssueCommentBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.updateIssueCommentBySlug,
|
||||
args
|
||||
),
|
||||
deleteIssueCommentBySlug: (args) =>
|
||||
route<WebGitHubResult<'deleteIssueCommentBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.deleteIssueCommentBySlug,
|
||||
args
|
||||
),
|
||||
listLabelsBySlug: (args) =>
|
||||
route<WebGitHubResult<'listLabelsBySlug'>>(GITHUB_WEB_RPC_METHODS.listLabelsBySlug, args),
|
||||
listAssignableUsersBySlug: (args) =>
|
||||
route<WebGitHubResult<'listAssignableUsersBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.listAssignableUsersBySlug,
|
||||
args
|
||||
),
|
||||
listIssueTypesBySlug: (args) =>
|
||||
route<WebGitHubResult<'listIssueTypesBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.listIssueTypesBySlug,
|
||||
args
|
||||
),
|
||||
updateIssueTypeBySlug: (args) =>
|
||||
route<WebGitHubResult<'updateIssueTypeBySlug'>>(
|
||||
GITHUB_WEB_RPC_METHODS.updateIssueTypeBySlug,
|
||||
args
|
||||
)
|
||||
} satisfies WebGitHubApi
|
||||
|
||||
return githubApi
|
||||
}
|
||||
|
||||
function createGitLabApi(): WebGitLabApi {
|
||||
const route = <Result>(method: WebGitLabRuntimeMethod, args?: unknown): Promise<Result> =>
|
||||
callRuntimeResult<Result>(method, mapRepoPathArg(args))
|
||||
|
||||
const gitLabApi = {
|
||||
viewer: () => Promise.resolve(null),
|
||||
projectSlug: () => Promise.resolve(null),
|
||||
mrForBranch: () => Promise.resolve(null),
|
||||
mr: () => Promise.resolve(null),
|
||||
listMRs: (args) => route<WebGitLabResult<'listMRs'>>(GITLAB_WEB_RPC_METHODS.listMRs, args),
|
||||
listWorkItems: (args) =>
|
||||
route<WebGitLabResult<'listWorkItems'>>(GITLAB_WEB_RPC_METHODS.listWorkItems, args),
|
||||
issue: () => Promise.resolve(null),
|
||||
listIssues: (args) =>
|
||||
route<WebGitLabResult<'listIssues'>>(GITLAB_WEB_RPC_METHODS.listIssues, args),
|
||||
createIssue: (args) =>
|
||||
route<WebGitLabResult<'createIssue'>>(GITLAB_WEB_RPC_METHODS.createIssue, args),
|
||||
updateIssue: (args) =>
|
||||
route<WebGitLabResult<'updateIssue'>>(GITLAB_WEB_RPC_METHODS.updateIssue, args),
|
||||
addIssueComment: (args) =>
|
||||
route<WebGitLabResult<'addIssueComment'>>(GITLAB_WEB_RPC_METHODS.addIssueComment, args),
|
||||
listLabels: () => Promise.resolve([]),
|
||||
listAssignableUsers: () => Promise.resolve([]),
|
||||
todos: (args) => route<WebGitLabResult<'todos'>>(GITLAB_WEB_RPC_METHODS.todos, args),
|
||||
workItemDetails: (args) =>
|
||||
route<WebGitLabResult<'workItemDetails'>>(GITLAB_WEB_RPC_METHODS.workItemDetails, args),
|
||||
closeMR: (args) =>
|
||||
route<WebGitLabResult<'closeMR'>>(GITLAB_WEB_RPC_METHODS.closeMR, {
|
||||
...args,
|
||||
state: 'closed'
|
||||
}),
|
||||
reopenMR: (args) =>
|
||||
route<WebGitLabResult<'reopenMR'>>(GITLAB_WEB_RPC_METHODS.reopenMR, {
|
||||
...args,
|
||||
state: 'opened'
|
||||
}),
|
||||
mergeMR: (args) => route<WebGitLabResult<'mergeMR'>>(GITLAB_WEB_RPC_METHODS.mergeMR, args),
|
||||
addMRComment: (args) =>
|
||||
route<WebGitLabResult<'addMRComment'>>(GITLAB_WEB_RPC_METHODS.addMRComment, args),
|
||||
workItemByPath: (args) =>
|
||||
route<WebGitLabResult<'workItemByPath'>>(GITLAB_WEB_RPC_METHODS.workItemByPath, args)
|
||||
} satisfies WebGitLabApi
|
||||
|
||||
return gitLabApi
|
||||
}
|
||||
|
||||
function createRuntimeNamespaceApi(prefix: string): never {
|
||||
|
||||
Reference in New Issue
Block a user