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

Add badge for NuGet download count, again #945

Merged
merged 3 commits into from
Apr 20, 2017

Conversation

Daniel15
Copy link
Member

NuGet download badges giveth, and NuGet download badges taketh away.

Now they're back, in pog V3 form.

I switched the NuGet badges from the SearchAutocompleteService to the SearchQueryService. The SearchQueryService returns download counts in addition to version numbers.

This works for both NuGet and MyGet:

I also verified that the version number badges still work as expected:

I tried to keep the style as close to the original code as possible, although this code could do with some modernization (like using promises rather than callbacks) at some point. I'm happy to help with that 😃

Closes #678

Daniel15 referenced this pull request Apr 18, 2017
The v2 API returned XML even though we asked for JSON.

MyGet is still not working.

Part of #655.
Switched from SearchAutocompleteService to SearchQueryService as this service also provides download counts.
@paulmelnikow
Copy link
Member

This looks great! I have a couple minor comments and I'll run some tests when you're done addressing them. Thanks for clearing up this long-standing issue.

Would you be interested in helping maintain shields? Modernization could be good… We've started using lexical scope, template strings, and arrow functions in new code. (You're welcome to use those here if you'd like.) Promises could improve error handling and reduce some of the callback boilerplate. It would be a big change, so it's something we need to plan and execute gradually. I try to avoid changing code solely for the sake of updating the style, though sometimes it's necessary. We're being conservative with server.js and try.html to avoid conflicts with the large backlog of PRs. My current focus is tests of the vendor badges (#927), which will make reviewing PRs much faster, help contributors code faster, and tell us when things break. Would you like to review #937?

server.js Outdated
try {
// Official NuGet server uses "totalDownloads" whereas MyGet uses
// "totaldownloads" (lowercase D). Ugh.
var downloads = nugetData.totalDownloads || nugetData.totaldownloads;
Copy link
Member

Choose a reason for hiding this comment

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

What if there are zero downloads? Would 'totalDownloads' in nugetData ? nugetData.totalDownloads : nugetData.totaldownloads be safer?

Copy link
Member Author

Choose a reason for hiding this comment

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

nugetData.totalDownloads || nugetData.totaldownloads || 0 is probably fine.

In theory, everything should be using totalDownloads and totaldownloads should not exist. Certainly there'll never be a feed in which both totalDownloads and totaldownloads exist, as many JSON parsers are not case-sensitive or have an option to disable case-sensitivity. I suspect the lowercase totaldownloads is simply a bug in MyGet.

try.html Outdated
</tr>
<tr><th> MyGet tenant: </th>
<td><img src='/dotnet.myget/dotnet-coreclr/dt/Microsoft.DotNet.CoreCLR.svg' alt=''/></td>
<td><code>https://img.shields.iodotnet.myget/dotnet-coreclr/dt/Microsoft.DotNet.CoreCLR.svg</code></td>
Copy link
Member

Choose a reason for hiding this comment

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

That link is missing a /.

server.js Outdated
if (filteredVersions.length > 0) {
versions = filteredVersions;
}
data = data.data && data.data[0];
Copy link
Member

Choose a reason for hiding this comment

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

Could you make this a more explicit check that it's an array, and with the expected length?

@paulmelnikow paulmelnikow added the service-badge Accepted and actionable changes, features, and bugs label Apr 18, 2017
@Daniel15
Copy link
Member Author

Thanks for the review! The issues you mentioned should be fixed now.

Would you be interested in helping maintain shields?

Yeah, sure! I could try to help out 😃

Modernization could be good

I posted some ideas in #948 if you're interested!

. I try to avoid changing code solely for the sake of updating the style, though sometimes it's necessary. We're being conservative with server.js and try.html to avoid conflicts with the large backlog of PRs.

We could always go through the pull requests and close out all the stale ones (where the author hasn't responded). Then go through all the current ones and see what could be merged easily. I think it's fine to tell people that code is in the process of being cleaned up and they'll need to rebase, particularly if they've got a large PR :)

My current focus is tests of the vendor badges (#927), which will make reviewing PRs much faster, help contributors code faster, and tell us when things break

This is a great focus. In my team at work, we recently had a "quality week" where we spent the whole week improving unit/integration/functional test coverage of our app, and also improving type safety (we use Flow for typechecking all our newer JavaScript). Tests will be great as we'll feel more confident with the changes being made. 👍

@paulmelnikow
Copy link
Member

… we recently had a "quality week" where we spent the whole week improving unit/integration/functional test coverage of our app, and also improving type safety …

Sounds like fun!

… we use Flow for typechecking all our newer JavaScript …

Total aside: it seems to me that TypeScript has gotten an edge recently. Why did FB choose Flow?

We could always go through the pull requests and close out all the stale ones (where the author hasn't responded). Then go through all the current ones and see what could be merged easily. I think it's fine to tell people that code is in the process of being cleaned up and they'll need to rebase, particularly if they've got a large PR :)

This is true. However, I tend to look at unmerged contributions as an unmined asset. There are some features in there I want to include – #409, #611, #774, #786 to name a few – and if those contributors don't respond, I'll fix them up myself. With the tests, that process should be fast and pleasant. I think it's realistic. 12 days ago there were 55 open pull requests and now there are 42, so I'm hopeful we can work through it by mid-May. I've also not wanted to merge things too fast, because I don't want to be too far ahead if things break on deploy, and also because I've only been onboard a month or so.

@paulmelnikow
Copy link
Member

Just ran these badges! It's not quite clear that these numbers are download counts:

screen shot 2017-04-19 at 2 52 24 pmscreen shot 2017-04-19 at 2 52 17 pmscreen shot 2017-04-19 at 2 51 39 pm

What do you think, could we make the left side "downloads"? If showing the repository is important, we could tack "downloads" on the right side, after the metric.

This is the npm dt badge:

screen shot 2017-04-19 at 2 53 47 pm

@Daniel15
Copy link
Member Author

Oh, good catch! I forgot to change the label on the badge to say "downloads". I can do that tonight 😃

Total aside: it seems to me that TypeScript has gotten an edge recently. Why did FB choose Flow?

I remember initially, Flow did a better job at inferring types from untyped code than TypeScript did. These days, both Flow and TypeScript seem good - I don't know if one has any advantages over the other. My team use Flow mainly because Flow is built by Facebook, so we can work closely with the Flow team if we encounter any issues. The app I work on (Ads - Power Editor) was actually the first app to ever use Flow in production. We have one of the largest JS apps at Facebook so it was a good test bed 😃

@Daniel15
Copy link
Member Author

Text updated!

@paulmelnikow paulmelnikow merged commit c5bd4a4 into badges:master Apr 20, 2017
@Daniel15 Daniel15 deleted the nuget-download branch April 21, 2017 18:44
@kzu
Copy link
Contributor

kzu commented Apr 22, 2017

I can't find the examples in the Downloads section for NuGet now, time to bring them back? ;)

@kzu
Copy link
Contributor

kzu commented Apr 22, 2017

I'm just being eager to try this, but I still can't get this to work: https://img.shields.io/nuget/dt/Moq.svg

@Daniel15
Copy link
Member Author

Daniel15 commented Apr 22, 2017 via email

@kzu
Copy link
Contributor

kzu commented Apr 24, 2017

gentle nudge 👍

@paulmelnikow
Copy link
Member

Not forgotten. We're waiting along with you.

@paulmelnikow paulmelnikow added this to the Next Deploy milestone Apr 26, 2017
@paulmelnikow
Copy link
Member

This has been deployed. 🚀

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.

NuGet download count no longer works
3 participants