Rename CombinedBranch

This commit is contained in:
Caleb Owens 2024-07-11 19:56:04 +02:00
parent 3b7c2c7bbb
commit 7dbab4722d
No known key found for this signature in database
5 changed files with 26 additions and 17 deletions

View File

@ -1,5 +1,5 @@
import { capture } from '$lib/analytics/posthog';
import { CombinedBranch } from '$lib/branches/types';
import { GivenNameBranchGrouping } from '$lib/branches/types';
import { groupBy } from '$lib/utils/groupBy';
import { Observable, combineLatest, of } from 'rxjs';
import { catchError, shareReplay, startWith, switchMap } from 'rxjs/operators';
@ -11,7 +11,7 @@ import type { VirtualBranch, Branch } from '$lib/vbranches/types';
import type { VirtualBranchService } from '$lib/vbranches/virtualBranch';
export class BranchService {
readonly branches$: Observable<CombinedBranch[]>;
readonly branches$: Observable<GivenNameBranchGrouping[]>;
constructor(
virtualBranchService: VirtualBranchService,
@ -35,7 +35,7 @@ export class BranchService {
prWithEmpty$
]).pipe(
switchMap(([virtualBranches, remoteBranches, pullRequests]) => {
return new Observable<CombinedBranch[]>((observer) => {
return new Observable<GivenNameBranchGrouping[]>((observer) => {
const contributions = mergeBranchesAndPrs(
virtualBranches,
pullRequests,
@ -104,7 +104,7 @@ function mergeBranchesAndPrs(
virtualBranches: VirtualBranch[] = [],
pullRequests: PullRequest[] = [],
remoteBranches: Branch[] = []
): CombinedBranch[] {
): GivenNameBranchGrouping[] {
const groupedPullRequests = groupBy(pullRequests, (pullRequest) => pullRequest.sourceBranch);
const groupedRemoteBranches = groupBy(remoteBranches, (remoteBranch) => remoteBranch.givenName);
@ -124,7 +124,7 @@ function mergeBranchesAndPrs(
const pullRequests = groupedPullRequests[branchName] || [];
const remoteBranches = groupedRemoteBranches[branchName] || [];
return new CombinedBranch({
return new GivenNameBranchGrouping({
pullRequests: pullRequests,
branches: remoteBranches
});

View File

@ -1,7 +1,16 @@
import type { PullRequest } from '$lib/github/types';
import type { Author, Branch } from '$lib/vbranches/types';
export class CombinedBranch {
/**
* A grouping of pull requests and branches based on their given name
*
* The given name of a branch is the name a user gave it, without the remote
* name attached
*
* IE for refs/heads/my-branch, the given name is my-branch
* for refs/remotes/origin/my-branch, the given name is my-branch
*/
export class GivenNameBranchGrouping {
pullRequests: PullRequest[];
branches: Branch[];

View File

@ -1,14 +1,14 @@
<script lang="ts">
import BranchIcon from '../branch/BranchIcon.svelte';
import TimeAgo from '$lib/shared/TimeAgo.svelte';
import type { CombinedBranch } from '$lib/branches/types';
import type { GivenNameBranchGrouping } from '$lib/branches/types';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
export let projectId: string;
export let branch: CombinedBranch;
export let branch: GivenNameBranchGrouping;
function getBranchLink(b: CombinedBranch): string | undefined {
function getBranchLink(b: GivenNameBranchGrouping): string | undefined {
return `/${projectId}/unapplied/${b.givenName}`;
}

View File

@ -13,7 +13,7 @@
import { BehaviorSubject, combineLatest } from 'rxjs';
import { createEventDispatcher } from 'svelte';
import { derived } from 'svelte/store';
import type { CombinedBranch } from '$lib/branches/types';
import type { GivenNameBranchGrouping } from '$lib/branches/types';
const dispatch = createEventDispatcher<{ scrollbarDragging: boolean }>();
@ -64,14 +64,14 @@
let contents: HTMLElement;
function filterByType(
branches: CombinedBranch[],
branches: GivenNameBranchGrouping[],
params: {
includePrs: boolean;
includeRemote: boolean;
includeStashed: boolean;
hideBots: boolean;
}
): CombinedBranch[] {
): GivenNameBranchGrouping[] {
return branches.filter((b) => {
if (params.includePrs && b.primaryPullRequest) {
return !params.hideBots || !b.primaryPullRequest.author?.isBot;
@ -82,7 +82,7 @@
});
}
function filterByText(branches: CombinedBranch[], search: string | undefined) {
function filterByText(branches: GivenNameBranchGrouping[], search: string | undefined) {
if (search === undefined) return branches;
return branches.filter((b) => searchMatchesAnIdentifier(search, b.searchableIdentifiers));
@ -96,7 +96,7 @@
return false;
}
function filterInactive(branches: CombinedBranch[]) {
function filterInactive(branches: GivenNameBranchGrouping[]) {
const currentTs = new Date().getTime();
return branches.filter((b) => {
if (!b.modifiedAt) return true; // Keep things that don't have a modified time

View File

@ -2,11 +2,11 @@
import { BranchService } from '$lib/branches/service';
import { getContext } from '$lib/utils/context';
import { onMount } from 'svelte';
import type { CombinedBranch } from '$lib/branches/types';
import type { GivenNameBranchGrouping } from '$lib/branches/types';
import { page } from '$app/stores';
// Maintain combined branches as a state variable
let combinedBranches: CombinedBranch[] = $state([]);
let combinedBranches: GivenNameBranchGrouping[] = $state([]);
onMount(() => {
branchService.branches$.subscribe((newCombinedBranches) => {
combinedBranches = newCombinedBranches;
@ -17,7 +17,7 @@
const givenName = $derived($page.params.givenName);
let combinedBranch: CombinedBranch | undefined = $derived(
let combinedBranch: GivenNameBranchGrouping | undefined = $derived(
combinedBranches.find((combinedBranch) => combinedBranch.givenName === givenName)
);