Skip to content

Commit d8d910b

Browse files
committed
Add support for metadata from GitLab repos.
Closes #5
1 parent 8e71c20 commit d8d910b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

discovery.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import urllib.parse
1414
from collections.abc import Mapping
1515

16+
import gitlab
1617
import jaraco.functools
1718
import jaraco.vcs
1819
import packaging.requirements
@@ -50,12 +51,27 @@ def name_from_vcs() -> str | None:
5051
return name_from_origin(origin())
5152

5253

54+
def owner_from_vcs() -> str | None:
55+
"""
56+
>>> owner_from_vcs()
57+
'coherent-oss'
58+
"""
59+
return owner_from_origin(origin())
60+
61+
5362
@jaraco.functools.pass_none
5463
def name_from_origin(origin: str | None) -> str:
5564
_, _, tail = origin.rpartition('/')
5665
return r_fix(tail).removesuffix('.git')
5766

5867

68+
@jaraco.functools.pass_none
69+
def owner_from_origin(origin: str | None) -> str:
70+
head, _, _ = origin.rpartition('/')
71+
_, _, owner = head.rpartition('/')
72+
return owner
73+
74+
5975
def name_from_path():
6076
"""
6177
>>> name_from_vcs()
@@ -83,7 +99,7 @@ def none_as(replacement):
8399
@functools.lru_cache
84100
@jaraco.functools.apply(none_as({}))
85101
def repo_info() -> Mapping:
86-
return github_repo_info()
102+
return github_repo_info() or gitlab_repo_info()
87103

88104

89105
@suppress(subprocess.CalledProcessError, FileNotFoundError)
@@ -98,6 +114,18 @@ def github_repo_info() -> Mapping:
98114
return {k: v for k, v in data.items() if v}
99115

100116

117+
@suppress(gitlab.exceptions.GitlabError)
118+
def gitlab_repo_info() -> Mapping:
119+
api = gitlab.Gitlab('https://gitlab.com')
120+
name = name_from_vcs()
121+
owner = owner_from_vcs()
122+
project = api.projects.get(f'{owner}/{name}')
123+
result = dict(url=project.web_url)
124+
if project.description:
125+
result.update(description=project.description)
126+
return result
127+
128+
101129
def summary():
102130
"""
103131
Load the summary from hosted project.

0 commit comments

Comments
 (0)