|  | 
|  | 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 | 
0 commit comments