Introducing badges for Gitlab

Have you ever tried to use more specialized badges for your private project in Gitlab?

Were you always envious of the Github projects with plenty of badges available out of the box?

What are badges?

Badges are those small images that shows information about your git project.

By default, Gitlab supports only two types of badges: Code Coverage and Pipeline Status.

Is this project for you?

Although it is possible to generate badges with other API’s such as shields.io, usually this process is not available in private repositories.

So if you are hosting a public project, this package is not specifically meant for you as you can workaround with other easier implementations.

But, if you are hosting a private project and don’t want to expose your project (Gitlab pages) or don’t want to risk exposing your credentials (API Requests), maybe this project is for you.

Another reason would be to avoid overloading servers (e.g. shields.io) with unnecessary requests for (re)creating badges.

The Project

The motivation for this project was getting to know a little bit more about Python and Software Engineering.

For this I wrote a complete CI pipeline, with static tests, unit tests, documentation (read the docs) and automatic versioning and releasing to PyPi.

The steps for this will be a topic for another post.

Is this project useful?

That’s questionable, if you like some decoration to your project yes, if you don’t care about it, this is an useless project. But for me it has been quite a huge learning step of building an open source project.

Usage

The documentation is much more detailed at Read The Docs (badges-gitlab.readthedocs.io), for this reason I will be very brief detailing the usage here.

This package was designed to run specifically as a Gitlab CI job, so the following steps should be performed to generate your static badges (snippet from .gitlab-ci.yml below):

variables:
    PRIVATE_TOKEN: $ACCESS_TOKEN
script:
	- pip install badges-gitlab
	- badges-gitlab
artifacts:
    when: always
    paths:
      - public/badges/*.svg

This “badges-gitlab CLI” will perform automatically the generation of the badges assuming that you passed a token for accessing your projects API.

After you run this job, the badges will be available at the public/badges folder and can be accessed though artifacts links, e.g.:

![License](../-/jobs/artifacts/main/raw/public/badges/license_name.svg?job=badges)

Further reading

If you want to access the source code of the project, it is available on Gitlab

https://gitlab.com/felipe_public/badges-gitlab

The documentation is available at:

https://badges-gitlab.readthedocs.io/en/latest/?badge=latest

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s