({
type = "application",
...entity
}: CloneGitlabRepository)
| 114 | } |
| 115 | |
| 116 | export const cloneGitlabRepository = async ({ |
| 117 | type = "application", |
| 118 | ...entity |
| 119 | }: CloneGitlabRepository) => { |
| 120 | let command = "set -e;"; |
| 121 | const { |
| 122 | appName, |
| 123 | gitlabBranch, |
| 124 | gitlabId, |
| 125 | gitlabPathNamespace, |
| 126 | enableSubmodules, |
| 127 | serverId, |
| 128 | outputPathOverride, |
| 129 | } = entity; |
| 130 | const { COMPOSE_PATH, APPLICATIONS_PATH } = paths(!!serverId); |
| 131 | |
| 132 | if (!gitlabId) { |
| 133 | command += `echo "Error: ❌ Gitlab Provider not found"; exit 1;`; |
| 134 | return command; |
| 135 | } |
| 136 | |
| 137 | await refreshGitlabToken(gitlabId); |
| 138 | const gitlab = await findGitlabById(gitlabId); |
| 139 | |
| 140 | const requirements = getErrorCloneRequirements(entity); |
| 141 | |
| 142 | // Check if requirements are met |
| 143 | if (requirements.length > 0) { |
| 144 | command += `echo "❌ [ERROR] GitLab Repository configuration failed for application: ${appName}"; echo "Reasons:"; echo "${requirements.join("\n")}"; exit 1;`; |
| 145 | return command; |
| 146 | } |
| 147 | |
| 148 | const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH; |
| 149 | const outputPath = outputPathOverride ?? join(basePath, appName, "code"); |
| 150 | command += `rm -rf ${outputPath};`; |
| 151 | command += `mkdir -p ${outputPath};`; |
| 152 | const repoClone = getGitlabRepoClone(gitlab, gitlabPathNamespace); |
| 153 | const cloneUrl = getGitlabCloneUrl(gitlab, repoClone); |
| 154 | command += `echo "Cloning Repo ${repoClone} to ${outputPath}: ✅";`; |
| 155 | command += `git clone --branch ${gitlabBranch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} ${cloneUrl} ${outputPath} --progress;`; |
| 156 | return command; |
| 157 | }; |
| 158 | |
| 159 | export const getGitlabRepositories = async (gitlabId?: string) => { |
| 160 | if (!gitlabId) { |
no test coverage detected