🔧 fix: update getGithubContext to only emit distinct values when baseBranch remoteUrl changes

This commit is contained in:
Mattias Granlund 2023-11-29 00:21:30 +01:00
parent 71cce6730e
commit 5973ce4364

View File

@ -1,13 +1,14 @@
import type { User } from '$lib/backend/cloud';
import type { GitHubIntegrationContext } from '$lib/github/types';
import type { BaseBranch } from '$lib/vbranches/types';
import { combineLatest, switchMap, type Observable, of, shareReplay } from 'rxjs';
import { combineLatest, switchMap, type Observable, of, shareReplay, distinct } from 'rxjs';
export function getGithubContext(
user$: Observable<User | undefined>,
baseBranch$: Observable<BaseBranch | null>
): Observable<GitHubIntegrationContext | undefined> {
return combineLatest([user$, baseBranch$]).pipe(
const distinctUrl$ = baseBranch$.pipe(distinct((ctx) => ctx?.remoteUrl));
return combineLatest([user$, distinctUrl$]).pipe(
switchMap(([user, baseBranch]) => {
const remoteUrl = baseBranch?.remoteUrl;
const authToken = user?.github_access_token;