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] download count for latest pre-release #1140

Merged
merged 8 commits into from
Oct 9, 2017
Merged

[github] download count for latest pre-release #1140

merged 8 commits into from
Oct 9, 2017

Conversation

platan
Copy link
Member

@platan platan commented Oct 8, 2017

Implements #1113.

Additionally I've removed extra space in 2 cases (failing tests without this change):

  1) Github downloads for latest release 
	[ GET http://localhost:1111/github/downloads/photonstorm/phaser/latest/total.json ]:
     ValidationError: child "value" fails because ["value" with value "63k " fails to match the required pattern: /^[0-9]+[kMGTPEZY]?$/]
--
  2) Github downloads-pre for latest release 
	[ GET http://localhost:1111/github/downloads-pre/photonstorm/phaser/latest/total.json ]:
     ValidationError: child "value" fails because ["value" with value "34 " fails to match the required pattern: /^[0-9]+[kMGTPEZY]?$/]
--
  3) Github downloads for specific asset from latest release 
	[ GET http://localhost:1111/github/downloads/atom/atom/latest/atom-amd64.deb.json ]:
     ValidationError: child "value" fails because ["value" with value "3k  [atom-amd64.deb]" fails to match the required pattern: /^[0-9]+[kMGTPEZY]? \[atom-amd64\.deb\]$/]
--
  4) Github downloads-pre for specific asset from latest release 
	[ GET http://localhost:1111/github/downloads-pre/atom/atom/latest/atom-amd64.deb.json ]:
     ValidationError: child "value" fails because ["value" with value "372  [atom-amd64.deb]" fails to match the required pattern: /^[0-9]+[kMGTPEZY]? \[atom-amd64\.deb\]$/]

@platan platan changed the title [github] download count for latest pre-release #1113 [github] download count for latest pre-release Oct 8, 2017
@platan
Copy link
Member Author

platan commented Oct 8, 2017

#1118 really helped me with developing this change.

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.

Thanks a bunch! I left a couple minor comments.

server.js Outdated
badgeData.text[1] = metric(downloads);
if (label) {
badgeData.text[1] += ' ' + label;
}
Copy link
Member

Choose a reason for hiding this comment

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

This code could be made clearer using Array.prototype.join:

const labelWords = [metric(downloads)];
if (tag !== latest) {
  labelWords.push(tag);
}
if (asset_name !== 'total') {
  labelWords.push(`[${asset_name}]`);
}
badgeData.text[1] = labelWords.join(' ');

This might avoid future bugs too!

Copy link
Member Author

Choose a reason for hiding this comment

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

Great idea! Thanks.

.get('/downloads-pre/photonstorm/phaser/latest/total.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('downloads'),
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]?$/)
Copy link
Member

Choose a reason for hiding this comment

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

Hopefully I will merge #1127 in a moment. Could you DRY this up by using isMetric?

@paulmelnikow paulmelnikow merged commit 848422c into badges:master Oct 9, 2017
paulmelnikow added a commit that referenced this pull request Oct 22, 2017
- `isMetric` tests must be > 0 to pass.
- Fix downloads badge bug introduced in #1140. (So much for [being clever](#1140 (comment))!)
- Fix 1 week activity badge by returning the previous week instead of the current week.
@marcelstoer
Copy link

PRs like this are the reason I'd argue that it's generally advisable to use GitHub's "squash and merge" option rather than the standard merge.

@paulmelnikow
Copy link
Member

I think I agree, though this was merged using "squash and merge."

@marcelstoer
Copy link

My bad, you're right, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants