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

Function cloneGithubRepository

packages/server/src/utils/providers/github.ts:127–173  ·  view source on GitHub ↗
({
	type = "application",
	...entity
}: CloneGithubRepository)

Source from the content-addressed store, hash-verified

125 outputPathOverride?: string;
126}
127export const cloneGithubRepository = async ({
128 type = "application",
129 ...entity
130}: CloneGithubRepository) => {
131 let command = "set -e;";
132 const isCompose = type === "compose";
133 const {
134 appName,
135 repository,
136 owner,
137 branch,
138 githubId,
139 enableSubmodules,
140 serverId,
141 outputPathOverride,
142 } = entity;
143 const { APPLICATIONS_PATH, COMPOSE_PATH } = paths(!!serverId);
144
145 if (!githubId) {
146 command += `echo "Error: ❌ Github Provider not found"; exit 1;`;
147
148 return command;
149 }
150
151 const requirements = getErrorCloneRequirements(entity);
152
153 // Check if requirements are met
154 if (requirements.length > 0) {
155 command += `echo "GitHub Repository configuration failed for application: ${appName}"; echo "Reasons:"; echo "${requirements.join("\n")}"; exit 1;`;
156 return command;
157 }
158
159 const githubProvider = await findGithubById(githubId);
160 const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH;
161 const outputPath = outputPathOverride ?? join(basePath, appName, "code");
162 const octokit = authGithub(githubProvider);
163 const token = await getGithubToken(octokit);
164 const repoclone = `github.com/${owner}/${repository}.git`;
165 command += `rm -rf ${outputPath};`;
166 command += `mkdir -p ${outputPath};`;
167 const cloneUrl = `https://oauth2:${token}@${repoclone}`;
168
169 command += `echo "Cloning Repo ${repoclone} to ${outputPath}: ✅";`;
170 command += `git clone --branch ${branch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} ${cloneUrl} ${outputPath} --progress;`;
171
172 return command;
173};
174
175export const getGithubRepositories = async (githubId?: string) => {
176 if (!githubId) {

Callers 5

cloneComposeFunction · 0.90
ensurePatchRepoFunction · 0.90
deployComposeFunction · 0.90
deployApplicationFunction · 0.90
deployPreviewApplicationFunction · 0.90

Calls 5

pathsFunction · 0.90
findGithubByIdFunction · 0.90
authGithubFunction · 0.85
getGithubTokenFunction · 0.85

Tested by

no test coverage detected