Get the FREE Ultimate OpenClaw Setup Guide →

gitlab-badge

npx machina-cli add skill grandcamel/GitLab-Assistant-Skills/gitlab-badge --openclaw
Files (1)
SKILL.md
9.2 KB

Badge Skill

Project badge management for GitLab using glab api raw endpoint calls.

Quick Reference

OperationCommand PatternRisk
List badgesglab api projects/:id/badges-
Get badgeglab api projects/:id/badges/:badge_id-
Create badgeglab api projects/:id/badges -X POST -f ...⚠️
Update badgeglab api projects/:id/badges/:badge_id -X PUT -f ...⚠️
Delete badgeglab api projects/:id/badges/:badge_id -X DELETE⚠️
Preview badgeglab api projects/:id/badges/render?...-
List group badgesglab api groups/:id/badges-

Risk Legend: - Safe | ⚠️ Caution | ⚠️⚠️ Warning | ⚠️⚠️⚠️ Danger

When to Use This Skill

ALWAYS use when:

  • User mentions "badge", "status badge", "coverage badge"
  • User wants to add badges to README
  • User wants pipeline or build status indicators
  • User mentions badge links or badge images

NEVER use when:

  • User wants labels on issues/MRs (use gitlab-label)
  • User wants status of pipelines (use gitlab-ci)
  • User wants project settings (use gitlab-repo)

API Prerequisites

Required Token Scopes: api

Permissions:

  • Read badges: Reporter+
  • Manage badges: Maintainer+

Badge Placeholders

GitLab supports placeholders in badge URLs:

PlaceholderDescription
%{project_path}Full project path (e.g., group/project)
%{project_id}Numeric project ID
%{project_name}Project name
%{project_namespace}Project namespace
%{default_branch}Default branch name
%{commit_sha}Current commit SHA

Available Commands

List Project Badges

# List all project badges
glab api projects/123/badges --method GET

# Using project path
glab api "projects/$(echo 'mygroup/myproject' | jq -Rr @uri)/badges"

List Group Badges

# List group badges (inherited by projects)
glab api groups/456/badges --method GET

Get Badge Details

# Get specific badge
glab api projects/123/badges/1 --method GET

Create Badge

# Create pipeline status badge
glab api projects/123/badges --method POST \
  -f link_url="https://gitlab.com/%{project_path}/-/pipelines" \
  -f image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg"

# Create coverage badge
glab api projects/123/badges --method POST \
  -f link_url="https://gitlab.com/%{project_path}/-/jobs" \
  -f image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/coverage.svg"

# Create custom badge (e.g., shields.io)
glab api projects/123/badges --method POST \
  -f link_url="https://opensource.org/licenses/MIT" \
  -f image_url="https://img.shields.io/badge/License-MIT-yellow.svg"

# Create named badge
glab api projects/123/badges --method POST \
  -f name="Build Status" \
  -f link_url="https://gitlab.com/%{project_path}/-/pipelines" \
  -f image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg"

# Create release badge
glab api projects/123/badges --method POST \
  -f link_url="https://gitlab.com/%{project_path}/-/releases" \
  -f image_url="https://gitlab.com/%{project_path}/-/badges/release.svg"

Update Badge

# Update badge URLs
glab api projects/123/badges/1 --method PUT \
  -f link_url="https://new-link.com" \
  -f image_url="https://new-image.com/badge.svg"

# Update badge name
glab api projects/123/badges/1 --method PUT \
  -f name="New Badge Name"

Delete Badge

# Delete badge
glab api projects/123/badges/1 --method DELETE

Preview Badge Rendering

# Preview how a badge would render
glab api "projects/123/badges/render?link_url=https://gitlab.com/%{project_path}&image_url=https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg" --method GET

Common Badge Templates

Pipeline Status Badge

# Link and image URLs
link_url="https://gitlab.com/%{project_path}/-/pipelines"
image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg"

glab api projects/123/badges --method POST \
  -f link_url="$link_url" \
  -f image_url="$image_url"

Markdown: [![pipeline status](https://gitlab.com/group/project/badges/main/pipeline.svg)](https://gitlab.com/group/project/-/pipelines)

Coverage Badge

link_url="https://gitlab.com/%{project_path}/-/jobs"
image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/coverage.svg"

glab api projects/123/badges --method POST \
  -f link_url="$link_url" \
  -f image_url="$image_url"

Release Badge

link_url="https://gitlab.com/%{project_path}/-/releases"
image_url="https://gitlab.com/%{project_path}/-/badges/release.svg"

glab api projects/123/badges --method POST \
  -f link_url="$link_url" \
  -f image_url="$image_url"

Custom Shields.io Badges

# License badge
glab api projects/123/badges --method POST \
  -f name="License" \
  -f link_url="https://opensource.org/licenses/MIT" \
  -f image_url="https://img.shields.io/badge/License-MIT-blue.svg"

# Version badge
glab api projects/123/badges --method POST \
  -f name="Version" \
  -f link_url="https://gitlab.com/%{project_path}/-/releases" \
  -f image_url="https://img.shields.io/badge/version-1.0.0-green.svg"

# Maintenance badge
glab api projects/123/badges --method POST \
  -f name="Maintained" \
  -f link_url="https://gitlab.com/%{project_path}" \
  -f image_url="https://img.shields.io/badge/Maintained%3F-yes-green.svg"

Common Workflows

Workflow 1: Set Up Standard Badges

project_id=123

# Pipeline status
glab api projects/$project_id/badges --method POST \
  -f name="Pipeline" \
  -f link_url="https://gitlab.com/%{project_path}/-/pipelines" \
  -f image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg"

# Coverage
glab api projects/$project_id/badges --method POST \
  -f name="Coverage" \
  -f link_url="https://gitlab.com/%{project_path}/-/jobs" \
  -f image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/coverage.svg"

# Latest release
glab api projects/$project_id/badges --method POST \
  -f name="Release" \
  -f link_url="https://gitlab.com/%{project_path}/-/releases" \
  -f image_url="https://gitlab.com/%{project_path}/-/badges/release.svg"

Workflow 2: Generate README Badge Markdown

# Get all badges and generate markdown
glab api projects/123/badges | \
  jq -r '.[] | "[![\(.name // "badge")](\(.rendered_image_url))](\(.rendered_link_url))"'

Workflow 3: Copy Badges to Another Project

source_project=123
target_project=456

# Get badges from source
badges=$(glab api projects/$source_project/badges)

# Create in target (using placeholders, so they'll work for the new project)
echo "$badges" | jq -c '.[]' | while read badge; do
  link_url=$(echo "$badge" | jq -r '.link_url')
  image_url=$(echo "$badge" | jq -r '.image_url')
  name=$(echo "$badge" | jq -r '.name // empty')

  glab api projects/$target_project/badges --method POST \
    -f link_url="$link_url" \
    -f image_url="$image_url" \
    ${name:+-f name="$name"}
done

Workflow 4: Audit Badge Configuration

# List all badges with rendered URLs
glab api projects/123/badges | \
  jq -r '.[] | "ID: \(.id)\n  Name: \(.name // "unnamed")\n  Image: \(.rendered_image_url)\n  Link: \(.rendered_link_url)\n"'

Workflow 5: Replace All Badges

project_id=123

# Delete existing badges
glab api projects/$project_id/badges | jq -r '.[].id' | while read badge_id; do
  glab api projects/$project_id/badges/$badge_id --method DELETE
done

# Create new badges
glab api projects/$project_id/badges --method POST \
  -f name="Build" \
  -f link_url="https://gitlab.com/%{project_path}/-/pipelines" \
  -f image_url="https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg"

Troubleshooting

IssueCauseSolution
Badge not showingURL incorrectCheck rendered URLs in API response
403 ForbiddenNot maintainerNeed Maintainer+ role
Placeholder not replacedWrong syntaxUse %{placeholder} format
Coverage badge shows "unknown"No coverage reportConfigure CI to output coverage
Pipeline badge shows old statusCacheBadge images may be cached

Badge Best Practices

  1. Use placeholders: Make badges portable between projects
  2. Name your badges: Helps identify them in the list
  3. Link to relevant pages: Badge clicks should go somewhere useful
  4. Keep badges updated: Remove stale badges
  5. Use consistent styling: Mix of GitLab and shields.io can look inconsistent

Related Documentation

Source

git clone https://github.com/grandcamel/GitLab-Assistant-Skills/blob/main/skills/gitlab-badge/SKILL.mdView on GitHub

Overview

Manage GitLab project and group badges via the GitLab API using glab. This skill covers listing, creating pipeline and coverage badges, updating or deleting badges, and previewing badge renders for README inclusion.

How This Skill Works

Glab api calls map to GitLab REST endpoints: GET to list or get a badge, POST to create, PUT to update, DELETE to remove, and render to preview. Badges can use placeholders like %{project_path} to assemble dynamic URLs and images.

When to Use It

  • You need to list all badges for a project (or for a group so badges are inherited by projects).
  • You want to add a pipeline status or coverage badge to a README.
  • You need to update or delete an existing badge.
  • You want to preview how a badge will render before publishing.
  • You need to review group badges that apply to multiple projects.

Quick Start

  1. Step 1: Ensure you have a GitLab access token with api scope and the glab CLI installed.
  2. Step 2: Choose an operation (list, create, update, delete, or preview) and run the matching glab api command.
  3. Step 3: For create/update, pass -f fields (link_url, image_url, optional name) and verify the result with a GET or preview.

Best Practices

  • Use an API token with the api scope; manage permissions as needed (Read badges: Reporter+, Manage badges: Maintainer+).
  • Prefer descriptive badge names (e.g., Build Status, Coverage) to keep READMEs clear.
  • Leverage placeholders like %{project_path} and %{default_branch} for reusable badges across projects.
  • Validate image_url and link_url targets before creating, and test via GET to confirm.
  • Test badge changes in a staging project before updating production READMEs.

Example Use Cases

  • glab api projects/123/badges --method GET
  • glab api projects/123/badges --method POST -f link_url='https://gitlab.com/%{project_path}/-/pipelines' -f image_url='https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg'
  • glab api projects/123/badges --method POST -f link_url='https://gitlab.com/%{project_path}/-/jobs' -f image_url='https://gitlab.com/%{project_path}/badges/%{default_branch}/coverage.svg'
  • glab api projects/123/badges --method PUT -f link_url='https://new-link.com' -f image_url='https://new-image.com/badge.svg'
  • glab api projects/123/badges/render?badge_id=1&format=svg

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers