Skip to content

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

Merged
paulmelnikow merged 8 commits intobadges:masterfrom
platan:issue-1113
Oct 9, 2017
Merged

[github] download count for latest pre-release#1140
paulmelnikow merged 8 commits intobadges:masterfrom
platan:issue-1113

Conversation

@platan
Copy link
Copy Markdown
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
Copy Markdown
Member Author

platan commented Oct 8, 2017

#1118 really helped me with developing this change.

Copy link
Copy Markdown
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.

Comment thread server.js Outdated
badgeData.text[1] = metric(downloads);
if (label) {
badgeData.text[1] += ' ' + label;
}
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread service-tests/github.js Outdated
.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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Member

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

@marcelstoer
Copy link
Copy Markdown

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

Development

Successfully merging this pull request may close these issues.

3 participants