-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[badge-json] new "badge-json" service #1525
Conversation
route: /^\/json\/(https?.+)\.(svg|png|gif|jpg|json)$/ added documentation to usage.js (with json-badge-maker) tweaked usage.js oh-so-slightly to better separate "static", "dynamic", and "json" added "style" parameter to parameter list & moved rendered styles from above the list to below removed the ginormous margin-left: 25% style from ul -> now applies to ul.options (was only one UL in in documentation) renamed duplicate "miscellaneous" id to "miscellaneous2"
Generated by 🚫 dangerJS |
question: how do I write a unit test that tests the style/template, colorA, & colorB. |
@bkdotcom There is a way to verify colors in service tests using this approach ( shields/service-tests/github.js Lines 38 to 40 in 8ad176d
Is it helpful? |
@platan Thanks! so.. I committed an updated unit test and now one of the circleci tests fails with a seemingly unrelated sunspots? Is there a way to rerun the test without a commit? |
You can close and reopen PR to run CI again. Does anyone know a better way? |
Thanks for the PR, I just re-ran the test, |
added notes to "dynamic" badge (what the params are)
thought 💡: Right now the JSON can contain "colorA" and "colorB" (which matches the optional url param names). What if instead, the JSON uses less ambiguous "labelBackgroundColor" and "valueBackgroundColor" (or "labelBgColor" / "valueBgColor").. The thought being that at some point the service could also specify "labelTextColor" / "valueTextColor (or instead something like boolean "labelTextInvert" / "valueTextInvert" which would use black text rather than white) |
This is a really interesting idea! I like it. I'll leave some comments on the specifics. @bkdotcom Seems like you're up on React! I wonder if we could take this opportunity to continue to break features out onto separate pages. What do you think about moving all the docs on Badge JSON to a new modal? There's a lot of detail and I think it would be good to have a chance to explain it further, and also why you might choose it when compared to other options. Typically the way we've handled this in the past is to have services redirect to our static badge. That does have an advantage over this badge JSON approach, which is that Shields doesn't have to make any network requests, making it much more performant on our end. However, this syntax is really nice. Much clearer. We've talked often about a more computer-friendly version of the static badge. Maybe we could take the badge JSON format developed here, and provide a second way to use it at something like That way, services only use this one (that requires us to fetch the data) if they can't easily pull off the redirect. Does that make sense? |
You can push a "null edit" – basically a commit that changes whitespace or some other meaningless thing. If master has moved, merging that would accomplish it too. |
I'd like to move away from
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this!
return; | ||
} | ||
try { | ||
let data = JSON.parse(buffer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this transformation code into its own function in lib/
, and make a list there of the supported parameters? It's great to have it in the web page, but feel like it ought to live with the code, too. By breaking this out into a separate (pure) function, it becomes very easy to test all this logic using data-driven tests. You'll see we've a bunch of these kind of tests now, using sazerac.
@@ -7545,6 +7545,71 @@ camp.route(/^\/maven-metadata\/v\/(https?)\/(.+\.xml)\.(svg|png|gif|jpg|json)$/, | |||
}); | |||
})); | |||
|
|||
// badge-json url | |||
camp.route(/^\/json\/(https?.+)\.(svg|png|gif|jpg|json)$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in #1525 (comment) let's make two or maybe three ways of leveraging the JSON functionality.
I'd prefer we add support for three endpoints:
/badge/dynamic/json-badge-data/https/example.com/info.json.svg
(as an alternative to /json`)/badge/dynamic/json-badge-data.svg?url=https%2Fexample.com%2Finfo.json
/badge/static.svg?badgeData=...
These support the more efficient static route for servers capable of building a redirect. That route can also be used in a dynamic web page, which is really cool! Simultaneously they make the "static" and "dynamic" distinctions very clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
sidenote
I'm not much of a fan of the https/example.com
endpoints,
just feels strange without the https://
:
/badge/dynamic/json-badge-data/https://example.com/path/to.json.svg
/badge/dynamic/json-badge-data/https/example.com/path/to.json.svg
but we have a few that way already so for the sake of consistency it's probably best to continue that pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea… I find it a little weird too. Though, I think a colon in a path is supposed to be URL encoded. Maybe we could just make the scheme optional and default to https
? That way it would disappear in most cases…
.expectJSON({ | ||
name: 'test', | ||
value: 'success', | ||
colorB: '#C001E0' // colorB param |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to keep some tests here, though it'll be possible to write some of these more simply as unit tests if the transformation logic is moved from server.js
to a function in lib/
.
Realized the semantic color discussion has been started: #1522. |
That's a really interesting distinction to make between the user of the badge and the data provider. It's a concern unique to the dynamic json-badge-data badges, since redirects to static badges are probably not going to be customizable. I really like your idea that the user should be able to customize the presentation. Also agreed, you're onto something about Re links, the most likely case is a single link for the whole badge. It didn't occur to me it was possible to link the message and not the label. I agree an array of links is not at all intuitive. Another option might be: Links both sides: "link": "http://example.com" Links one side: "link": { "message": "http://example.com" } Links one side: "link": { "label": "http://example.com/1", "message": "http://example.com/2" } I quite like the elegance of that. However, |
Hi! Before you pick this up again, could you please merge in master, and move |
There are a lot of open PRs with code that needs reviewing. To help the maintainers identify the actionable PRs that are on a critical path, I'm marking this PR "on hold." It's not dead and can or will be picked up at some point. Work on this PR is blocked until a port of the existing dynamic badge goes through. I'm prioritizing that behind #2284 which may inform it and will create some conflicts in server.js. This PR then needs to be worked on a bit, in particular with some thought to the API design, and then rewritten using new-style services. |
This reimplements the idea @bkdotcom came up with in #1519, and took a stab at in #1525. It’s a really powerful way to add all sorts of custom badges, particularly considering [tools like RunKit endpoints and Jupyter Kernel Gateway](#2259 (comment)), not to mention all the other ways cloud functions can be deployed these days. Ref #1752 #2259
Closing in favor of #2473. |
This reimplements the idea @bkdotcom came up with in #1519, and took a stab at in #1525. It’s a really powerful way to add all sorts of custom badges, particularly considering [tools like RunKit endpoints and Jupyter Kernel Gateway](#2259 (comment)), not to mention all the other ways cloud functions can be deployed these days.
fixes #1519
closes #1752
route: /^/json/(https?.+).(svg|png|gif|jpg|json)$/
added documentation to usage.js (with json-badge-maker)
a few tweaks to documentation
Screenshot of updated docs: