Skip to content

Commit 0e72991

Browse files
authored
Merge pull request #29 from openSUSE/3-clone-repos
Fix #3: Clone (Git) repos
2 parents e729ab3 + 3071374 commit 0e72991

27 files changed

Lines changed: 1502 additions & 10 deletions

File tree

changelog.d/3.feature.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Implement cloning of Git repositories
2+
3+
All repos are "bare" clones, meaning they do not have a working directory.
4+
This was needed to avoid issues with branches.
5+
6+
The internal logic is available through some CLI commands:
7+
8+
* :command:`docbuild repo clone` - Clone a repository into the permanent storage.
9+
With the help of the :class:`~docbuild.cli.models.repo.Repo` class,
10+
it can handle different notations of repositories, such as HTTP URLs, SSH URLS, or abbreviated URLs (like ``gh://org/repo``).
11+
* :command:`docbuild repo dir` - Shows the directory path for permanent storage.
12+
This is useful for debugging and manual operations.
13+
* :command:`docbuild repo list` - List all repositories in the permanent storage.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
docbuild.cli.cmd_repo.cmd_clone
2+
===============================
3+
4+
.. py:module:: docbuild.cli.cmd_repo.cmd_clone
5+
6+
.. autoapi-nested-parse::
7+
8+
Clone repositories.
9+
10+
Pass any of the following URLs to clone:
11+
12+

13+
* HTTPS URLs like https://github.com/org/repo.git
14+
* SSH URLS like [email protected]:org/repo.git
15+
* Abbreviated URLs like 'org/repo'
16+
17+
18+
19+
Functions
20+
---------
21+
22+
.. autoapisummary::
23+
24+
docbuild.cli.cmd_repo.cmd_clone.clone
25+
26+
27+
Module Contents
28+
---------------
29+
30+
.. py:function:: clone(ctx: click.Context, repos: tuple[str, Ellipsis]) -> None
31+
32+
Clone repositories into permanent directory.
33+
34+
:param repos: A tuple of repository selectors. If empty, all repos are cloned.
35+
:param ctx: The Click context object.
36+
37+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
docbuild.cli.cmd_repo.cmd_dir
2+
=============================
3+
4+
.. py:module:: docbuild.cli.cmd_repo.cmd_dir
5+
6+
.. autoapi-nested-parse::
7+
8+
Show the directory path for permanent repositories.
9+
10+
11+
12+
Functions
13+
---------
14+
15+
.. autoapisummary::
16+
17+
docbuild.cli.cmd_repo.cmd_dir.cmd_dir
18+
19+
20+
Module Contents
21+
---------------
22+
23+
.. py:function:: cmd_dir(ctx: click.Context) -> None
24+
25+
Show the directory path for permanent repositories.
26+
27+
Outputs the path to the repository directory defined
28+
in the environment configuration.
29+
30+
:param ctx: The Click context object.
31+
32+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
docbuild.cli.cmd_repo.cmd_list
2+
==============================
3+
4+
.. py:module:: docbuild.cli.cmd_repo.cmd_list
5+
6+
.. autoapi-nested-parse::
7+
8+
List the available permanent repositories.
9+
10+
11+
12+
Functions
13+
---------
14+
15+
.. autoapisummary::
16+
17+
docbuild.cli.cmd_repo.cmd_list.cmd_list
18+
19+
20+
Module Contents
21+
---------------
22+
23+
.. py:function:: cmd_list(ctx: click.Context) -> None
24+
25+
List the available permanent repositories.
26+
27+
Outputs the directory names of all repositories defined in the
28+
environment configuration.
29+
If no repositories are defined, it outputs a message indicating that
30+
no repositories are available.
31+
32+
:param ctx: The Click context object.
33+
34+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
docbuild.cli.cmd_repo
2+
=====================
3+
4+
.. py:module:: docbuild.cli.cmd_repo
5+
6+
.. autoapi-nested-parse::
7+
8+
Manage repositories.
9+
10+
11+
12+
Submodules
13+
----------
14+
15+
.. toctree::
16+
:maxdepth: 1
17+
18+
/reference/_autoapi/docbuild/cli/cmd_repo/cmd_clone/index
19+
/reference/_autoapi/docbuild/cli/cmd_repo/cmd_dir/index
20+
/reference/_autoapi/docbuild/cli/cmd_repo/cmd_list/index
21+
/reference/_autoapi/docbuild/cli/cmd_repo/process/index
22+
23+
24+
Functions
25+
---------
26+
27+
.. autoapisummary::
28+
29+
docbuild.cli.cmd_repo.clone
30+
docbuild.cli.cmd_repo.cmd_dir
31+
docbuild.cli.cmd_repo.cmd_list
32+
docbuild.cli.cmd_repo.repo
33+
34+
35+
Package Contents
36+
----------------
37+
38+
.. py:function:: clone(ctx: click.Context, repos: tuple[str, Ellipsis]) -> None
39+
40+
Clone repositories into permanent directory.
41+
42+
:param repos: A tuple of repository selectors. If empty, all repos are cloned.
43+
:param ctx: The Click context object.
44+
45+
46+
.. py:function:: cmd_dir(ctx: click.Context) -> None
47+
48+
Show the directory path for permanent repositories.
49+
50+
Outputs the path to the repository directory defined
51+
in the environment configuration.
52+
53+
:param ctx: The Click context object.
54+
55+
56+
.. py:function:: cmd_list(ctx: click.Context) -> None
57+
58+
List the available permanent repositories.
59+
60+
Outputs the directory names of all repositories defined in the
61+
environment configuration.
62+
If no repositories are defined, it outputs a message indicating that
63+
no repositories are available.
64+
65+
:param ctx: The Click context object.
66+
67+
68+
.. py:function:: repo(ctx: click.Context) -> None
69+
70+
Subcommand to validate XML configuration files.
71+
72+
:param ctx: The Click context object.
73+
74+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
docbuild.cli.cmd_repo.process
2+
=============================
3+
4+
.. py:module:: docbuild.cli.cmd_repo.process
5+
6+
.. autoapi-nested-parse::
7+
8+
Clone Git repositories from a stitchfile or a list of repository URLs.
9+
10+
11+
12+
Functions
13+
---------
14+
15+
.. autoapisummary::
16+
17+
docbuild.cli.cmd_repo.process.clone_repo
18+
docbuild.cli.cmd_repo.process.process
19+
20+
21+
Module Contents
22+
---------------
23+
24+
.. py:function:: clone_repo(repo: docbuild.models.repo.Repo, base_dir: pathlib.Path) -> bool
25+
:async:
26+
27+
28+
Clone a GitHub repository into the specified base directory.
29+
30+
31+
.. py:function:: process(context: docbuild.cli.context.DocBuildContext, repos: tuple[str, Ellipsis]) -> int
32+
:async:
33+
34+
35+
Process the cloning of repositories.
36+
37+
:param context: The DocBuildContext object containing configuration.
38+
:param repos: A tuple of repository selectors. If empty, all repos are used.
39+
:return: An integer exit code.
40+
:raises ValueError: If configuration paths are missing.
41+
42+

docs/source/reference/_autoapi/docbuild/models/deliverable/Deliverable.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ docbuild.models.deliverable.Deliverable
114114

115115

116116
.. py:property:: git
117-
:type: str
117+
:type: docbuild.models.repo.Repo
118118

119119

120120
Return the git repository.

docs/source/reference/_autoapi/docbuild/models/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Submodules
2121
/reference/_autoapi/docbuild/models/lifecycle/index
2222
/reference/_autoapi/docbuild/models/metadata/index
2323
/reference/_autoapi/docbuild/models/product/index
24+
/reference/_autoapi/docbuild/models/repo/index
2425
/reference/_autoapi/docbuild/models/serverroles/index
2526

2627

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
docbuild.models.repo.Repo
2+
=========================
3+
4+
.. py:class:: docbuild.models.repo.Repo(value: str)
5+
6+
A repository model that can be initialized from a URL or a short name.
7+
8+
This model can be compared directly with strings, which will check
9+
against the repository's abbreviated name (e.g., 'org/repo').
10+
11+
Two Repo objects are considered equal if their derived names are the same,
12+
regardless of the original URL (HTTPS vs. SSH).
13+
14+
15+
.. py:attribute:: DEFAULT_HOST
16+
:type: ClassVar[str]
17+
:value: 'https://github.com'
18+
19+
20+
The default host to use when constructing a URL from a short name.
21+
22+
23+
24+
.. py:attribute:: url
25+
:type: str
26+
27+
The full URL of the repository.
28+
29+
30+
31+
.. py:attribute:: surl
32+
:type: str
33+
34+
The shortened URL version of the repository, for example gh://org/repo for
35+
a GitHub repo.
36+
37+
38+
39+
.. py:attribute:: name
40+
:type: str
41+
42+
The abbreviated name of the repository (e.g., 'org/repo').
43+
44+
45+
46+
.. py:method:: __eq__(other: object) -> bool
47+
48+
Compare Repo with another Repo (by name) or a string (by name).
49+
50+
51+
52+
.. py:method:: __str__() -> str
53+
54+
Return the canonical URL of the repository.
55+
56+
57+
58+
.. py:method:: __hash__() -> int
59+
60+
Hash the Repo object based on its canonical derived name.
61+
62+
63+
64+
.. py:method:: __contains__(item: str) -> bool
65+
66+
Check if a string is part of the repository's abbreviated name.
67+
68+
69+
70+
.. py:property:: slug
71+
:type: str
72+
73+
74+
Return the slug name of the repository.
75+
76+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
docbuild.models.repo
2+
====================
3+
4+
.. py:module:: docbuild.models.repo
5+
6+
.. autoapi-nested-parse::
7+
8+
A repository model that can be initialized from a URL or a short name.
9+
10+
11+
12+
Classes
13+
-------
14+
15+
.. toctree::
16+
:hidden:
17+
18+
/reference/_autoapi/docbuild/models/repo/Repo
19+
20+
.. autoapisummary::
21+
22+
docbuild.models.repo.Repo
23+
24+

0 commit comments

Comments
 (0)