Custom Shields with Shields IO

πŸ“˜

Request a shield for your public repository

We can provide one for you; request one on the PR Cycle Time Shield Request page. Computed on our Faros CE instance :)

946

On our Faros CE GitHub repository, you may have noticed the PR Cycle Time shield in the README file. It is powered by our Faros CE instance through shields.io. Here are the steps to create your own, once you have ingested the data needed to compute the shield value.

  1. Ensure sharing is enabled on your metabase instance
  2. Create a question in Metabase that computes the desired value and save it
  3. Create a public link for that question (arrow moving up to the right); save the id in the public link
  4. Head to shields.io to build your dynamic shield:
    i) data url is based on this Metabase API call; choose json for the export format
    ii) data type is label
    iii) query is based on the output of the API call (see example below)

Click Make Badge and here is your URL!

As an example, our question query is (with the 2 variables tied to field filters with default values):

SELECT ROUND(CAST(EXTRACT(epoch FROM (
SELECT 
    justify_interval(
      avg(
        "vcs_PullRequest"."mergedAt" - "vcs_PullRequest"."createdAt"
      )
    ) as cycle_time 
  FROM 
    "vcs_PullRequest" 
  JOIN "vcs_Repository" ON "vcs_PullRequest"."repository" = "vcs_Repository"."id"
  WHERE 
    "vcs_PullRequest"."mergedAt" IS NOT NULL AND {{mergedAt}} AND {{repositoryName}}
) / 3600 / 24) as decimal), 1) as pr_cycle_time

The public link for that question after sharing it is:

https://metabase.faros-ce.onplural.sh/public/question/7fc36121-3005-49b8-aa14-02d29b53e247

The Metabase API call is therefore:

https://metabase.faros-ce.onplural.sh/api/public/card/7fc36121-3005-49b8-aa14-02d29b53e247/query/json

and returns

[
{"pr_cycle_time":0.6}
]

Our dynamic shield URL is therefore:

https://img.shields.io/badge/dynamic/json?color=informational&label=PR%20Cycle%20Time&query=%24%5B0%5D.pr_cycle_time&suffix=%20days&url=https%3A%2F%2Fmetabase.faros-ce.onplural.sh%2Fapi%2Fpublic%2Fcard%2F7fc36121-3005-49b8-aa14-02d29b53e247%2Fquery%2Fjson
  • Notice all parameters are URL-escaped
  • Query is $.pr_cycle_time (JSONPath)