Building software is a hefty task, but managing software is the real key.
Git is an open-source project, which aims to manage software development projects and their files as they change over time. Git stores this information in a set of a data structure called a repository.
A git repository is a primary place where developers share, store, test, and collaborates on web projects.
Let’s Suppose a GitLab has more than a thousand projects, more than 500 Users, and more than 200 Groups, and you want to retrieve some details from GitLab. Details such as a list of the project with Name, commit, storage, and a list of Groups and Users.
Getting all this done from GitLab GUI is a nightmare.
You can use GitLab API, and here we will learn how to get these data from GitLab in seconds or minutes depending upon the size of data, using a Python Module of GitLab. This module uses the GitLab API.
In this blog will learn how to install and set up this GitLab Command Line (CLI) and see some examples:-
We will need to create an access token to access the GitLab using API.
You will need Python 3.6+ version for this.
1. Install using pip
$ sudo pip install --upgrade python-gitlab
2. Clone the gitlab CLI code and install it.
$ git clone https://github.com/python-gitlab/python-gitlab $ cd python-gitlab $ sudo python setup.py install
3. Check the installation by running the following command:
$ gitlab --help
We will need to configure the GitLab CLI by using an Access Token created in Step 1.
Create a configuration by file at /etc/ path.
$ sudo nano /etc/python-gitlab.cfg
Paste the following code in the python-gitlab.cfg file
[global]
default = somewhere
ssl_verify = true
timeout = 60
[somewhere]
url = https://www.gitlab.com
private_token = BQdERfKksnf4xViZjNyz
api_version = 4
per_page = 10
Replace the GitLab URL if you are using GitLab self-managed instance.
Replace the private_token with your Access Token.
Check the Gitlab CLI configuration by running the following command:
$ gitlab project list
This command will give you the data such as the id and path of some projects. (10 projects as mentioned in the config file)
id: 26857216
path: road_damaged_detection_model
id: 26857212
path: test
id: 26857192
path: robber-run
id: 26857171
path: codes.assign
id: 26857170
path: fad6-role
id: 26857150
path: TestAssessment
id: 26857131
path: exam_17t1021123
id: 26857127
path: hakaton
id: 26857126
path: hello
id: 26857099
path: dump_device_realme_rmx2076
$ gitlab project list
If you are using GitLab.com then the below command will show you any project which is publicly accessible.
$ gitlab project list --owned true
This command will show your projects present in your account.
$ gitlab project list --owned true --all
This will provide you with a list of all your projects.
Similarly, there are lots of commands to get the names of users, groups, etc. You can create and update the data of projects as well. You can check other options by running --help commands.
$ gitlab --help
We have learned how to install and configure a Python Module of Gitlab CLI. This CLI can create, update and access the data from GitLab.