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

@ -351,7 +351,7 @@
}
async function reloadCompose() {
if (loading.reloadCompose) return;
if (!$appSession.tokens.github) {
if (!$appSession.tokens.github && !isPublicRepository) {
const { token } = await get(`/applications/${id}/configuration/githubToken`);
$appSession.tokens.github = token;
}
@ -385,7 +385,7 @@
}
}
if (application.gitSource.type === 'gitlab') {
if (!$appSession.tokens.gitlab) {
if (!$appSession.tokens.gitlab && !isPublicRepository) {
await getGitlabToken();
}

View File

@ -125,6 +125,7 @@
}
}
</script>
{#if repositories.length === 0 && loading.repositories === false}
<div class="flex-col text-center">
<div class="pb-4">{$t('application.configuration.no_repositories_configured')}</div>
@ -134,43 +135,45 @@
</div>
{:else}
<form on:submit|preventDefault={handleSubmit} class="px-10">
<div class="flex lg:flex-row flex-col lg:space-y-0 space-y-2 space-x-0 lg:space-x-2 items-center lg:justify-center">
<div class="custom-select-wrapper w-full"><label for="repository" class="pb-1">Repository</label>
<Select
placeholder={loading.repositories
? $t('application.configuration.loading_repositories')
: $t('application.configuration.select_a_repository')}
id="repository"
showIndicator={!loading.repositories}
isWaiting={loading.repositories}
on:select={loadBranches}
items={reposSelectOptions}
isDisabled={loading.repositories}
isClearable={false}
/>
</div>
<input class="hidden" bind:value={selected.projectId} name="projectId" />
<div class="custom-select-wrapper w-full"><label for="repository" class="pb-1">Branch</label>
<Select
placeholder={loading.branches
? $t('application.configuration.loading_branches')
: !selected.repository
? $t('application.configuration.select_a_repository_first')
: $t('application.configuration.select_a_branch')}
isWaiting={loading.branches}
showIndicator={selected.repository && !loading.branches}
id="branches"
on:select={selectBranch}
items={branchSelectOptions}
isDisabled={loading.branches || !selected.repository}
isClearable={false}
/>
</div></div>
<div
class="flex lg:flex-row flex-col lg:space-y-0 space-y-2 space-x-0 lg:space-x-2 items-center lg:justify-center"
>
<div class="custom-select-wrapper w-full">
<label for="repository" class="pb-1">Repository</label>
<Select
placeholder={loading.repositories
? $t('application.configuration.loading_repositories')
: $t('application.configuration.select_a_repository')}
id="repository"
showIndicator={!loading.repositories}
isWaiting={loading.repositories}
on:select={loadBranches}
items={reposSelectOptions}
isDisabled={loading.repositories}
isClearable={false}
/>
</div>
<input class="hidden" bind:value={selected.projectId} name="projectId" />
<div class="custom-select-wrapper w-full">
<label for="repository" class="pb-1">Branch</label>
<Select
placeholder={loading.branches
? $t('application.configuration.loading_branches')
: !selected.repository
? $t('application.configuration.select_a_repository_first')
: $t('application.configuration.select_a_branch')}
isWaiting={loading.branches}
showIndicator={selected.repository && !loading.branches}
id="branches"
on:select={selectBranch}
items={branchSelectOptions}
isDisabled={loading.branches || !selected.repository}
isClearable={false}
/>
</div>
</div>
<div class="pt-5 flex-col flex justify-center items-center space-y-4">
<button
class="btn btn-wide btn-primary"
type="submit"
disabled={!showSave}
<button class="btn btn-wide btn-primary" type="submit" disabled={!showSave}
>{$t('forms.save')}</button
>
</div>

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">