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

[Github] Last commit date and commit stats #1112

Merged
merged 19 commits into from
Oct 2, 2017
Merged

[Github] Last commit date and commit stats #1112

merged 19 commits into from
Oct 2, 2017

Conversation

paulmelnikow
Copy link
Member

This adds badges for the last commit date and the commit activity.

Reopen of #928. Closes #897.

Copy link
Member

@Daniel15 Daniel15 left a comment

Choose a reason for hiding this comment

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

Minor comments inline

if (steps.length in defaultColors) {
colors = defaultColors[steps.length];
} else {
throw Error(`No default colors for ${steps.length} steps.`);
Copy link
Member

Choose a reason for hiding this comment

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

These should be throw new Error, not throw Error. Invoking constructors without the new keyword is deprecated.

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 can't find a reference supporting this. I used to write new Error but stopped because it's extra tokens for seemingly no value. The ES5 spec specifically permits this. Is there an ES6 reference that says otherwise?

I only bring it up because I'd enforce what you're asking for if I had a good reference.

Copy link
Member

@Daniel15 Daniel15 Oct 2, 2017

Choose a reason for hiding this comment

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

Ah, interesting @paulmelnikow! That's still in the ES2015 spec (https://www.ecma-international.org/ecma-262/6.0/#sec-error-constructor):

When Error is called as a function rather than as a constructor, it creates and initializes a new Error object. Thus the function call Error(…) is equivalent to the object creation expression new Error(…) with the same arguments.

I guess it's okay then. I was basing my info off an internal lint rule we have at Facebook, but perhaps the info is outdated/incorrect.

const daysElapsed = moment().diff(moment(date), 'days');
return colorByAge(daysElapsed);
}
exports.age = age;
Copy link
Member

Choose a reason for hiding this comment

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

Do

module.exports =  {
  age,
  colorScale,
};

for consistency with the other modules you've created?

@@ -4,6 +4,9 @@
*/
'use strict';

var moment = require('moment');
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to put this require call inside the formatDate method so you only incur the overhead of loading moment if it's really needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

When would avoiding that overhead be helpful?

intervalLabel = '/week';
break;
default:
throw Error('Unhandled case');
Copy link
Member

Choose a reason for hiding this comment

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

throw new Error


describe('Color formatters', function() {
it('should step appropriately', function() {
const byPercentage = colorScale([Number.EPSILON, 80, 90, 100]);
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of Number.EPSILON here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The semantics of colorScale are that the color shifts into the new color when the value >= the provided step value. By making this EPSILON, a value of 0.5 produces yellow. If it were 1 it would be red.

Copy link
Member

Choose a reason for hiding this comment

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

Can you just use 0, or do you want to differentiate 0 from "any possible value after 0"?

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing percentage function makes 0 red and anything after that yellow. I don't see the point in differentiating between 0 and 1, which both seem terrible, though I was aiming for parity.

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 added tests at 0.5 to clarify this.

@paulmelnikow
Copy link
Member Author

The six affected service tests are passing locally.

@paulmelnikow paulmelnikow merged commit 8e08b37 into badges:master Oct 2, 2017
@paulmelnikow paulmelnikow deleted the github-code-frequency branch October 2, 2017 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants