Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing to "omit" a character when pulling data for dynamic badges #10866

Closed

Conversation

ThibaudMZN
Copy link

@ThibaudMZN ThibaudMZN commented Feb 2, 2025

Copy link
Contributor

github-actions bot commented Feb 2, 2025

Messages
📖 ✨ Thanks for your contribution to Shields, @ThibaudMZN!

Generated by 🚫 dangerJS against 6d5fe8e

@chris48s
Copy link
Member

chris48s commented Feb 3, 2025

Hi. We're not planning to add any more additional formatting options to the dynamic badges so I'm going to close this one.

In general, if you've outgrown the options available with the dynamic badges, the next level for customisation is the endpoint badge https://shields.io/badges/endpoint-badge

@chris48s chris48s closed this Feb 3, 2025
@ThibaudMZN
Copy link
Author

That's really unfortunate, though I understand the reasoning behind it.

Unfortunately, the application I want to use this for has really strict security policy and I won't be able to deploy a specific route to serve those versions.

Thanks anyway !

@chris48s
Copy link
Member

chris48s commented Feb 3, 2025

A couple of suggestions for the specific thing you are trying to achieve:

One of the most popular ways to make an "endpoint" is to write a static file to your repo using a GitHub action. So you write a GitHub action that reads in package.json, performs whatever pre-processing you want, and generates a JSON document using the endpoint format. So { "schemaVersion": 1, "label": "react", "message": "18.3.0", "color": "blue" } or whatever. Then the action commits that file back to your repo and then your badge URL is https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fupptime%2Fupptime%2Fmaster%2Fapi%2Fgoogle%2Fuptime.json or whatever. This way, you get complete customisation - the world is your oyster. Also you don't need to add any endpoint to your application. If shields.io can see the repo where your package.json is, we can see that file too.

Another thing that might be worth looking at:
If your application has a lockfile, you can get the resolved version from package-lock.json using the dynamic JSON badge. So for example
https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fbadges%2Fshields%2Frefs%2Fheads%2Fmaster%2Fpackage-lock.json&query=%24.%5B%27node_modules%2Freact%27%5D.version
That is the resolved version, which is not the exact same thing as "the constraint with special characters stripped", but might actually be what you want? That would allow you to have a constraint in the manifest but show the resolved version on a badge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants