Add variables %{group_name} and %{project_name} to badges

Problem to solve

As a group maintainer, I can not set group badges that redirect to project Gitlab pages.

Further details

Assume that all projects in a group expose coverage reports in exactly the same way: via a job named "coverage" and public pages called "coverage/index.html". (This is a real case, we did manage to achieve this)

In order to avoid setting a project specific badge on each and every project settings, we have set a common group badge:

  • Link: see below.
  • Badge image URL: https://gitlab.anevia.com/%{project_path}/badges/%{default_branch}/coverage.svg?job=coverage

The link for a gitlab page is under the format: http://%s.pages.anevia.com/%s with %s respectively being the group and the project name.

Yet, we can not set the link to that format as we are missing both key variables.

Proposal

  • Add %{group_name} as an available variable that always expand to the group name.

  • Add %{project_name} as an available variable that always expand to the project name.

This enables use to set link to http://%{group_name}.pages.anevia.com/%{project_name}/coverage/index.html for our example above.

Workaround

Create and host an external webserver that has an endpoint such as /redirect/%{project_path} to http://%{group_name}.pages.anevia.com/%{project_name} by splitting %{project_path} into 2.

We have added such an endpoint to our internal gitlab helper API server.

Links / references

Similar but not identical to #49295 (moved) Expands upon #41174 (closed)