@@ -5,22 +5,38 @@ List project submodules and get the commits they point to with python-gitlab.
5
5
6
6
The [ Gitlab REST API V4] ( https://docs.gitlab.com/ee/api/api_resources.html )
7
7
doesn't implement anything for submodule inspection yet. The only thing we can
8
- currently do is [ updating a submodule to a new commit id] ( https://docs.gitlab.com/ee/api/repository_submodules.html ) ,
8
+ currently do is [ updating a submodule to a new commit id] (
9
+ https://docs.gitlab.com/ee/api/repository_submodules.html ),
9
10
but how can we trigger such an update if we don't know the current commit id
10
11
of our submodule?
11
12
12
13
If you're using ` python-gitlab ` and you're distributing shared code among
13
14
your projects with submodules, you've probably run into this issue already.
14
15
15
16
This package provides minimal utils to list the submodules present in a
16
- Gitlab project, and more importantly to get the commits they're pointing to
17
- (when the submodules are Gitlab projects themselves, otherwise we cannot
18
- access the project via their URLs using ` python-gitlab ` only).
17
+ Gitlab project, and more importantly to get the commits they're pointing to.
19
18
20
19
Internally, it reads and parses the ` .gitmodules ` file at the root of the
21
20
Project. To get the commit id of a submodule, it finds the last commit that
22
21
updated the submodule and parses its diff.
23
22
23
+ ---
24
+ ** About the future of this package**
25
+
26
+ I don't plan to make PRs to ` python-gitlab ` for now.
27
+
28
+ In my opinion this problem should ideally be fixed in the Gitlab REST API,
29
+ and then ` python-gitlab ` could wrap around the new endpoints.
30
+
31
+ So I see this package as a temporary solution until the API gets extended
32
+ with more submodule functionalities.
33
+
34
+ [ @darkdragon-001 ] ( https://github.com/darkdragon-001 ) created an issue on
35
+ GitLab about the lack of support for submodules, feel free to support it with
36
+ a thumb up: https://gitlab.com/gitlab-org/gitlab/-/issues/352836
37
+
38
+ ---
39
+
24
40
## Requirements
25
41
- Python >= __ 3.7__ (required by ` python-gitlab ` since version ` 3.0.0 ` )
26
42
@@ -100,14 +116,13 @@ Output:
100
116
### ` iterate_subprojects(...) `
101
117
What you'll probably use most of the time.<br />
102
118
- Yields [ ` Subproject ` ] ( #class-subproject ) objects that describe the submodules.
103
- - Ignores submodules that are not hosted on Gitlab. If you want to list all
104
- modules present in the ` .gitmodules ` file but without mapping them to
105
- ` gitlab.v4.objects.Project ` objects, use [ ` list_submodules(...) ` ] ( #list_submodules ) instead.
106
119
``` python
107
120
iterate_subprojects(
108
121
project: Project,
109
122
gl: Union[Gitlab, ProjectManager],
110
123
ref: Optional[str ] = None ,
124
+ only_gitlab_subprojects: bool = False ,
125
+ self_managed_gitlab_host: Optional[str ] = None ,
111
126
get_latest_commit_possible_if_not_found: bool = False ,
112
127
get_latest_commit_possible_ref: Optional[str ] = None
113
128
) -> Generator[Subproject, None , None ]
@@ -118,13 +133,20 @@ Parameters:
118
133
` projects: gitlab.v4.objects.ProjectManager ` attribute
119
134
- ` ref ` : (optional) a ref to a branch, commit, tag etc. Defaults to the
120
135
HEAD of the project default branch.
121
- - ` get_latest_commit_possible_if_not_found ` : in some rare cases, there
122
- won't be any ` Subproject commit ... ` info in the diff of the last commit
123
- that updated the submodules. Set this option to ` True ` if you want to get
124
- instead the most recent commit in the subproject that is anterior to the
136
+ - ` only_gitlab_subprojects ` : (optional) if set to ` True ` , will ignore the
137
+ submodules not hosted on GitLab. If set to ` False ` (default), it will yield
138
+ [ ` Subproject ` ] ( #class-subproject ) objects with ` self.project = None `
139
+ for submodules not hosted on GitLab.
140
+ - ` self_managed_gitlab_host ` : (optional) if some submodules are hosted on a
141
+ self-managed GitLab instance, you should pass its url here otherwise it
142
+ may be impossible to know from the URL that it's a GitLab project.
143
+ - ` get_latest_commit_possible_if_not_found ` : (optional) in some rare cases,
144
+ there won't be any ` Subproject commit ... ` info in the diff of the last
145
+ commit that updated the submodules. Set this option to ` True ` if you want to
146
+ get instead the most recent commit in the subproject that is anterior to the
125
147
commit that updated the submodules of the project. If your goal is to
126
148
check that your submodules are up-to-date, you might want to use this.
127
- - ` get_latest_commit_possible_ref ` : in case you set
149
+ - ` get_latest_commit_possible_ref ` : (optional) in case you set
128
150
` get_latest_commit_possible_if_not_found ` to ` True ` , you can specify a ref for the
129
151
subproject (for instance your submodule could point to a different branch
130
152
than the main one). By default, the main branch of the subproject will be
@@ -140,10 +162,13 @@ returns a `list` of [`Subproject`](#class-subproject) objects.
140
162
Basic objects that contain the info about a Gitlab subproject.
141
163
142
164
Attributes:
143
- - ` project: gitlab.v4.objects.Project ` : the Gitlab project that the submodule links to
165
+ - ` project: Optional[gitlab.v4.objects.Project] ` : the Gitlab project that the
166
+ submodule links to (can be ` None ` if the submodule is not hosted on GitLab)
144
167
- ` submodule: ` [ ` Submodule ` ] ( #class-submodule ) : a basic object that contains
145
168
the info found in the ` .gitmodules ` file (name, path, url).
146
- - ` commit: gitlab.v4.objects.ProjectCommit ` : the commit that the submodule points to
169
+ - ` commit: Union[gitlab.v4.objects.ProjectCommit, Commit] ` : the commit that
170
+ the submodule points to (if the submodule is not hosted on GitLab, it will
171
+ be a dummy ` Commit ` object with a single attribute ` id ` )
147
172
- ` commit_is_exact: bool ` : ` True ` most of the time, ` False ` only if the commit
148
173
had to be guessed via the ` get_latest_commit_possible_if_not_found ` option
149
174
@@ -195,6 +220,7 @@ hosted on Gitlab.
195
220
submodule_to_subproject(
196
221
gitmodules_submodule: Submodule,
197
222
gl: Union[Gitlab, ProjectManager],
223
+ self_managed_gitlab_host: Optional[str ] = None ,
198
224
get_latest_commit_possible_if_not_found: bool = False ,
199
225
get_latest_commit_possible_ref: Optional[str ] = None
200
226
) -> Subproject
0 commit comments