[READ-ONLY] Mirror of https://github.com/FoxxMD/komodo-import. Import existing compose stacks into Komodo foxxmd.github.io/komodo-import
compose docker import komodo toml
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: Better repo parsing and git providers

* Use *any* remote URL domain as git provider (custom in Komodo)
* Parse URL pathname as repo

+31 -25
+10 -4
src/builders/stack/gitStack.ts
··· 7 7 import { stripIndents } from "common-tags"; 8 8 import { isDebugMode, removeUndefinedKeys } from "../../common/utils/utils.js"; 9 9 import { DEFAULT_COMPOSE_GLOB, DEFAULT_ENV_GLOB, selectComposeFiles, selectEnvFiles } from "./stackUtils.js"; 10 - import { detectGitRepo, komodoRepoFromRemoteAndDomain, matchGitDataWithKomodo, matchRemote, RemoteInfo } from "../../common/utils/git.js"; 10 + import { detectGitRepo, komodoRepoFromRemote, matchGitDataWithKomodo, matchRemote, RemoteInfo } from "../../common/utils/git.js"; 11 11 12 12 export type BuildGitStackOptions = GitStackConfig & { logger: Logger }; 13 13 ··· 51 51 const [provider, repo, repoHint] = await matchGitDataWithKomodo(gitData); 52 52 if (repo === undefined) { 53 53 logger.verbose(`Stack will be built without a linked repo: ${repoHint}`); 54 - const repo = komodoRepoFromRemoteAndDomain(provider?.domain ?? 'github.com', gitData[1].url); 55 - logger.debug(`Parsed Repo '${repo}' from Remote URL ${gitData[1].url}`); 54 + const [domain, repo] = komodoRepoFromRemote(gitData[1].url); 55 + if(repo === undefined) { 56 + throw new Error(`Could not parse repo from Remote URL ${gitData[1].url}`); 57 + } 58 + logger.debug(`Parsed Repo '${repo}' with ${provider?.domain !== undefined ? `provider` : 'URL'} domain '${provider?.domain ?? domain}' from Remote URL ${gitData[1].url}`); 59 + if(provider?.username !== undefined) { 60 + logger.debug(`Using provider username ${provider.username}`); 61 + } 56 62 gitStackConfig = { 57 - git_provider: provider?.domain, 63 + git_provider: provider?.domain ?? domain, 58 64 git_account: provider?.username, 59 65 repo 60 66 };
+6 -5
src/builders/stack/stackBuilder.ts
··· 4 4 import { dirHasGitConfig, pathExistsAndIsReadable, readDirectories } from "../../common/utils/io.js"; 5 5 import { childLogger, Logger } from "@foxxmd/logging"; 6 6 import { isUndefinedOrEmptyString, parseBool } from "../../common/utils/utils.js"; 7 - import { detectGitRepo, komodoRepoFromRemoteAndDomain, matchGitDataWithKomodo } from "../../common/utils/git.js"; 7 + import { detectGitRepo, komodoRepoFromRemote, matchGitDataWithKomodo } from "../../common/utils/git.js"; 8 8 import { getDefaultKomodoApi } from "../../common/utils/komodo.js"; 9 9 import { buildGitStack } from "./gitStack.js"; 10 10 import { join as joinPath, parse, ParsedPath } from 'path'; ··· 58 58 inMonorepo: true 59 59 } 60 60 try { 61 - const [provider, repo, repoHint] = await matchGitDataWithKomodo(gitData); 61 + const [provider, linkedRepo, repoHint] = await matchGitDataWithKomodo(gitData); 62 62 if (repoHint !== undefined) { 63 63 logger.warn(`All Stacks will be built without a linked repo: ${repoHint}}`); 64 64 } 65 + const [domain, repo] = komodoRepoFromRemote(gitData[1].remote) 65 66 if (repo === undefined) { 66 67 gitStackConfig = { 67 68 ...options, 68 - git_provider: provider?.domain, 69 + git_provider: provider?.domain ?? domain, 69 70 git_account: provider?.username, 70 - repo: komodoRepoFromRemoteAndDomain(provider?.domain ?? 'github.com', gitData[1].remote) 71 + repo 71 72 }; 72 73 } else { 73 74 gitStackConfig = { 74 75 ...options, 75 - linked_repo: repo.name, 76 + linked_repo: linkedRepo.name, 76 77 } 77 78 } 78 79 } catch (e) {
+15 -16
src/common/utils/git.ts
··· 146 146 } 147 147 } 148 148 149 - export const komodoRepoFromRemoteAndDomain = (domain: string, remote: string): string | undefined => { 150 - const broken = remote.split(domain); 151 - if (broken.length < 2) { 152 - return undefined; 149 + const GIT_EXTENSION = new RegExp(/\.git$/); 150 + 151 + export const komodoRepoFromRemote = (remote: string): [string, string?] => { 152 + const u = new URL(remote); 153 + const provider = u.host; 154 + // this shouldn't happen 155 + if(u.pathname === '/') { 156 + return [provider]; 153 157 } 154 - let cleaned = broken[1].replace('.git', ''); 155 - if (cleaned[0] === '/') { 156 - cleaned = cleaned.substring(1); 158 + let repo: string = u.pathname.replace(GIT_EXTENSION, ''); 159 + if (repo[0] === '/') { 160 + repo = repo.substring(1); 157 161 } 158 - if (cleaned[cleaned.length - 1] === '/') { 159 - cleaned = cleaned.substring(0, cleaned.length - 1); 162 + if (repo[repo.length - 1] === '/') { 163 + repo = repo.substring(0, repo.length - 1); 160 164 } 161 - return cleaned; 165 + return [provider, repo]; 162 166 } 163 167 164 168 export const matchGitDataWithKomodo = async (gitData: Awaited<ReturnType<typeof detectGitRepo>>): Promise<[GitProviderAccount?, RepoListItem?, string?]> => { ··· 181 185 182 186 const providers = await getDefaultKomodoApi().getGitProviders(); 183 187 const validProvider = providers.find(x => gitData[1].url.includes(x.domain)); 184 - if (validProvider === undefined) { 185 - // default provider, we don't need to find an added one 186 - if (!gitData[1].url.includes('github.com')) { 187 - throw new Error(`No Komodo Git Account provider matches remote ${gitData[1].url}`); 188 - } 189 - } else { 188 + if (validProvider !== undefined) { 190 189 provider = validProvider; 191 190 } 192 191 return [provider, repo, repoHint];