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

Number support for version color formatter #1615

Merged
merged 2 commits into from
Mar 29, 2018

Conversation

PyvesB
Copy link
Member

@PyvesB PyvesB commented Mar 27, 2018

This pull request is related to discussions in #1599.

Tests to cover cases where the version is provided as a numerical value were added. I thought of several different ways of tackling the implementation and went with one, but a more experienced Javascript reviewer may have some better ideas. 👍

@shields-ci
Copy link

shields-ci commented Mar 27, 2018

Messages
📖

✨ Thanks for your contribution to Shields, @PyvesB!

Generated by 🚫 dangerJS

@PyvesB PyvesB mentioned this pull request Mar 27, 2018
@@ -7,11 +7,13 @@
const moment = require('moment');

function version(version) {
let first = version[0];
// The passed in version may or may not already be a string. See #1599.
const stringifiedVersion = '' + version;
Copy link
Member

Choose a reason for hiding this comment

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

This works! Another way I'm also fine with is like this:

version = '' + version;

Copy link
Member Author

Choose a reason for hiding this comment

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

I code a lot in Java and we tend to avoid this, but I'm happy to use it here! 😄

Copy link
Member

Choose a reason for hiding this comment

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

Yea… it's a matter of style. The language treats them as let variables, though if you want you can tell eslint not to let you reassign them. The advantage of reassigning them is that it prevents you from accidentally using the unmodified value, and I think reassigning them once at the top of the function is not so confusing. Though I could be convinced otherwise. 😁

@@ -7,11 +7,13 @@
const moment = require('moment');

function version(version) {
let first = version[0];
// The passed in version may or may not already be a string. See #1599.
Copy link
Member

Choose a reason for hiding this comment

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

Since this can be inferred from the code itself, and tests will fail if this code is changed (which is really the best thing!) this comment isn't needed.

Copy link
Member

@RedSparr0w RedSparr0w left a comment

Choose a reason for hiding this comment

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

Nice work, looks good to me!

Side note: on mobile right now so can't check, but does version need to be changed to a string with the updated regex?

@PyvesB
Copy link
Member Author

PyvesB commented Mar 28, 2018

@RedSparr0w I thought the same initially, but actually you can't cover edge cases such as floating point numbers smaller than one without the string conversion. 0.1 would show as blue for instance, whereas we should actually treat it as a beta version.
In the end I left the updated regex anyway, as it's slightly more concise and has better performance. 😉

@PyvesB PyvesB changed the title Number support to version color formatter Number support for version color formatter Mar 28, 2018
@PyvesB PyvesB added the core Server, BaseService, GitHub auth, Shared helpers label Mar 28, 2018
@PyvesB PyvesB merged commit 16eea6d into badges:master Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth, Shared helpers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants