Skip to content
Open
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
13 changes: 7 additions & 6 deletions apps/code/src/main/services/folders/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "node:fs";
import path from "node:path";
import { getRemoteUrl, isGitRepository } from "@posthog/git/queries";
import { InitRepositorySaga } from "@posthog/git/sagas/init";
import { parseGitHubUrl } from "@posthog/git/utils";
import { parseGithubUrl } from "@posthog/git/utils";
import { WorktreeManager } from "@posthog/git/worktree";
import type { IDialog } from "@posthog/platform/dialog";
import { normalizeRepoKey } from "@shared/utils/repo";
Expand Down Expand Up @@ -237,14 +237,15 @@ export class FoldersService {
folderPath: string,
overrideRemoteUrl: string | undefined,
): Promise<string | null> {
const slug = (url: string | null | undefined) => {
const parsed = parseGithubUrl(url);
return parsed ? `${parsed.owner}/${parsed.repo}` : null;
};
if (overrideRemoteUrl) {
return (
parseGitHubUrl(overrideRemoteUrl)?.path ??
normalizeRepoKey(overrideRemoteUrl)
);
return slug(overrideRemoteUrl) ?? normalizeRepoKey(overrideRemoteUrl);
}
const localRemoteUrl = await getRemoteUrl(folderPath);
return parseGitHubUrl(localRemoteUrl)?.path ?? null;
return slug(localRemoteUrl);
}

getRepositoryByRemoteUrl(
Expand Down
55 changes: 33 additions & 22 deletions apps/code/src/main/services/git/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { CommitSaga } from "@posthog/git/sagas/commit";
import { DiscardFileChangesSaga } from "@posthog/git/sagas/discard";
import { PullSaga } from "@posthog/git/sagas/pull";
import { PushSaga } from "@posthog/git/sagas/push";
import { parseGitHubUrl, parsePrUrl } from "@posthog/git/utils";
import { parseGithubUrl } from "@posthog/git/utils";
import { inject, injectable } from "inversify";
import { MAIN_TOKENS } from "../../di/tokens";
import { logger } from "../../utils/logger";
Expand Down Expand Up @@ -218,15 +218,15 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
const remoteUrl = await getRemoteUrl(directoryPath);
if (!remoteUrl) return null;

const repo = parseGitHubUrl(remoteUrl);
if (!repo) return null;
const parsed = parseGithubUrl(remoteUrl);
if (!parsed) return null;

const branch = await getCurrentBranch(directoryPath);
if (!branch) return null;

return {
organization: repo.organization,
repository: repo.repository,
organization: parsed.owner,
repository: parsed.repo,
remote: remoteUrl,
branch,
};
Expand Down Expand Up @@ -426,20 +426,20 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
const remoteUrl = await getRemoteUrl(directoryPath);
if (!remoteUrl) return null;

const parsed = parseGitHubUrl(remoteUrl);
const parsed = parseGithubUrl(remoteUrl);
if (!parsed) return null;

const currentBranch = await getCurrentBranch(directoryPath);
const defaultBranch = await getDefaultBranch(directoryPath);

let compareUrl: string | null = null;
if (currentBranch && currentBranch !== defaultBranch) {
compareUrl = `https://github.com/${parsed.path}/compare/${defaultBranch}...${currentBranch}?expand=1`;
compareUrl = `https://github.com/${parsed.owner}/${parsed.repo}/compare/${defaultBranch}...${currentBranch}?expand=1`;
}

return {
organization: parsed.organization,
repository: parsed.repository,
organization: parsed.owner,
repository: parsed.repo,
currentBranch: currentBranch ?? null,
defaultBranch,
compareUrl,
Expand Down Expand Up @@ -819,7 +819,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {

try {
const remoteUrl = await getRemoteUrl(directoryPath);
const isGitHubRepo = !!(remoteUrl && parseGitHubUrl(remoteUrl));
const isGitHubRepo = !!(remoteUrl && parseGithubUrl(remoteUrl));
const currentBranch = await getCurrentBranch(directoryPath);
const defaultBranch = await getDefaultBranch(directoryPath).catch(
() => null,
Expand Down Expand Up @@ -890,7 +890,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
const remoteUrl = await getRemoteUrl(directoryPath);
if (!remoteUrl) return null;

const parsed = parseGitHubUrl(remoteUrl);
const parsed = parseGithubUrl(remoteUrl);
if (!parsed) return null;

const result = await execGh([
Expand All @@ -905,7 +905,7 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
"--limit",
"1",
"--repo",
parsed.path,
`${parsed.owner}/${parsed.repo}`,
]);

if (result.exitCode !== 0) {
Expand Down Expand Up @@ -980,8 +980,8 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
}

public async getPrChangedFiles(prUrl: string): Promise<ChangedFile[]> {
const pr = parsePrUrl(prUrl);
if (!pr) return [];
const pr = parseGithubUrl(prUrl);
if (pr?.kind !== "pr") return [];

const { owner, repo, number } = pr;

Expand Down Expand Up @@ -1053,8 +1053,8 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
public async getPrDetailsByUrl(
prUrl: string,
): Promise<PrDetailsByUrlOutput | null> {
const pr = parsePrUrl(prUrl);
if (!pr) return null;
const pr = parseGithubUrl(prUrl);
if (pr?.kind !== "pr") return null;

try {
const result = await execGh([
Expand Down Expand Up @@ -1089,8 +1089,8 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
prUrl: string,
action: PrActionType,
): Promise<UpdatePrByUrlOutput> {
const pr = parsePrUrl(prUrl);
if (!pr) {
const pr = parseGithubUrl(prUrl);
if (pr?.kind !== "pr") {
return { success: false, message: "Invalid PR URL" };
}

Expand Down Expand Up @@ -1123,8 +1123,8 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
}

public async getPrReviewComments(prUrl: string): Promise<PrReviewComment[]> {
const pr = parsePrUrl(prUrl);
if (!pr) return [];
const pr = parseGithubUrl(prUrl);
if (pr?.kind !== "pr") return [];

const { owner, repo, number } = pr;

Expand Down Expand Up @@ -1155,8 +1155,8 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
commentId: number,
body: string,
): Promise<ReplyToPrCommentOutput> {
const pr = parsePrUrl(prUrl);
if (!pr) {
const pr = parseGithubUrl(prUrl);
if (pr?.kind !== "pr") {
return { success: false, comment: null };
}

Expand Down Expand Up @@ -1544,6 +1544,17 @@ ${truncatedDiff || "(no diff available)"}${contextSection}`;
const repoInfo = await this.getGitRepoInfo(directoryPath);
if (!repoInfo) return [];

// Full GitHub URL: look up directly. May target a different repo than the local one.
const urlRef = parseGithubUrl(query);
if (urlRef && urlRef.kind !== "repo" && kinds.includes(urlRef.kind)) {
const repoSlug = `${urlRef.owner}/${urlRef.repo}`;
return this.fetchGhRefs(
[urlRef.kind, "view", String(urlRef.number), "--repo", repoSlug],
repoSlug,
urlRef.kind,
);
Comment thread
charlesvien marked this conversation as resolved.
}

const repo = await this.resolveCanonicalRepo(
`${repoInfo.organization}/${repoInfo.repository}`,
);
Expand Down
Loading
Loading