Merge pull request #816 from Yarmeli/main

[Bug] Fixed issue with docker-compose not loading for Gitlab instances
This commit is contained in:
Andras Bacsai 2023-01-10 10:56:03 +01:00 committed by GitHub
commit 2244050160
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 10 deletions

View File

@ -352,11 +352,12 @@
async function reloadCompose() { async function reloadCompose() {
if (loading.reloadCompose) return; if (loading.reloadCompose) return;
loading.reloadCompose = true; loading.reloadCompose = true;
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
try { try {
if (application.gitSource.type === 'github') { if (application.gitSource.type === 'github') {
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
const headers = isPublicRepository const headers = isPublicRepository
? {} ? {}
: { : {
@ -383,6 +384,17 @@
if (!$appSession.tokens.gitlab) { if (!$appSession.tokens.gitlab) {
await getGitlabToken(); await getGitlabToken();
} }
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation.substring(1) // Remove the '/' from the start
: application.dockerComposeFileLocation;
// If the file is in a subdirectory, lastIndex will be > 0
// Otherwise it will be -1 and path will be an empty string
const lastIndex = composeLocation.lastIndexOf('/') + 1
const path = composeLocation.substring(0, lastIndex)
const fileName = composeLocation.substring(lastIndex)
const headers = isPublicRepository const headers = isPublicRepository
? {} ? {}
: { : {
@ -390,13 +402,13 @@
}; };
const url = isPublicRepository const url = isPublicRepository
? `` ? ``
: `/v4/projects/${application.projectId}/repository/tree`; : `/v4/projects/${application.projectId}/repository/tree?path=${path}`; // Use path param to find file in a subdirectory
const files = await get(`${apiUrl}${url}`, { const files = await get(`${apiUrl}${url}`, {
...headers ...headers
}); });
const dockerComposeFileYml = files.find( const dockerComposeFileYml = files.find(
(file: { name: string; type: string }) => (file: { name: string; type: string }) =>
file.name === composeLocation && file.type === 'blob' file.name === fileName && file.type === 'blob'
); );
const id = dockerComposeFileYml.id; const id = dockerComposeFileYml.id;

View File

@ -366,11 +366,12 @@
async function reloadCompose() { async function reloadCompose() {
if (loading.reloadCompose) return; if (loading.reloadCompose) return;
loading.reloadCompose = true; loading.reloadCompose = true;
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
try { try {
if (application.gitSource.type === 'github') { if (application.gitSource.type === 'github') {
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
const headers = isPublicRepository const headers = isPublicRepository
? {} ? {}
: { : {
@ -397,6 +398,17 @@
if (!$appSession.tokens.gitlab) { if (!$appSession.tokens.gitlab) {
await getGitlabToken(); await getGitlabToken();
} }
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation.substring(1) // Remove the '/' from the start
: application.dockerComposeFileLocation;
// If the file is in a subdirectory, lastIndex will be > 0
// Otherwise it will be -1 and path will be an empty string
const lastIndex = composeLocation.lastIndexOf('/') + 1
const path = composeLocation.substring(0, lastIndex)
const fileName = composeLocation.substring(lastIndex)
const headers = isPublicRepository const headers = isPublicRepository
? {} ? {}
: { : {
@ -404,13 +416,13 @@
}; };
const url = isPublicRepository const url = isPublicRepository
? `` ? ``
: `/v4/projects/${application.projectId}/repository/tree`; : `/v4/projects/${application.projectId}/repository/tree?path=${path}`;
const files = await get(`${apiUrl}${url}`, { const files = await get(`${apiUrl}${url}`, {
...headers ...headers
}); });
const dockerComposeFileYml = files.find( const dockerComposeFileYml = files.find(
(file: { name: string; type: string }) => (file: { name: string; type: string }) =>
file.name === composeLocation && file.type === 'blob' file.name === fileName && file.type === 'blob'
); );
const id = dockerComposeFileYml.id; const id = dockerComposeFileYml.id;