mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 15:02:32 +00:00
refactor(coding-agent): centralize git url detection
This commit is contained in:
parent
4719929f6a
commit
254c00b788
3 changed files with 8 additions and 37 deletions
|
|
@ -5,6 +5,7 @@ import { homedir, tmpdir } from "node:os";
|
|||
import { basename, dirname, join, relative, resolve } from "node:path";
|
||||
import { minimatch } from "minimatch";
|
||||
import { CONFIG_DIR_NAME } from "../config.js";
|
||||
import { looksLikeGitUrl } from "../utils/git.js";
|
||||
import type { PackageSource, SettingsManager } from "./settings-manager.js";
|
||||
|
||||
export interface PathMetadata {
|
||||
|
|
@ -522,7 +523,7 @@ export class DefaultPackageManager implements PackageManager {
|
|||
};
|
||||
}
|
||||
|
||||
if (source.startsWith("git:") || this.looksLikeGitUrl(source)) {
|
||||
if (source.startsWith("git:") || looksLikeGitUrl(source)) {
|
||||
const repoSpec = source.startsWith("git:") ? source.slice("git:".length).trim() : source;
|
||||
const [repo, ref] = repoSpec.split("@");
|
||||
const normalized = repo.replace(/^https?:\/\//, "").replace(/\.git$/, "");
|
||||
|
|
@ -542,12 +543,6 @@ export class DefaultPackageManager implements PackageManager {
|
|||
return { type: "local", path: source };
|
||||
}
|
||||
|
||||
private looksLikeGitUrl(source: string): boolean {
|
||||
const gitHosts = ["github.com", "gitlab.com", "bitbucket.org", "codeberg.org"];
|
||||
const normalized = source.replace(/^https?:\/\//, "");
|
||||
return gitHosts.some((host) => normalized.startsWith(`${host}/`));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a unique identity for a package, ignoring version/ref.
|
||||
* Used to detect when the same package is in both global and project settings.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue