13
13
import urllib .parse
14
14
from collections .abc import Mapping
15
15
16
+ import gitlab
16
17
import jaraco .functools
17
18
import jaraco .vcs
18
19
import packaging .requirements
@@ -50,12 +51,27 @@ def name_from_vcs() -> str | None:
50
51
return name_from_origin (origin ())
51
52
52
53
54
+ def owner_from_vcs () -> str | None :
55
+ """
56
+ >>> owner_from_vcs()
57
+ 'coherent-oss'
58
+ """
59
+ return owner_from_origin (origin ())
60
+
61
+
53
62
@jaraco .functools .pass_none
54
63
def name_from_origin (origin : str | None ) -> str :
55
64
_ , _ , tail = origin .rpartition ('/' )
56
65
return r_fix (tail ).removesuffix ('.git' )
57
66
58
67
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
+
59
75
def name_from_path ():
60
76
"""
61
77
>>> name_from_vcs()
@@ -83,7 +99,7 @@ def none_as(replacement):
83
99
@functools .lru_cache
84
100
@jaraco .functools .apply (none_as ({}))
85
101
def repo_info () -> Mapping :
86
- return github_repo_info ()
102
+ return github_repo_info () or gitlab_repo_info ()
87
103
88
104
89
105
@suppress (subprocess .CalledProcessError , FileNotFoundError )
@@ -98,6 +114,18 @@ def github_repo_info() -> Mapping:
98
114
return {k : v for k , v in data .items () if v }
99
115
100
116
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
+
101
129
def summary ():
102
130
"""
103
131
Load the summary from hosted project.
0 commit comments