Skip to content

Commit 1631f57

Browse files
committed
improve README.md a bit
1 parent 6969e7a commit 1631f57

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pip install git+git://github.com/ValentinFrancois/python-gitlab-submodule#egg=py
3737
```
3838

3939
## Usage example
40-
- Iterate the submodules of the Gitlab [Inkscape](https://gitlab.com/inkscape/inkscape) project
40+
### 1)
41+
- Iterate over the submodules of the Gitlab [Inkscape](https://gitlab.com/inkscape/inkscape) project
4142
- For each submodule, print:
4243
- its path in the project
4344
- its own Gitlab project SSH URL
@@ -66,14 +67,41 @@ Output:
6667
- share/themes (git@gitlab.com:inkscape/themes.git) -> 2fc6ece138323f905c9b475c3bcdef0d007eb233
6768
```
6869

70+
### 2)
71+
- Iterate over the submodules of the Gitlab [Inkscape](https://gitlab.com/inkscape/inkscape) project
72+
- For each submodule, print:
73+
- its path in the project
74+
- if its commit is up-to-date with the HEAD of the main branch of the
75+
subproject
76+
```diff
77+
for subproject in subprojects:
78+
print('- {} ({}) -> {}'.format(
79+
- subproject.submodule.path,
80+
- subproject.project.url,
81+
- subproject.commit.id))
82+
+ head_subproject_commit = subproject.project.commits.list(
83+
+ ref=subproject.project.default_branch)[0]
84+
+ up_to_date = subproject.commit.id == head_subproject_commit.id
85+
+ print('- {}: {}'.format(
86+
+ subproject.submodule.path,
87+
+ 'ok' if up_to_date else '/!\\ must update'))
88+
89+
```
90+
Output:
91+
```
92+
- share/extensions: /!\ must update
93+
- src/3rdparty/2geom: ok
94+
- share/themes: ok
95+
```
96+
6997
## Available functions and objects
7098

7199
### `iterate_subprojects(...)`
72100
What you'll probably use most of the time.<br/>
73-
- Yields `Subproject` objects that describe the submodules.
101+
- Yields [`Subproject`](#class-subproject) objects that describe the submodules.
74102
- Ignores submodules that are not hosted on Gitlab. If you want to list all
75103
modules present in the `.gitmodules` file but without mapping them to
76-
`gitlab.v4.objects.Project` objects, use list_submodules(...) instead.
104+
`gitlab.v4.objects.Project` objects, use [`list_submodules(...)`](#list_submodules) instead.
77105
```python
78106
iterate_subprojects(
79107
project: Project,
@@ -104,16 +132,16 @@ Parameters:
104132
Returns: Generator of `Subproject` objects
105133

106134
### `list_subprojects(...)`
107-
Same parameters as `iterate_subprojects(...)` but returns a `list` or
108-
`Subproject` objects.
135+
Same parameters as [`iterate_subprojects(...)`](#iterate_subprojects) but
136+
returns a `list` of [`Subproject`](#class-subproject) objects.
109137

110138
### class `Subproject`
111139
Basic objects that contain the info about a Gitlab subproject.
112140

113141
Attributes:
114142
- `project: gitlab.v4.objects.Project`: the Gitlab project that the submodule links to
115-
- `submodule`: `Submodule`: a basic object that contains the info found in
116-
the `.gitmodules` file (name, path, url).
143+
- `submodule: `[`Submodule`](#class-submodule): a basic object that contains
144+
the info found in the `.gitmodules` file (name, path, url).
117145
- `commit: gitlab.v4.objects.ProjectCommit`: the commit that the submodule points to
118146
- `commit_is_exact: bool`: `True` most of the time, `False` only if the commit
119147
had to be guessed via the `get_latest_commit_possible_if_not_found` option
@@ -159,7 +187,7 @@ Example `str()` output:
159187
```
160188

161189
### `submodule_to_subproject(...)`
162-
Converts a `Submodule` object to a `Subproject` object, assuming it's
190+
Converts a `Submodule` object to a [`Subproject`](#class-subproject) object, assuming it's
163191
hosted on Gitlab.
164192

165193
```python
@@ -170,4 +198,4 @@ submodule_to_subproject(
170198
get_latest_commit_possible_ref: Optional[str] = None
171199
) -> Subproject
172200
```
173-
Parameters: See `iterate_subprojects(...)`
201+
Parameters: See [`iterate_subprojects(...)`](#iterate_subprojects)

tests/test_gitlab_submodule.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class TestSubmoduleCommit(unittest.TestCase):
1212

13-
def test_read_inkscape_submodule_info(self):
13+
def test_read_inkscape_subproject(self):
1414

1515
gl = Gitlab()
1616
inkscape = gl.projects.get('inkscape/inkscape')
@@ -29,7 +29,7 @@ def test_read_inkscape_submodule_info(self):
2929
'9d38946b7d7a0486a4a75669008112d306309d9e')
3030
self.assertEqual(submodule_info.commit, submodule_commit)
3131

32-
def test_list_all_inkscape_submodule_info(self):
32+
def test_list_inkscape_subprojects(self):
3333
gl = Gitlab()
3434
inkscape = gl.projects.get('inkscape/inkscape')
3535
subprojects = list_subprojects(
@@ -41,3 +41,19 @@ def test_list_all_inkscape_submodule_info(self):
4141
subproject.submodule.path,
4242
subproject.project.ssh_url_to_repo,
4343
subproject.commit.id))
44+
45+
def test_compare_inkscape_subprojects_commits_to_head(self):
46+
gl = Gitlab()
47+
inkscape = gl.projects.get('inkscape/inkscape')
48+
subprojects = list_subprojects(
49+
inkscape,
50+
gl,
51+
ref='e371b2f826adcba316f2e64bbf2f697043373d0b')
52+
for subproject in subprojects:
53+
head_subproject_commit = subproject.project.commits.list(
54+
ref=subproject.project.default_branch)[0]
55+
up_to_date = subproject.commit.id == head_subproject_commit.id
56+
print('- {}: {}'.format(
57+
subproject.submodule.path,
58+
'ok' if up_to_date else '/!\\ must update'))
59+

0 commit comments

Comments
 (0)