Skip to content

Commit e0f5f8a

Browse files
authored
feat: repo detection based off of workspace (#28)
1 parent 3fda983 commit e0f5f8a

File tree

13 files changed

+438
-162
lines changed

13 files changed

+438
-162
lines changed

pnpm-lock.yaml

Lines changed: 145 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ onlyBuiltDependencies:
55
- electron
66
- esbuild
77

8-
overrides:
9-
'@posthog/agent': link:../agent

src/api/repoDetector.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/main/preload.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ contextBridge.exposeInMainWorld("electronAPI", {
3434
ipcRenderer.invoke("validate-repo", directoryPath),
3535
checkWriteAccess: (directoryPath: string): Promise<boolean> =>
3636
ipcRenderer.invoke("check-write-access", directoryPath),
37+
detectRepo: (
38+
directoryPath: string,
39+
): Promise<{
40+
organization: string;
41+
repository: string;
42+
branch?: string;
43+
remote?: string;
44+
} | null> => ipcRenderer.invoke("detect-repo", directoryPath),
3745
showMessageBox: (options: MessageBoxOptions): Promise<{ response: number }> =>
3846
ipcRenderer.invoke("show-message-box", options),
3947
openExternal: (url: string): Promise<void> =>

src/main/services/os.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,61 @@ export function registerOsIpc(getMainWindow: () => BrowserWindow | null): void {
158158
}
159159
},
160160
);
161+
162+
ipcMain.handle(
163+
"detect-repo",
164+
async (
165+
_event: IpcMainInvokeEvent,
166+
directoryPath: string,
167+
): Promise<{
168+
organization: string;
169+
repository: string;
170+
branch?: string;
171+
remote?: string;
172+
} | null> => {
173+
if (!directoryPath) return null;
174+
try {
175+
// Get remote URL
176+
const { stdout: remoteUrl } = await execAsync(
177+
"git remote get-url origin",
178+
{ cwd: directoryPath },
179+
);
180+
const cleanUrl = remoteUrl.trim();
181+
182+
// Parse GitHub URL (HTTPS or SSH format)
183+
let match = cleanUrl.match(/github\.com[:/](.+?)\/(.+?)(\.git)?$/);
184+
if (!match) {
185+
match = cleanUrl.match(/git@github\.com:(.+?)\/(.+?)(\.git)?$/);
186+
}
187+
188+
if (!match) {
189+
return null;
190+
}
191+
192+
const organization = match[1];
193+
const repository = match[2].replace(/\.git$/, "");
194+
195+
// Get current branch
196+
let branch: string | undefined;
197+
try {
198+
const { stdout: branchName } = await execAsync(
199+
"git branch --show-current",
200+
{ cwd: directoryPath },
201+
);
202+
branch = branchName.trim();
203+
} catch {
204+
// Ignore branch detection errors
205+
}
206+
207+
return {
208+
organization,
209+
repository,
210+
branch,
211+
remote: cleanUrl,
212+
};
213+
} catch {
214+
return null;
215+
}
216+
},
217+
);
161218
}

0 commit comments

Comments
 (0)