Add new placeholders for group/project badges
Problem to solve
I want to be able to link a coverage badge to a report that is published with GitLab Pages. Unfortunately, there is no way to set this generically at the group level using the current placeholders.
%{project_path}
includes the project's namespace, so there's no way to generate a URL like this:
http://<project_namespace>.pages.<my_gitlab_server>/<project_name>/coverage
Proposal
Add the following new placeholders:
-
%{project_namespace}
- the group/namespace of the project -
%{group_name}
- the name of the group -
%{gitlab_server}
(or similar) - e.g. example.com -
%{gitlab_pages_domain}
(or similar) - e.g. pages.example.io
Links / references
https://docs.gitlab.com/ee/user/project/badges.html#placeholders
Implementation Guide
- Update the
app/models/badge.rb
to include new placeholders (project_namespace
,group_name
, etc.) in thePLACEHOLDERS
hash, e.g.:
'project_namespace' => ->(project) { project.project_namespace.to_param },
'group_name' => ->(project) { project.group&.to_param },
'gitlab_server' => -> { Gitlab.config.gitlab.dig('host') },
'gitlab_pages_domain' => -> { Gitlab.config.pages.dig('host') },
- Update the
app/assets/javascripts/badges/constants.js
, to add support for the new placeholders. - Add relevant specs for the new changes
- Update documentation for new placeholders (
doc/api/group_badges.md
,doc/api/project_badges.md
anddoc/user/project/badges.md
).
Edited by Christina Lohr