fix: public gh repo reload compose

This commit is contained in:
Andras Bacsai
2023-01-16 12:36:59 +01:00
parent dfd9272b70
commit 344c36997a
3 changed files with 62 additions and 53 deletions

View File

@@ -366,16 +366,16 @@
async function reloadCompose() {
if (loading.reloadCompose) return;
loading.reloadCompose = true;
if (!$appSession.tokens.github) {
if (!$appSession.tokens.github && !isPublicRepository) {
const { token } = await get(`/applications/${id}/configuration/githubToken`);
$appSession.tokens.github = token;
}
try {
if (application.gitSource.type === 'github') {
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
const headers = isPublicRepository
? {}
: {
@@ -402,17 +402,17 @@
if (!$appSession.tokens.gitlab) {
await getGitlabToken();
}
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation.substring(1) // Remove the '/' from the start
: application.dockerComposeFileLocation;
? 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 lastIndex = composeLocation.lastIndexOf('/') + 1;
const path = composeLocation.substring(0, lastIndex);
const fileName = composeLocation.substring(lastIndex);
const headers = isPublicRepository
? {}
: {
@@ -425,8 +425,7 @@
...headers
});
const dockerComposeFileYml = files.find(
(file: { name: string; type: string }) =>
file.name === fileName && file.type === 'blob'
(file: { name: string; type: string }) => file.name === fileName && file.type === 'blob'
);
const id = dockerComposeFileYml.id;
@@ -506,7 +505,14 @@
<div class="grid grid-flow-row gap-2 px-4">
<div class="mt-2 grid grid-cols-2 items-center">
<label for="name">{$t('forms.name')}</label>
<input name="name" id="name" class="w-full" bind:value={application.name} disabled={!$appSession.isAdmin} required />
<input
name="name"
id="name"
class="w-full"
bind:value={application.name}
disabled={!$appSession.isAdmin}
required
/>
</div>
{#if !isSimpleDockerfile}
<div class="grid grid-cols-2 items-center">