🔨 chore: move github context to page and inject into components

This commit is contained in:
Kiril Videlov 2023-10-18 14:39:37 +02:00 committed by Kiril Videlov
parent 3f74c66fb7
commit 1e23e77ffa
3 changed files with 26 additions and 14 deletions

View File

@ -26,6 +26,8 @@
import BaseBranchSelect from './BaseBranchSelect.svelte';
import { unsubscribe } from '$lib/utils';
import * as hotkeys from '$lib/hotkeys';
import { userStore } from '$lib/stores/user';
import type { GitHubIntegrationContext } from '$lib/github/types';
export let data: PageData;
let { projectId, project, cloud } = data;
@ -81,6 +83,24 @@
)
)
);
function getIntegrationContext(
remoteUrl: string,
githubAuthToken: string
): GitHubIntegrationContext | undefined {
if (!remoteUrl.includes('github')) return undefined;
const [owner, repo] = remoteUrl.split('.git')[0].split(/\/|:/).slice(-2);
return {
authToken: githubAuthToken,
owner,
repo
};
}
$: githubContext =
$baseBranchStore?.remoteUrl && $userStore?.github_access_token
? getIntegrationContext($baseBranchStore?.remoteUrl, $userStore?.github_access_token)
: undefined;
</script>
{#if $baseBranchesState.isLoading}
@ -151,6 +171,7 @@
baseBranchState={$baseBranchesState}
cloudEnabled={$project?.api?.sync || false}
{cloud}
{githubContext}
/>
</div>
<!-- <BottomPanel base={$baseBranchStore} {userSettings} /> -->

View File

@ -8,6 +8,7 @@
import type { LoadState } from '@square/svelte-store';
import { open } from '@tauri-apps/api/shell';
import { IconFile, IconTerminal, IconExternalLink } from '$lib/icons';
import type { GitHubIntegrationContext } from '$lib/github/types';
export let projectId: string;
export let projectPath: string;
@ -22,6 +23,8 @@
export let cloud: ReturnType<typeof getCloudApiClient>;
export let branchController: BranchController;
export let githubContext: GitHubIntegrationContext | undefined
let dragged: any;
let dropZone: HTMLDivElement;
let priorPosition = 0;
@ -100,6 +103,7 @@
{cloud}
{branchController}
branchCount={branches.filter((c) => c.active).length}
{githubContext}
/>
{/each}

View File

@ -65,6 +65,7 @@
export let branchController: BranchController;
export let maximized = false;
export let branchCount = 1;
export let githubContext: GitHubIntegrationContext | undefined;
const user = userStore;
const userSettings = getContext<SettingsStore>(SETTINGS_CONTEXT);
@ -87,20 +88,6 @@
const dzType = 'text/hunk';
const laneWidthKey = 'laneWidth:';
function getIntegrationContext(): GitHubIntegrationContext | undefined {
const remoteUrl = base?.remoteUrl;
if (!remoteUrl) return undefined;
const [owner, repo] = remoteUrl.split('.git')[0].split(/\/|:/).slice(-2);
const authToken = $user?.github_access_token;
if (!authToken) return undefined;
return {
authToken,
owner,
repo
};
}
$: githubContext = getIntegrationContext();
$: pullRequestPromise =
githubContext && branch.upstream
? getPullRequestByBranch(githubContext, branch.upstream.split('/').slice(-1)[0])