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

Fix issue with custom logo generation in badge-maker (#9644) #9645

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zavoloklom
Copy link

  • allow logo, logoPosition, logoWidth, and links as expected keys

  • add validation for logo, logoPosition, logoWidth, and links keys

  • add validation tests

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2023

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

Generated by 🚫 dangerJS against d481672

* allow `logo`, `logoPosition`, `logoWidth`, and `links` as expected keys

* add validation for `logo`, `logoPosition`, `logoWidth`, and `links` keys

* add validation tests
@chris48s
Copy link
Member

chris48s commented Oct 9, 2023

Thanks. I will have a look over this but first I really need to re-read #4947 From memory we never progressed it because there were some things we didn't really reach an agreement on. #9476 may decide one of them for us. Adding just base64 is a reasonable first step, but I want to be sure we're not doing it in a way that impacts how we would want to add named logos.

@zavoloklom
Copy link
Author

Thanks. I will have a look over this but first I really need to re-read #4947 From memory we never progressed it because there were some things we didn't really reach an agreement on. #9476 may decide one of them for us. Adding just base64 is a reasonable first step, but I want to be sure we're not doing it in a way that impacts how we would want to add named logos.

Thank you for response!
I had a look over these discussions and I hope you'll pick a solution.
I also wonder is it appropriate to add yargs as dependency to badge-maker and setup cli to work with all options? If so - i can add commit here or create new PR.

@chris48s
Copy link
Member

chris48s commented Oct 9, 2023

At some point in the past I looked at adopting a proper argument parsing library like yargs or commander. Because of the slightly non-standard way the arguments are currently parsed (positional argument 5 can be either style or labelColor, depending on whether it starts with an @ or not), we'd have to make a non backwards-compatible change to the CLI in order to do that.

That doesn't mean we can't do it. It would make much more sense to have flags like --labelColor blue or whatever, rather than all positional args.

Lets not load it into this PR though. This PR is a relatively small change. Re-working the CLI is going to be a bigger job, so lets not block this PR on doing that as well.

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to update the documentation in
https://github.com/badges/shields/tree/master/badge-maker#format
to cover the new params.

@@ -4,6 +4,10 @@ interface Format {
labelColor?: string
color?: string
style?: 'plastic' | 'flat' | 'flat-square' | 'for-the-badge' | 'social'
logo?: string
Copy link
Member

@chris48s chris48s Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this layer, lets call this param logoBase64 instead of just logo so that it is not ambiguous with named logos when we add that. It can stay as logo at the next layer down though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking about this again.. in the endpoint schema, we expose logoSvg (which is literally an SVG as a string) and namedLogo. I wonder if we should just expose logoSvg here and encode it for the user to keep the package API consistent with the endpoint schema. Base64 is useful in URLs, but we don't have that constraint here. The only downside is we can't accept encoded PNG logos.

I am being quite indecisive here 🤔

Comment on lines +8 to +9
logoPosition?: number
logoWidth?: number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a strong case for exposing logoPosition and logoWidth in the badge-maker package. logoPosition is not exposed at all by shields.io. logoWidth kind of is available by accident but it is not documented and we may deprecate or quietly remove it at some point.

logo?: string
logoPosition?: number
logoWidth?: number
links?: Array<string>
Copy link
Member

@chris48s chris48s Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding links is issue #4949

The reason this has been sitting around for a while is because links is implemented internally as an array for historical reasons, rather than using the label and message terminology, but we really wanted to add it as labelLink and messageLink to match the other params.

Tbh, I think I've changed my mind on this. Lets just get it done and expose it as links[] for now. If we want to change it, it is a library and we can version it. We can always deprecate this format at some later date.

})

if ('links' in format) {
if (!Array.isArray(format.links)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we validate that the links array has a max length of 2

@chris48s chris48s added the npm-package Badge generation and badge templates label Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm-package Badge generation and badge templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants