MCPcopy
hub / github.com/Dokploy/dokploy / sanitizeRepoPathSSH

Function sanitizeRepoPathSSH

packages/server/src/utils/providers/git.ts:116–150  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

114 return `ssh-keyscan -p ${port} ${domain} >> ${knownHostsPath};`;
115};
116const sanitizeRepoPathSSH = (input: string) => {
117 const SSH_PATH_RE = new RegExp(
118 [
119 /^\s*/,
120 /(?:(?<proto>[a-z]+):\/\/)?/,
121 /(?:(?<user>[a-z_][a-z0-9_-]+)@)?/,
122 /(?<domain>[^\s/?#:]+)/,
123 /(?::(?<port>[0-9]{1,5}))?/,
124 /(?:[/:](?<owner>[^\s/?#:]+))?/,
125 /(?:[/:](?<repo>(?:[^\s?#:.]|\.(?!git\/?\s*$))+))/,
126 /(?:.git)?\/?\s*$/,
127 ]
128 .map((r) => r.source)
129 .join(""),
130 "i",
131 );
132
133 const found = input.match(SSH_PATH_RE);
134 if (!found) {
135 throw new Error(`Malformatted SSH path: ${input}`);
136 }
137
138 return {
139 user: found.groups?.user ?? "git",
140 domain: found.groups?.domain,
141 port: Number(found.groups?.port ?? 22),
142 owner: found.groups?.owner ?? "",
143 repo: found.groups?.repo,
144 get repoPath() {
145 return `ssh://${this.user}@${this.domain}:${this.port}/${this.owner}${
146 this.owner && "/"
147 }${this.repo}.git`;
148 },
149 };
150};
151
152interface Props {
153 appName: string;

Callers 2

cloneGitRepositoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected