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

Consistent version formatting #1246

Merged
merged 6 commits into from
Nov 11, 2017
Merged

Conversation

PyvesB
Copy link
Member

@PyvesB PyvesB commented Nov 2, 2017

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:

  • the version function in color-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 to text-formatters, where it really belongs.
  • unit tests were added for these two functions in color-formatters.spec and text-formatters.spec, using Sazerac.
  • as discussed in Leading "v" is forcefully added in github release badges  #1181, the leading v was omitted for xxxx-yy-zz date patterns. Any future exceptions can easily be added to the ignoredVersionPatterns pattern.
  • the badge colour was previously switched to orange if a hyphen was found in the version string. This didn't seem ideal, instead pattern matching is done to find keywords such as beta, alpha or snapshot. Of course, this list can easily be extended.
  • all badges related to versions now use the versionText and versionColor 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';, where prerelease is determined from an API's response).

As always, looking forward to feedback! ☺️

Cheers,

Pyves

@paulmelnikow
Copy link
Member

Nice! Looking forward to giving this a closer read.

@paulmelnikow paulmelnikow added core Server, BaseService, GitHub auth, Shared helpers service-badge New or updated service badge labels Nov 3, 2017
@tooomm
Copy link
Contributor

tooomm commented Nov 4, 2017

@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."
Is that second part covered here already?

  • the badge colour was previously switched to orange if a hyphen was found in the version string. This didn't seem ideal, instead pattern matching is done to find keywords such as beta, alpha or snapshot. Of course, this list can easily be extended.

development, prerelease and pre-release might be suitable keywords too

@PyvesB
Copy link
Member Author

PyvesB commented Nov 4, 2017

Is that second part covered here already?

It was already covered previously, and I have not altered that behaviour.

development, prerelease and pre-release might be suitable keywords too

They could easily be added. Nevertheless, are they often used in version numbers?

@tooomm
Copy link
Contributor

tooomm commented Nov 5, 2017

Nevertheless, are they often used in version numbers?

Stumbled upon this Facebook repo on random in the dependency graph:
https://github.com/facebookarchive/esprima/releases

@PyvesB
Copy link
Member Author

PyvesB commented Nov 5, 2017

I have added the dev and pre keywords as matchers as well, that should do the trick.

Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

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

Looks good!

@@ -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}/;
Copy link
Member

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.

@@ -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) {
Copy link
Member

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}`;
}

Copy link
Member Author

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. ^^

@@ -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.
Copy link
Member

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.

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 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');
Copy link
Member

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' });
Copy link
Member

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?

Copy link
Member Author

@PyvesB PyvesB Nov 9, 2017

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. 😉

Copy link
Member

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';
Copy link
Member

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. 🍻

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)
Copy link
Member

Choose a reason for hiding this comment

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

👍

@paulmelnikow
Copy link
Member

Do you feel like I should give all of server.js another once-over relative to this change? Or are you comfortable with it as it is?

@PyvesB
Copy link
Member Author

PyvesB commented Nov 10, 2017

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. 😉

@paulmelnikow
Copy link
Member

A few service tests failing locally, but nothing related to this change.

@paulmelnikow paulmelnikow merged commit 7039e68 into badges:master Nov 11, 2017
@paulmelnikow
Copy link
Member

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 'v'.

@PyvesB
Copy link
Member Author

PyvesB commented Nov 11, 2017

I'll go through recent changes and submit a small pull request to clean up anything that needs to be.

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 service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants