@@ -4,6 +4,7 @@ class Route extends SumType<{
44 UserOverview : [ string ] ;
55 ProjectOverview : [ string , string ] ;
66 ProjectCode : [ string , string , string | undefined ] ;
7+ ProjectDefinition : [ string , string , string , string , Array < string > ] ;
78 ProjectTickets : [ string , string ] ;
89 ProjectTicket : [ string , string , number ] ;
910 ProjectContributions : [ string , string ] ;
@@ -30,6 +31,23 @@ function ProjectCode(
3031 return new Route ( "ProjectCode" , handle , projectSlug , branchRef ) ;
3132}
3233
34+ function ProjectDefinition (
35+ handle : string ,
36+ projectSlug : string ,
37+ branchRef : string ,
38+ definitionType : string ,
39+ fqn : Array < string >
40+ ) : Route {
41+ return new Route (
42+ "ProjectDefinition" ,
43+ handle ,
44+ projectSlug ,
45+ branchRef ,
46+ definitionType ,
47+ fqn
48+ ) ;
49+ }
50+
3351function ProjectTickets ( handle : string , projectSlug : string ) : Route {
3452 return new Route ( "ProjectTickets" , handle , projectSlug ) ;
3553}
@@ -79,11 +97,13 @@ function parse(rawUrl: string): Route {
7997 return fromPathname ( url . pathname ) ;
8098}
8199
100+ function isContributorBranchOrRelease ( s : string ) : boolean {
101+ return s . startsWith ( "@" ) || s . startsWith ( "releases" ) ;
102+ }
103+
82104function fromPathname ( rawPath : string ) : Route {
83105 const parts = rawPath . split ( "/" ) . filter ( ( s ) => s . length ) ;
84106
85- console . log ( "route parts" , parts ) ;
86-
87107 const [ handle , projectSlug , ...rest ] = parts ;
88108
89109 if ( handle && handle . startsWith ( "@" ) && ! projectSlug ) {
@@ -92,17 +112,41 @@ function fromPathname(rawPath: string): Route {
92112 const [ projectPage ] = rest ;
93113
94114 if ( projectPage === "code" ) {
95- const [ _ , branchPart1 , branchPart2 ] = rest ;
115+ const [
116+ _ ,
117+ branchPart1 ,
118+ branchPart2 ,
119+ namespaceHashOrDefinitionType ,
120+ definitionTypeOrNameSegment ,
121+ ...nameSegments
122+ ] = rest ;
96123
97124 let branchRef = branchPart1 ;
98- if (
99- branchPart1 &&
100- ( branchPart1 . startsWith ( "@" ) || branchPart1 . startsWith ( "releases" ) )
101- ) {
125+ let fqn = nameSegments || [ ] ;
126+ let definitionType = definitionTypeOrNameSegment ;
127+ if ( branchPart1 && isContributorBranchOrRelease ( branchPart1 ) ) {
102128 branchRef = `${ branchRef } /${ branchPart2 } ` ;
129+ } else if ( branchPart2 ) {
130+ // if the branchPart1 contributor branch a release, then branch2 is a namespaceHash,
131+ // which means the namespaceHashOrDefinitionType is a definition type, and definitionTypeOrNameSegment
132+ // is the first part of the FQN
133+ fqn = [ definitionTypeOrNameSegment , ...nameSegments ] ;
134+ definitionType = namespaceHashOrDefinitionType ;
103135 }
104136
105- return ProjectCode ( handle , projectSlug , branchRef ) ;
137+ // Gotta have an FQN to be a definition Route
138+ if ( fqn . length && definitionType ) {
139+ return ProjectDefinition (
140+ handle ,
141+ projectSlug ,
142+ branchRef ,
143+ // remove the trailing 's' from the definition type
144+ definitionType . substring ( 0 , definitionType . length - 1 ) ,
145+ fqn
146+ ) ;
147+ } else {
148+ return ProjectCode ( handle , projectSlug , branchRef ) ;
149+ }
106150 } else if ( projectPage === "tickets" ) {
107151 const [ _ , ticketRef ] = rest ;
108152
@@ -141,6 +185,7 @@ export {
141185 UserOverview ,
142186 ProjectOverview ,
143187 ProjectCode ,
188+ ProjectDefinition ,
144189 ProjectContributions ,
145190 ProjectContribution ,
146191 ProjectTickets ,
0 commit comments