Skip to content

Commit c92c936

Browse files
authored
docs: Add gitlab examples to docs (#341)
See also: #336, #337
2 parents 9e55bee + 3bd187f commit c92c936

File tree

3 files changed

+117
-1
lines changed

3 files changed

+117
-1
lines changed

docs/config-generation.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
(config-generation)=
2+
3+
# Config generation
4+
5+
As a temporary solution for `vcspull` not being able to generate {ref}`configuration` through scanning directories or fetching them via API (e.g. gitlab, github, etc), you can write scripts to generate configs in the mean time.
6+
7+
(config-generation-gitlab)=
8+
9+
## Collect repos from Gitlab
10+
11+
Contributed by Andreas Schleifer ([email protected])
12+
13+
Limitation on both, no pagination support in either, so only returns the
14+
first page of repos (as of Feb 26th this is 100).
15+
16+
(config-generation-gitlab-shell)=
17+
18+
### Shell script version
19+
20+
_Requires [jq] and [curl]._
21+
22+
```{literalinclude} ../scripts/generate_gitlab.sh
23+
:language: shell
24+
25+
```
26+
27+
```{code-block} shell
28+
export GITLAB_TOKEN=mySecretToken
29+
/path/to/generate_gitlab.sh gitlab.mycompany.com desired_namespace
30+
```
31+
32+
To be executed from the path where the repos should later be stored. It will use
33+
the current working directory as a "prefix" for the path used in the new config file.
34+
35+
Optional: Set config file output path as additional argument (_will overwrite_)
36+
37+
```{code-block} shell
38+
export GITLAB_TOKEN=mySecretToken
39+
/path/to/generate_gitlab.sh gitlab.mycompany.com desired_namespace /path/to/config.yaml
40+
```
41+
42+
**Demonstration**
43+
44+
Assume current directory of _/home/user/workspace/_ and script at _/home/user/workspace/scripts/generate_gitlab.sh_:
45+
46+
```{code-block} shell
47+
./scripts/generate_gitlab.sh gitlab.com vcs-python
48+
```
49+
50+
New file _vcspull.yaml_:
51+
52+
```{code-block} yaml
53+
/my/workspace/:
54+
g:
55+
url: 'git+ssh://[email protected]/vcs-python/g.git'
56+
remotes:
57+
origin: 'ssh://[email protected]/vcs-python/g.git'
58+
libvcs:
59+
url: 'git+ssh://[email protected]/vcs-python/libvcs.git'
60+
remotes:
61+
origin: 'ssh://[email protected]/vcs-python/libvcs.git'
62+
vcspull:
63+
url: 'git+ssh://[email protected]/vcs-python/vcspull.git'
64+
remotes:
65+
origin: 'ssh://[email protected]/vcs-python/vcspull.git'
66+
```
67+
68+
[jq]: https://stedolan.github.io/jq/
69+
[curl]: https://curl.se/
70+
71+
(config-generation-gitlab-python)=
72+
73+
### Python version
74+
75+
_Requires [requests] and [pyyaml]._
76+
77+
This confirms file overwrite, if already exists. It also requires passing the protocol/schema
78+
of the gitlab mirror, e.g. `https://gitlab.com` instead of `gitlab.com`.
79+
80+
```{literalinclude} ../scripts/generate_gitlab.py
81+
:language: python
82+
83+
```
84+
85+
**Demonstration**
86+
87+
Assume current directory of _/home/user/workspace/_ and script at _/home/user/workspace/scripts/generate_gitlab.sh_:
88+
89+
```{code-block} sh
90+
./scripts/generate_gitlab.py https://gitlab.com vcs-python
91+
```
92+
93+
```{code-block} yaml
94+
/my/workspace/vcs-python:
95+
g:
96+
remotes:
97+
origin: ssh://[email protected]/vcs-python/g.git
98+
url: git+ssh://[email protected]/vcs-python/g.git
99+
libvcs:
100+
remotes:
101+
origin: ssh://[email protected]/vcs-python/libvcs.git
102+
url: git+ssh://[email protected]/vcs-python/libvcs.git
103+
vcspull:
104+
remotes:
105+
origin: ssh://[email protected]/vcs-python/vcspull.git
106+
url: git+ssh://[email protected]/vcs-python/vcspull.git
107+
```
108+
109+
[requests]: https://docs.python-requests.org/en/latest/
110+
[pyyaml]: https://pyyaml.org/
111+
112+
### Contribute your own
113+
114+
Post yours on <https://github.com/vcs-python/vcspull/discussions> or create a PR to add
115+
yours to scripts/ and be featured here

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
quickstart
2323
configuration
24+
config-generation
2425
cli
2526
developing
2627
history

docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $ pip install --user -e git+https://github.com/vcs-python/vcspull.git#egg=vcspul
2626

2727
```{seealso}
2828
29-
{ref}`configuration`.
29+
{ref}`configuration` and {ref}`config-generation`.
3030
3131
```
3232

0 commit comments

Comments
 (0)