|
2 | 2 |
|
3 | 3 | # Config generation |
4 | 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. |
| 5 | +The `vcspull import` command can generate configuration by fetching |
| 6 | +repositories from remote services. See {ref}`cli-import` for details. |
6 | 7 |
|
7 | | -(config-generation-gitlab)= |
| 8 | +Supported services: GitHub, GitLab, Codeberg, Gitea, Forgejo, |
| 9 | +AWS CodeCommit. |
8 | 10 |
|
9 | | -## Collect repos from Gitlab |
10 | | - |
11 | | -Contributed by Andreas Schleifer (a.schleifer@bigpoint.net) |
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 | | -````{tab} Shell-script |
17 | | -
|
18 | | -_Requires [jq] and [curl]._ |
19 | | -
|
20 | | -```{literalinclude} ../../scripts/generate_gitlab.sh |
21 | | -:language: shell |
22 | | -``` |
| 11 | +Example — import all repos from a GitLab group: |
23 | 12 |
|
24 | 13 | ```console |
25 | | -$ env GITLAB_TOKEN=mySecretToken \ |
26 | | - /path/to/generate_gitlab.sh gitlab.mycompany.com desired_namespace |
27 | | -``` |
28 | | -
|
29 | | -To be executed from the path where the repos should later be stored. It will use |
30 | | -the current working directory as a "prefix" for the path used in the new config file. |
31 | | -
|
32 | | -Optional: Set config file output path as additional argument (_will overwrite_) |
33 | | -
|
34 | | -```console |
35 | | -$ env GITLAB_TOKEN=mySecretToken \ |
36 | | - /path/to/generate_gitlab.sh gitlab.mycompany.com desired_namespace /path/to/config.yaml |
37 | | -``` |
38 | | -
|
39 | | -**Demonstration** |
40 | | -
|
41 | | -Assume current directory of _/home/user/workspace/_ and script at _/home/user/workspace/scripts/generate_gitlab.sh_: |
42 | | -
|
43 | | -```console |
44 | | -$ ./scripts/generate_gitlab.sh gitlab.com vcs-python |
45 | | -``` |
46 | | -
|
47 | | -New file _vcspull.yaml_: |
48 | | -
|
49 | | -```yaml |
50 | | -/my/workspace/: |
51 | | - g: |
52 | | - url: "git+ssh://git@gitlab.com/vcs-python/g.git" |
53 | | - remotes: |
54 | | - origin: "ssh://git@gitlab.com/vcs-python/g.git" |
55 | | - libvcs: |
56 | | - url: "git+ssh://git@gitlab.com/vcs-python/libvcs.git" |
57 | | - remotes: |
58 | | - origin: "ssh://git@gitlab.com/vcs-python/libvcs.git" |
59 | | - vcspull: |
60 | | - url: "git+ssh://git@gitlab.com/vcs-python/vcspull.git" |
61 | | - remotes: |
62 | | - origin: "ssh://git@gitlab.com/vcs-python/vcspull.git" |
| 14 | +$ vcspull import gitlab my-group \ |
| 15 | + --workspace ~/code \ |
| 16 | + --mode org |
63 | 17 | ``` |
64 | | -
|
65 | | -[jq]: https://stedolan.github.io/jq/ |
66 | | -
|
67 | | -[curl]: https://curl.se/ |
68 | | -
|
69 | | -```` |
70 | | - |
71 | | -````{tab} Python |
72 | | -_Requires [requests] and [pyyaml]._ |
73 | | -
|
74 | | -This confirms file overwrite, if already exists. It also requires passing the protocol/schema |
75 | | -of the gitlab mirror, e.g. `https://gitlab.com` instead of `gitlab.com`. |
76 | | -
|
77 | | -```{literalinclude} ../../scripts/generate_gitlab.py |
78 | | -:language: python |
79 | | -``` |
80 | | -
|
81 | | -**Demonstration** |
82 | | -
|
83 | | -Assume current directory of _/home/user/workspace/_ and script at _/home/user/workspace/scripts/generate_gitlab.sh_: |
84 | | -
|
85 | | -```console |
86 | | -$ ./scripts/generate_gitlab.py https://gitlab.com vcs-python |
87 | | -``` |
88 | | -
|
89 | | -```yaml |
90 | | -/my/workspace/vcs-python: |
91 | | - g: |
92 | | - remotes: |
93 | | - origin: ssh://git@gitlab.com/vcs-python/g.git |
94 | | - url: git+ssh://git@gitlab.com/vcs-python/g.git |
95 | | - libvcs: |
96 | | - remotes: |
97 | | - origin: ssh://git@gitlab.com/vcs-python/libvcs.git |
98 | | - url: git+ssh://git@gitlab.com/vcs-python/libvcs.git |
99 | | - vcspull: |
100 | | - remotes: |
101 | | - origin: ssh://git@gitlab.com/vcs-python/vcspull.git |
102 | | - url: git+ssh://git@gitlab.com/vcs-python/vcspull.git |
103 | | -``` |
104 | | -
|
105 | | -[requests]: https://docs.python-requests.org/en/latest/ |
106 | | -[pyyaml]: https://pyyaml.org/ |
107 | | -
|
108 | | -```` |
109 | | - |
110 | | -### Contribute your own |
111 | | - |
112 | | -Post yours on <https://github.com/vcs-python/vcspull/discussions> or create a PR to add |
113 | | -yours to scripts/ and be featured here |
0 commit comments