fix: ghToken in session now

This commit is contained in:
Andras Bacsai
2022-02-18 15:29:32 +01:00
parent 2ce64ac213
commit 906a63b6b5
8 changed files with 37 additions and 39 deletions

View File

@@ -1,13 +1,11 @@
<script lang="ts">
import { goto } from '$app/navigation';
export let githubToken;
export let application;
import { page } from '$app/stores';
import { page, session } from '$app/stores';
import { get, post } from '$lib/api';
import { getGithubToken } from '$lib/components/common';
import { enhance, errorNotification } from '$lib/form';
import { errorNotification } from '$lib/form';
import { onMount } from 'svelte';
const { id } = $page.params;
@@ -30,19 +28,16 @@
branch: undefined
};
let showSave = false;
let token = null;
async function loadRepositoriesByPage(page = 0) {
try {
return await get(`${apiUrl}/installation/repositories?per_page=100&page=${page}`, {
Authorization: `token ${token}`
Authorization: `token ${$session.ghToken}`
});
} catch ({ error }) {
return errorNotification(error);
}
}
async function loadRepositories() {
token = await getGithubToken({ apiUrl, githubToken, application });
let page = 1;
let reposCount = 0;
const loadedRepos = await loadRepositoriesByPage();
@@ -63,7 +58,7 @@
selected.projectId = repositories.find((repo) => repo.full_name === selected.repository).id;
try {
branches = await get(`${apiUrl}/repos/${selected.repository}/branches`, {
Authorization: `token ${token}`
Authorization: `token ${$session.ghToken}`
});
return;
} catch ({ error }) {