Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions assets/scripts/GitAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import FS from '@isomorphic-git/lightning-fs'
import git from 'isomorphic-git'
import http from 'isomorphic-git/http/web'

const DEFAULT_CORS_PROXY_URL = 'https://cors.isomorphic-git.org'

import type { CommitObject, GitAuth } from 'isomorphic-git'
import type { CommitObject } from 'isomorphic-git'
import type { ResolutionOption } from './store.ts'
import type { OAuthServiceAPI } from './types/git.ts'

export default class GitAgent {
#fs
#remoteURL
#repoId
#corsProxyURL
#corsProxyURL: string | undefined = undefined
#onAuth
#onMergeConflict

Expand All @@ -34,14 +33,14 @@ export default class GitAgent {
constructor({
repoId,
remoteURL,
corsProxyURL = DEFAULT_CORS_PROXY_URL,
auth,
corsProxyURL,
gitServiceProvider,
onMergeConflict,
}: {
repoId: string
remoteURL: string
corsProxyURL?: string
auth: GitAuth
gitServiceProvider: OAuthServiceAPI
onMergeConflict?:
| ((resolutionOptions: ResolutionOption[]) => void)
| undefined
Expand All @@ -50,6 +49,8 @@ export default class GitAgent {

this.#repoId = repoId
this.#remoteURL = remoteURL
const auth = gitServiceProvider.getOauthUsernameAndPassword()

this.#onAuth = () => auth
this.#onMergeConflict = onMergeConflict
this.#corsProxyURL = corsProxyURL
Expand Down Expand Up @@ -83,6 +84,7 @@ export default class GitAgent {
singleBranch: true,
corsProxy: this.#corsProxyURL,
depth: 5,
onAuth: this.#onAuth,
})
}

Expand Down Expand Up @@ -191,6 +193,7 @@ export default class GitAgent {
singleBranch: false, // we want all the branches
dir: this.#repoDirectory,
corsProxy: this.#corsProxyURL,
onAuth: this.#onAuth,
})
}

Expand Down
23 changes: 12 additions & 11 deletions assets/scripts/actions/current-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import page from 'page'
import yaml from 'js-yaml'

import store, { type PartialStore } from './../store.ts'
import ScribouilliGitRepo, {
makeRepoId,
makePublicRepositoryURL,
} from './../scribouilliGitRepo.ts'
import ScribouilliGitRepo from './../scribouilliGitRepo.ts'
import GitAgent from '../GitAgent.ts'
import { handleErrors, logMessage } from './../utils.ts'
import { fetchAuthenticatedUserLogin } from './current-user.ts'
Expand All @@ -17,7 +14,7 @@ import { file } from './file.ts'
import { getPagesList } from './page.ts'
import { getArticlesList } from './article.ts'
import { getOAuthServiceAPI } from '../oauth-services-api/index.ts'
import { CUSTOM_CSS_PATH } from '../config.ts'
import { CUSTOM_CSS_PATH, PROVIDERS_MAP } from '../config.ts'
import type { BuildStatus } from '../types/git.ts'

export const getCurrentRepoPages = () => {
Expand Down Expand Up @@ -65,26 +62,30 @@ export const setCurrentRepositoryFromQuerystring = async (
}

const origin = oAuthProvider.origin
const repoId = makeRepoId(owner, repoName)
const provider = PROVIDERS_MAP.get(oAuthProvider.id)
if (!provider) {
throw new TypeError(`Unkown provider ${oAuthProvider.id}`)
}
const oAuthServiceAPI = getOAuthServiceAPI()

const scribouilliGitRepo = new ScribouilliGitRepo({
owner,
repoName,
repoId,
repoType: provider.type,
origin: origin,
publicRepositoryURL: makePublicRepositoryURL(owner, repoName, origin),
gitServiceProvider: getOAuthServiceAPI(),
})

store.mutations.setCurrentRepository(scribouilliGitRepo)

const gitAgent = new GitAgent({
repoId,
remoteURL: `${origin}/${repoId}.git`,
repoId: oAuthServiceAPI.makeRepoId(owner, repoName),
remoteURL: oAuthServiceAPI.makePublicRepositoryURL(owner, repoName),
corsProxyURL: provider.corsProxy,
gitServiceProvider: oAuthServiceAPI,
onMergeConflict: resolutionOptions => {
store.mutations.setConflict(resolutionOptions)
},
auth: getOAuthServiceAPI().getOauthUsernameAndPassword(),
})

store.mutations.setGitAgent(gitAgent)
Expand Down
26 changes: 13 additions & 13 deletions assets/scripts/actions/setup.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import page from 'page'

import store, { ResolutionOption } from './../store.ts'
import ScribouilliGitRepo, {
makePublicRepositoryURL,
makeRepoId,
} from './../scribouilliGitRepo.ts'
import ScribouilliGitRepo from './../scribouilliGitRepo.ts'
import { getOAuthServiceAPI } from './../oauth-services-api/index.ts'
import { makeAtelierListPageURL } from './../routes/urls.ts'
import { logMessage } from './../utils.ts'
import { setBaseUrlInConfigIfNecessary } from './current-repository.ts'
import GitAgent from '../GitAgent.ts'
import git from 'isomorphic-git'
import type { GitSiteTemplate } from '../types/git.ts'
import { PROVIDERS_MAP } from '../config.ts'

const waitRepoReady = (
scribouilliGitRepo: ScribouilliGitRepo,
Expand Down Expand Up @@ -130,34 +128,36 @@ export const createRepositoryForCurrentAccount = async (
}

const origin = oAuthProvider.origin
const provider = PROVIDERS_MAP.get(oAuthProvider.id)
if (!provider) {
throw new TypeError(`Unkown provider ${oAuthProvider.id}`)
}
const oAuthServiceAPI = getOAuthServiceAPI()

const scribouilliGitRepo = new ScribouilliGitRepo({
owner: owner,
repoName: escapedRepoName,
repoType: provider.type,
origin: origin,
publicRepositoryURL: makePublicRepositoryURL(
owner,
escapedRepoName,
origin,
),
gitServiceProvider: getOAuthServiceAPI(),
gitServiceProvider: oAuthServiceAPI,
})

store.mutations.setCurrentRepository(scribouilliGitRepo)

return (
getOAuthServiceAPI()
oAuthServiceAPI
.createDefaultRepository(scribouilliGitRepo, template)
.then(({ remoteURL }) => {
const gitAgent = new GitAgent({
repoId: makeRepoId(owner, escapedRepoName),
repoId: oAuthServiceAPI.makeRepoId(owner, escapedRepoName),
remoteURL: remoteURL,
corsProxyURL: provider.corsProxy,
onMergeConflict: (
resolutionOptions: ResolutionOption[] | undefined,
) => {
store.mutations.setConflict(resolutionOptions)
},
auth: getOAuthServiceAPI().getOauthUsernameAndPassword(),
gitServiceProvider: oAuthServiceAPI,
})

store.mutations.setGitAgent(gitAgent)
Expand Down
12 changes: 7 additions & 5 deletions assets/scripts/components/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import type { BuildStatus } from '../types/git.ts'
import type { ScribouilliState } from '../store.ts'
import type { BackendType } from '../types/atelier.ts'

interface Props {
buildStatus: BuildStatus
Expand All @@ -20,8 +21,9 @@
let buildStatusClass = $derived(buildStatus ? `build-${buildStatus}` : undefined)
let publishedWebsiteURL: Promise<string> | undefined = $derived(currentRepository?.publishedWebsiteURL)
let repositoryURL: string | undefined = $derived(currentRepository?.publicRepositoryURL)
let repositoryType: BackendType | undefined = $derived(currentRepository?.repoType)
let repoName: string | undefined = $derived(currentRepository?.repoName)
let account: string | undefined = $derived(currentRepository?.owner)
let account: string | undefined = $derived(currentRepository?.owner)
let homeURL: string | undefined =
$derived(repoName && account
? `/atelier-list-pages?repoName=${repoName}&account=${account}`
Expand Down Expand Up @@ -96,13 +98,13 @@
Paramètres
</a>
</li>
<li>
{#if repositoryURL}
{#if repositoryURL && repositoryType !== 'scribouilli' }
<li>
{#await repositoryURL then urlrepository}
<a href={urlrepository} target="_blank">Sur {(new URL(urlrepository)).hostname}</a>
{/await}
{/if}
</li>
</li>
{/if}
</ul>
</nav>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/components/Skeleton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

interface Props {
showArticles?: boolean
buildStatus: BuildStatus
buildStatus?: BuildStatus
currentRepository?: ScribouilliState["currentRepository"] | undefined
conflict?: ScribouilliState["conflict"]
children?: Snippet
Expand Down
51 changes: 11 additions & 40 deletions assets/scripts/components/screens/Account.svelte
Original file line number Diff line number Diff line change
@@ -1,60 +1,31 @@
<script lang="ts">
import { ScribouilliBackendProvider } from "../../types/atelier"
import Skeleton from "../Skeleton.svelte";

interface Props {
gitProvider: string
provider: ScribouilliBackendProvider
}

let { gitProvider }: Props = $props();
let { provider }: Props = $props();
</script>

<Skeleton>
{#if gitProvider === 'github.com'}
<section class="screen" id="account">
<div>
<h2>Avez-vous un compte GitHub&nbsp;?</h2>

<div>
<a href="./login?provider=github.com" class="btn">Oui, je me connecte</a>
<a href="./create-account?provider=github.com" class="btn"
>Non, je veux créer un compte</a
>
</div>
</div>
</section>
{/if}

{#if gitProvider === 'gitlab.com'}
<section class="screen" id="account">
<div>
<h2>Avez-vous un compte sur gitlab.com&nbsp;?</h2>

<div>
<a href="./login?provider=gitlab.com" class="btn">Oui, je me connecte</a>
<a href="./create-account?provider=gitlab.com" class="btn"
>Non, je veux créer un compte</a
>
</div>
</div>
</section>
{/if}

{#if gitProvider === 'git.scribouilli.org'}
<section class="screen" id="account">
<div>
<h2>Avez-vous un compte sur git.scribouilli.org&nbsp;?</h2>
{#if provider.type === 'github' }
<h2>Avez-vous un compte GitHub&nbsp;?</h2>
{:else}
<h2>Avez-vous un compte sur { provider.id }&nbsp;?</h2>
{/if}

<div>
<a href="./login?provider=git.scribouilli.org" class="btn">Oui, je me connecte</a>
<a href="./create-account?provider=git.scribouilli.org" class="btn"
<a href="./login?provider={ provider.id }" class="btn">Oui, je me connecte</a>
<a href="./create-account?provider={ provider.id }" class="btn"
>Non, je veux créer un compte</a
>
</div>
</div>
</section>
{/if}


</Skeleton>

<style lang="scss">
Expand Down
19 changes: 7 additions & 12 deletions assets/scripts/components/screens/ChooseAccount.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import Skeleton from '../Skeleton.svelte'
import { PROVIDERS } from '../../config'
</script>

<Skeleton>
Expand All @@ -14,21 +15,15 @@
</p>

<ul class="descriptions">
<li>
<strong>Gitlab.com</strong> qui est un hébergeur professionnel.<br>
Si vous n'avez pas encore de compte, Gitlab demandera à <a href="https://docs.gitlab.com/ee/security/identity_verification.html" target="_blank">vérifier votre identité</a> avec un n° de téléphone ou de carte bleue.
</li>
<li>
<strong>ScribouGit</strong>, l'hébergement géré par l'équipe de Scribouilli.<br>
Si vous n'avez pas encore de compte, nous prendrons le temps de le valider manuellement (cela peut prendre quelques jours).
</li>
<li>Microsoft GitHub®, si vous l'utilisez déjà.</li>
{#each PROVIDERS as provider }
<li>{@html provider.description}</li>
{/each}
</ul>

<ul class="buttons">
<li><a href="./account?provider=gitlab.com" class="btn">Gitlab</a></li>
<li><a href="./account?provider=git.scribouilli.org" class="btn">ScribouGit</a></li>
<li><a href="./account?provider=github.com" class="btn">Github</a></li>
{#each PROVIDERS as provider }
<li><a href="./account?provider={provider.id}" class="btn">{provider.name}</a></li>
{/each}
</ul>
</section>
</Skeleton>
Expand Down
Loading