Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions apps/code/src/main/services/git/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,22 @@ export const discardFileChangesOutput = z.object({
});

export type DiscardFileChangesOutput = z.infer<typeof discardFileChangesOutput>;

export const githubIssueSchema = z.object({
number: z.number(),
title: z.string(),
state: z.string(),
labels: z.array(z.string()),
url: z.string(),
repo: z.string(),
});

export type GitHubIssue = z.infer<typeof githubIssueSchema>;

export const searchGithubIssuesInput = z.object({
directoryPath: z.string(),
query: z.string().optional(),
limit: z.number().default(25),
});

export const searchGithubIssuesOutput = z.array(githubIssueSchema);
103 changes: 103 additions & 0 deletions apps/code/src/main/services/git/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type {
GhStatusOutput,
GitCommitInfo,
GitFileStatus,
GitHubIssue,
GitRepoInfo,
GitStateSnapshot,
GitSyncStatus,
Expand Down Expand Up @@ -995,4 +996,106 @@ ${filesSummary || "(no file changes detected)"}`;
body: bodyMatch?.[1]?.trim() ?? "",
};
}

private async resolveCanonicalRepo(repo: string): Promise<string> {
const result = await execGh([
"repo",
"view",
repo,
"--json",
"name,owner",
"--jq",
'.owner.login + "/" + .name',
]);
if (result.exitCode !== 0) return repo;
return result.stdout.trim() || repo;
}

private parseGhIssues(stdout: string, repo: string): GitHubIssue[] {
const raw = JSON.parse(stdout) as Array<{
number: number;
title: string;
state: string;
labels: Array<{ name: string }>;
url: string;
}>;
const items = Array.isArray(raw) ? raw : [raw];
return items.map((issue) => ({
number: issue.number,
title: issue.title,
state: issue.state.toUpperCase(),
labels: issue.labels.map((l) => l.name),
url: issue.url,
repo,
}));
}

public async searchGithubIssues(
directoryPath: string,
query?: string,
limit = 5,
): Promise<GitHubIssue[]> {
const repoInfo = await this.getGitRepoInfo(directoryPath);
if (!repoInfo) return [];

const repo = await this.resolveCanonicalRepo(
`${repoInfo.organization}/${repoInfo.repository}`,
);
const trimmed = query?.trim().replace(/^#/, "");
const issueNumber = trimmed ? Number(trimmed) : Number.NaN;

if (!Number.isNaN(issueNumber) && Number.isInteger(issueNumber)) {
return this.fetchGhIssues(
["issue", "view", String(issueNumber), "--repo", repo],
repo,
);
}

if (trimmed) {
return this.fetchGhIssues(
[
"search",
"issues",
trimmed,
"--repo",
repo,
"--limit",
String(limit),
"--match",
"title",
],
repo,
);
}

return this.fetchGhIssues(
[
"issue",
"list",
"--repo",
repo,
"--limit",
String(limit),
"--state",
"all",
],
repo,
);
}

private async fetchGhIssues(
args: string[],
repo: string,
): Promise<GitHubIssue[]> {
const jsonFields = "number,title,state,labels,url";
const result = await execGh([...args, "--json", jsonFields]);
if (result.exitCode !== 0) return [];

try {
return this.parseGhIssues(result.stdout, repo);
} catch {
log.warn("Failed to parse GitHub issues response", { repo, args });
return [];
}
}
}
13 changes: 13 additions & 0 deletions apps/code/src/main/trpc/routers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import {
pullOutput,
pushInput,
pushOutput,
searchGithubIssuesInput,
searchGithubIssuesOutput,
syncInput,
syncOutput,
validateRepoInput,
Expand Down Expand Up @@ -288,4 +290,15 @@ export const gitRouter = router({
input.credentials,
),
),

searchGithubIssues: publicProcedure
.input(searchGithubIssuesInput)
.output(searchGithubIssuesOutput)
.query(({ input }) =>
getService().searchGithubIssues(
input.directoryPath,
input.query,
input.limit,
),
),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
.attachment-menu {
padding: var(--space-1);
min-width: 140px;
}

.attachment-menu-item {
all: unset;
box-sizing: border-box;
display: flex;
align-items: center;
gap: var(--space-2);
width: 100%;
height: var(--space-5);
padding: 0 var(--space-2);
font-size: 12px;
line-height: var(--line-height-1);
letter-spacing: var(--letter-spacing-1);
color: var(--gray-12);
border-radius: var(--radius-1);
cursor: pointer;
user-select: none;
white-space: nowrap;
}

.attachment-menu-item:hover {
background: var(--accent-a4);
}

.attachment-menu-item:disabled {
opacity: 0.5;
cursor: default;
pointer-events: none;
}

.attachment-menu-item-icon {
flex-shrink: 0;
display: flex;
align-items: center;
color: var(--gray-11);
}

.issue-picker [cmdk-root] {
display: flex;
flex-direction: column;
max-height: 340px;
width: 300px;
overflow: hidden;
}

.issue-picker .combobox-input-wrapper {
display: flex;
align-items: center;
gap: var(--space-2);
padding: var(--space-1) var(--space-2);
flex-shrink: 0;
background: var(--gray-2);
border-bottom: 1px solid var(--gray-a6);
}

.issue-picker .combobox-input-icon {
color: var(--gray-9);
flex-shrink: 0;
}

.issue-picker [cmdk-input] {
font-family: var(--default-font-family);
padding: 0;
width: 100%;
background: transparent;
border: none;
outline: none;
color: var(--gray-12);
caret-color: var(--accent-9);
font-size: 12px;
line-height: var(--line-height-1);
flex: 1;
}

.issue-picker [cmdk-input]::placeholder {
color: var(--gray-9);
}

.issue-picker [cmdk-list] {
flex: 1;
min-height: 230px;
overflow-y: auto;
overflow-x: hidden;
overscroll-behavior: contain;
scrollbar-width: thin;
scrollbar-color: var(--gray-a5) transparent;
}

.issue-picker [cmdk-group] {
padding: var(--space-1);
}

.issue-picker [cmdk-item] {
display: flex;
padding: var(--space-1) var(--space-2);
cursor: pointer;
user-select: none;
color: var(--gray-12);
outline: none;
border-radius: var(--radius-1);
font-size: 12px;
line-height: var(--line-height-1);
letter-spacing: var(--letter-spacing-1);
min-width: 0;
overflow: hidden;
}

.issue-picker [cmdk-item][data-selected="true"] {
background: var(--accent-a4);
color: var(--accent-12);
}

.issue-picker [cmdk-item]:active {
background: var(--accent-4);
}

.issue-picker [cmdk-empty] {
display: flex;
align-items: center;
justify-content: center;
height: 64px;
font-size: 12px;
color: var(--gray-9);
}

.issue-picker-text {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
overflow: hidden;
}

.issue-picker-title {
display: flex;
align-items: center;
gap: var(--space-1);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-weight: 500;
}

.issue-picker-dot {
width: 8px;
height: 8px;
border-radius: 50%;
flex-shrink: 0;
}

.issue-picker-meta {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--gray-a10);
font-size: 11px;
}
Loading
Loading