(filePath: string)
| 17 | } |
| 18 | |
| 19 | const parseGitPath = (filePath: string): GitPathSegments => { |
| 20 | filePath = path.normalize(filePath); |
| 21 | // FilePath will start with the clone directory. We want to remove the clone dir, so that the |
| 22 | // segments can be extracted correctly. |
| 23 | filePath = filePath.replace(_cloneDirRegExp, ''); |
| 24 | // Ignore empty and current directory '.' segments |
| 25 | const [root, type, idRaw] = filePath.split(path.sep).filter(s => s !== '' && s !== '.'); |
| 26 | const id = typeof idRaw === 'string' ? idRaw.replace(/\.(json|yml)$/, '') : idRaw; |
| 27 | return { |
| 28 | root: root || null, |
| 29 | type: models.isValidType(type) ? type : null, |
| 30 | id: id || null, |
| 31 | }; |
| 32 | }; |
| 33 | |
| 34 | export default parseGitPath; |
no test coverage detected