Parse a GitHub repository git url into its parts
(url)
| 12 | |
| 13 | |
| 14 | def _parse_github_url(url) -> dict: |
| 15 | '''Parse a GitHub repository git url into its parts''' |
| 16 | # examples: |
| 17 | # git://github.com/codertocat/hello-world.git |
| 18 | # https://github.com/colbylwilliams/devbox-images.git |
| 19 | # git@github.com:colbylwilliams/devbox-images.git |
| 20 | |
| 21 | if not _is_github(url): |
| 22 | raise ValueError(f'{url} is not a valid GitHub repository url') |
| 23 | |
| 24 | url = url.lower().replace('git@', 'https://').replace('git://', 'https://').replace('github.com:', 'github.com/') |
| 25 | |
| 26 | if url.endswith('.git'): |
| 27 | url = url[:-4] |
| 28 | |
| 29 | parts = url.split('/') |
| 30 | |
| 31 | index = next((i for i, part in enumerate(parts) if 'github.com' in part), -1) |
| 32 | |
| 33 | if index == -1 or len(parts) < index + 3: |
| 34 | raise ValueError(f'{url} is not a valid GitHub repository url') |
| 35 | |
| 36 | repo = { |
| 37 | 'provider': 'github', |
| 38 | 'url': url, |
| 39 | 'org': parts[index + 1], |
| 40 | 'repo': parts[index + 2] |
| 41 | } |
| 42 | |
| 43 | return repo |
| 44 | |
| 45 | |
| 46 | def _parse_devops_url(url) -> dict: |
no test coverage detected