Fetch using Gitlab API
Fetch using Gitlab API
Motivation
I use gitlab, and I have many repos that I need to track on daily basis, or even more than once per day. I found it so tyring first of all to clone all those repos when I change my working machine, and then to keep all these repos up to date. For that reason I began to write an automation script to do the boring tasks of my shoulders.
Process
I started with a simple bash script, which go through a for-loop and do the stuff, where the paths of the repos must be hard-coded.
This was fast and worked for a while, but when I got to work with multiple projects, and my co-workers added/removed/renamed a repo, it was sill manual work to update the script, and as boring as I am, I did not like it, and looked for a lazy way to automate the process, and opened the Gitlab API-Documentation, where the fun started.
Solution Idea
A python script to talk to the gitlab API, and use the /projects
end point to access the repos.
Requirements:
- Gtilab Token: create a private token first to use it accessing the API as explained in the docs.
- Virtual access to the repos (e.g.: gitlab.com)
Optional:
- Pipenv to install the dev-dependencies:
brew install pipenv
First Try: argparse
The first try was to pass the options as arguments to the script:
Usage:
usage: main.py [-h] [--token TOKEN] [--url URL]
optional arguments:
-h, --help show this help message and exit
--token TOKEN, -t TOKEN
Gitlab private Token
--url URL, -u URL Gitlab URL<Paste>
Second Try: JSON
Then I thought that the configurations must be more flexible, so the use of a separate config file make sense.
Full project repository can be found here
Usage
python main.py