-
-
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
Consistent version formatting #1246
Conversation
Nice! Looking forward to giving this a closer read. |
@paulmelnikow said there: "I'd probably start by approaching this the other way, and matching version types that look terrible with a v. For example, anything that starts with a xxxx-yy-zz, which is clearly a date, or anything which does not start with a number."
|
It was already covered previously, and I have not altered that behaviour.
They could easily be added. Nevertheless, are they often used in version numbers? |
Stumbled upon this Facebook repo on random in the dependency graph: |
I have added the |
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.
Looks good!
lib/text-formatters.js
Outdated
@@ -63,6 +63,17 @@ function omitv(version) { | |||
return version; | |||
} | |||
|
|||
// Add a starting v to the version number if needed. | |||
const ignoredVersionPatterns = /^[^0-9]+|[0-9]{4}-[0-9]{2}-[0-9]{2}/; |
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.
^[^0-9]+
<- the trailing +
is not needed.
Could you comment here that [0-9]{4}-[0-9]{2}-[0-9]{2}
is to catch yyyy-mm-dd? It's clear from the tests, but it still helps here to understand the code.
lib/text-formatters.js
Outdated
@@ -63,6 +63,17 @@ function omitv(version) { | |||
return version; | |||
} | |||
|
|||
// Add a starting v to the version number if needed. | |||
const ignoredVersionPatterns = /^[^0-9]+|[0-9]{4}-[0-9]{2}-[0-9]{2}/; | |||
function addv(version) { |
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.
Double negatives are hard to understand, so when it's possible to rewrite an if
/else
to eliminate them, I tend to do that. Mercifully, we now have String#startsWith. I think this is a bit clearer that way.
if (version.startsWith('v') || ignoredVersionPatterns.test(version)) {
return version;
} else {
return `v${version}`;
}
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 point, I should have been more clever than just copy pasting the leftovers of the old function. ^^
lib/color-formatters.js
Outdated
@@ -1,6 +1,6 @@ | |||
/** | |||
* Commonly-used functions for determining the colour to use for a badge, | |||
* including colours based off download count, version number, etc. | |||
* including colours based off download count, version colour, etc. |
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.
Not sure why this was changed. It seems like it was more grammatical before.
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.
I must have misread the first part of the sentence... Will revert this!
given('6.0-SNAPSHOT'), | ||
given('1.0.1-dev'), | ||
given('2.1.6-prerelease'), | ||
]).expect('orange'); |
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.
❤️
@@ -30,7 +30,7 @@ t.create('search snapshot version not in latestSnapshot') | |||
.get('/nexus/service/local/lucene/search') | |||
.query({g: 'com.progress.fuse', a: 'fusehq'}) | |||
.reply(200, '{ "data": [ { "version": "7.0.1-SNAPSHOT" } ] }')) | |||
.expectJSON({ name: 'nexus', value: '7.0.1-SNAPSHOT' }); | |||
.expectJSON({ name: 'nexus', value: 'v7.0.1-SNAPSHOT' }); |
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.
I wonder if we should omit v
's on SNAPSHOT versions. Thoughts?
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.
A quick search in Google shows that quite a few people tend to add a leading v
with SNAPSHOT versions. Almost certainly not a majority, but I would be inclined to say we should add it and also be consistent with other keywords such as "BETA", "APLHA", etc. But I'm happy either way. 😉
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.
I'm fine with leaving them in. We can see what people say once it's changed!
} else { | ||
return { version: version, color: 'blue' }; | ||
return 'blue'; |
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.
Thank you for separating these responsibilities. 🍻
lib/text-formatters.js
Outdated
const ignoredVersionPatterns = /^[^0-9]+|[0-9]{4}-[0-9]{2}-[0-9]{2}/; | ||
// Add a starting v to the version unless: | ||
// - it does not start with a digit | ||
// - it is a date (yyyy-mm-dd) |
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.
👍
Do you feel like I should give all of |
Feel free to do so. But as you said "We can see what people say once it's changed!", and quickly iterate if they are unhappy about some of the changes. 😉 |
A few service tests failing locally, but nothing related to this change. |
Thanks so much for this! There might be a little bit of cleanup to do. For example, #1268 which was merged just before this, prepends a |
I'll go through recent changes and submit a small pull request to clean up anything that needs to be. |
Hello,
This is a pull request related to issue #1181. It aims at providing greater consistency for badges related to versions. It's a slightly ambitious pull request, I'll try to give a clear outline of what was done:
version
function incolor-formatters
was previously returning the colour of the badge, but also its text with a leading v. It was broken down into two separate functions and the text formatting part was moved totext-formatters
, where it really belongs.color-formatters.spec
andtext-formatters.spec
, using Sazerac.ignoredVersionPatterns
pattern.beta
,alpha
orsnapshot
. Of course, this list can easily be extended.versionText
andversionColor
functions. There are a few rare exceptions, for instance in cases where the data returned by the service's API allows to figure things out without relying on any parsing/pattern matching (eg.badgeData.colorscheme = prerelease ? 'orange' : 'blue';
, whereprerelease
is determined from an API's response).As always, looking forward to feedback!☺️
Cheers,
Pyves