(url: string)
| 7 | } |
| 8 | |
| 9 | export function getRepositoryPreview(url: string): |
| 10 | | {error: 'NOT_A_REPOSITORY' | 'NOT_A_DIRECTORY'} |
| 11 | | {user: string; repository: string; parts: string[]; directory: string} { |
| 12 | const [, user, repository, ...restPathParts] = cleanUrl( |
| 13 | decodeURIComponent(new URL(url).pathname), |
| 14 | ).split('/'); |
| 15 | const type = restPathParts[0]; |
| 16 | |
| 17 | if (!user || !repository) { |
| 18 | return {error: 'NOT_A_REPOSITORY'}; |
| 19 | } |
| 20 | |
| 21 | if (type && type !== 'tree') { |
| 22 | return {error: 'NOT_A_DIRECTORY'}; |
| 23 | } |
| 24 | |
| 25 | const directoryParts = type === 'tree' ? restPathParts.slice(2) : []; |
| 26 | const parts = type === 'tree' ? restPathParts.slice(1) : []; |
| 27 | |
| 28 | return { |
| 29 | user, |
| 30 | repository, |
| 31 | parts, |
| 32 | directory: directoryParts.join('/'), |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | async function parsePath( |
| 37 | user: string, |
no test coverage detected