MCPcopy Create free account
hub / github.com/Azure/dev-box-images / _parse_github_url

Function _parse_github_url

builder/repos.py:14–43  ·  view source on GitHub ↗

Parse a GitHub repository git url into its parts

(url)

Source from the content-addressed store, hash-verified

12
13
14def _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
46def _parse_devops_url(url) -> dict:

Callers 1

parse_urlFunction · 0.85

Calls 1

_is_githubFunction · 0.85

Tested by

no test coverage detected