| 1 |
// The remote provider registered with the Oxygen extension: a hub is any |
| 2 |
// base URL we know (signed in, or configured), and a remote URL is a |
| 3 |
// repository on one of them. |
| 4 |
|
| 5 |
import { hubUrl, parseRepoUrl } from "./hub"; |
| 6 |
|
| 7 |
export interface KnownHubs { |
| 8 |
bases(): string[]; |
| 9 |
} |
| 10 |
|
| 11 |
export function makeProvider(hubs: KnownHubs) { |
| 12 |
return { |
| 13 |
id: "oxygenhub", |
| 14 |
label: "OxygenHub", |
| 15 |
matches(remoteUrl: string): boolean { |
| 16 |
const p = parseRepoUrl(remoteUrl); |
| 17 |
return !!p && hubs.bases().some((b) => b.replace(/\/$/, "") === p.base); |
| 18 |
}, |
| 19 |
urlFor(remoteUrl: string, target: { kind: string; [k: string]: unknown }): string | undefined { |
| 20 |
const p = parseRepoUrl(remoteUrl); |
| 21 |
return p ? hubUrl(p.base, p.owner, p.name, target) : undefined; |
| 22 |
}, |
| 23 |
}; |
| 24 |
} |