File tree Expand file tree Collapse file tree 4 files changed +15
-15
lines changed
Expand file tree Collapse file tree 4 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -296,11 +296,11 @@ describe("FoldersService", () => {
296296 ] ) ;
297297 } ) ;
298298
299- it ( "strips .git suffix from remote repo name in display name" , async ( ) => {
299+ it ( "strips .git suffix from remote repo name in display name (defensive against legacy data) " , async ( ) => {
300300 const repos = [
301301 {
302302 id : "folder-1" ,
303- path : "/home/user/MURZINI " ,
303+ path : "/home/user/my-billing-fork " ,
304304 remoteUrl : "PostHog/billing.git" ,
305305 lastAccessedAt : "2024-01-01T00:00:00.000Z" ,
306306 createdAt : "2024-01-01T00:00:00.000Z" ,
@@ -312,7 +312,7 @@ describe("FoldersService", () => {
312312
313313 const result = await service . getFolders ( ) ;
314314
315- expect ( result [ 0 ] . name ) . toBe ( "MURZINI (billing)" ) ;
315+ expect ( result [ 0 ] . name ) . toBe ( "my-billing-fork (billing)" ) ;
316316 } ) ;
317317
318318 it ( "uses remote repo name in display name when it differs from local dir" , async ( ) => {
Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ import path from "node:path";
33import { getRemoteUrl , isGitRepository } from "@posthog/git/queries" ;
44import { InitRepositorySaga } from "@posthog/git/sagas/init" ;
55
6+ import { normalizeRepoKey } from "@shared/utils/repo" ;
7+
68function extractRepoKey ( url : string ) : string | null {
79 const httpsMatch = url . match ( / g i t h u b \. c o m \/ ( [ ^ / ] + \/ [ ^ / ] + ) / ) ;
8- if ( httpsMatch ) return httpsMatch [ 1 ] . replace ( / \. g i t $ / , "" ) ;
10+ if ( httpsMatch ) return normalizeRepoKey ( httpsMatch [ 1 ] ) ;
911
1012 const sshMatch = url . match ( / g i t h u b \. c o m : ( [ ^ / ] + \/ [ ^ / ] + ) / ) ;
11- if ( sshMatch ) return sshMatch [ 1 ] . replace ( / \. g i t $ / , "" ) ;
13+ if ( sshMatch ) return normalizeRepoKey ( sshMatch [ 1 ] ) ;
1214
1315 return null ;
1416}
@@ -86,12 +88,7 @@ export class FoldersService {
8688 ) : string {
8789 const localName = path . basename ( repoPath ) ;
8890 if ( remoteUrl ) {
89- const repoName = remoteUrl
90- . trim ( )
91- . split ( "/" )
92- . pop ( )
93- ?. replace ( / \. g i t $ / , "" )
94- ?. trim ( ) ;
91+ const repoName = normalizeRepoKey ( remoteUrl ) . split ( "/" ) . pop ( ) ;
9592 if ( repoName && repoName . toLowerCase ( ) !== localName . toLowerCase ( ) ) {
9693 return `${ localName } (${ repoName } )` ;
9794 }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
1515} from "@phosphor-icons/react" ;
1616import { Box , Flex , Popover , Text } from "@radix-ui/themes" ;
1717import { useWorkspace } from "@renderer/features/workspace/hooks/useWorkspace" ;
18+ import { normalizeRepoKey } from "@shared/utils/repo" ;
1819import { useNavigationStore } from "@stores/navigationStore" ;
1920import { useCallback , useEffect } from "react" ;
2021import type { TaskData , TaskGroup } from "../hooks/useSidebarData" ;
@@ -378,10 +379,9 @@ export function TaskListView({
378379 const isExpanded = ! collapsedSections . has ( group . id ) ;
379380 const folder = folders . find (
380381 ( f ) =>
381- f . remoteUrl
382- ?. trim ( )
383- . replace ( / \. g i t $ / , "" )
384- . toLowerCase ( ) === group . id . trim ( ) . toLowerCase ( ) ||
382+ ( f . remoteUrl &&
383+ normalizeRepoKey ( f . remoteUrl ) . toLowerCase ( ) ===
384+ normalizeRepoKey ( group . id ) . toLowerCase ( ) ) ||
385385 f . path === group . id ,
386386 ) ;
387387 const groupFolderId =
Original file line number Diff line number Diff line change 1+ export function normalizeRepoKey ( key : string ) : string {
2+ return key . trim ( ) . replace ( / \. g i t $ / , "" ) ;
3+ }
You can’t perform that action at this time.
0 commit comments