-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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] File Size #745
[Github] File Size #745
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LMK if you guys need any changes
@olivierlacan hi, |
Hi, I'd like to get this merged. Would you be willing to add tests using the project's new testing framework? |
server.js
Outdated
var customHeaders = { | ||
'User-Agent': 'Shields.io', | ||
'Accept': 'application/vnd.github.drax-preview+json' | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use githubAuth.request
, which should take care of most of these issues for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, got it.
server.js
Outdated
var path = match[3]; | ||
var format = match[4]; | ||
|
||
var apiUrl = 'https://api.github.com/repos/' + user + '/' + repo + '/contents/' + path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a HEAD
request be sufficient to get the size?
Add file size test
@paulmelnikow done |
Thanks, I'm glad to hear that! Testing more of the github services would be great! Feel free to open an issue to coordinate, if you'd like. Another open PR (#756) has tests of the downloads endpoint, though the rest of the badges are wide open. There is an issue that is causing github to be flaky in CI, which will also need to be fixed at some point (observed here, see this log). Will leave you a few minor comments. |
server.js
Outdated
if (serverSecrets) { | ||
apiUrl += '?client_id=' + serverSecrets.gh_client_id | ||
+ '&client_secret=' + serverSecrets.gh_client_secret; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can skip this block too. ^^ The auth should be covered by githubAuth.request
.
(Looks like this was copied from the github license integration, which ought to be fixed at some point…)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you pick that commit into this branch?
service-tests/github.js
Outdated
.expectJSONTypes(Joi.object().keys({ | ||
name: Joi.equal('size'), | ||
value: Joi.string().regex(/^[0-9]*[.]?[0-9]+\s(B|kB|MB|GB|TB|PB|EB|ZB|YB)$/) | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Is it possible to hit both the repo or file not found
and unknown file
branches? Could you test these as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should have explained that better!
The purpose of adding tests is to make sure the repo or file not found
code branch and the unknown file
code branch are working as intended. There needs to be a separate test for each one, with an exact match on the string in the response. Otherwise we don't know the API can ever return something that will trigger that branch.
For example, you could add a test for /size/some-nonexistent-user/some-nonexistent-repo/some-nonexistent-file.md
. I imagine that will hit one of those. Then identify another badge URI which will hit the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
server.js
Outdated
return; | ||
} | ||
var body = JSON.parse(buffer); | ||
if (body.size != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This test accepts some unexpected values. Does a json null
signify something in the API? If so, the reliable test would be body.size !== null
. If not, it would be Number.isInteger(body.size)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add file size test
Moved to #976 |
Thanks for jumping on those tests! It would be easier to me to finish up the review I started here. Small and atomic PRs are easier, and plus we've already begun the conversation. Hopefully we can merge this in the next day or two, and then proceed with the rest of the tests in #976. |
@paulmelnikow ok i'll organize this |
@paulmelnikow this is done. |
service-tests/github.js
Outdated
.expectJSONTypes(Joi.object().keys({ | ||
name: Joi.equal('size'), | ||
value: Joi.string().regex(/^unknown file$/), | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is what happens when you point the badge at e.g. a directory.
Would "not a regular file" be a more helpful message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulmelnikow sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sorry, I meant in the output as well: "unknown file" -> "not a regular file".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm still not being clear enough.
Could you set badgeData.text[1] = 'not a regular file'
so the user sees that message on the badge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulmelnikow 58f2e6f done
Be welcome to make commits to my PR
service-tests/github.js
Outdated
value: Joi.string().regex(/^unknown file$/), | ||
})); | ||
|
||
t.create('downloads for release without slash') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove these download tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulmelnikow this is from the #756 PR.
I Fork from there. He was the first to create the file.
I fixed potential conflicts.
What should we do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you can just remove the lines and commit the change.
Everything will get squashed, so the individual commits will go away. Probably this will go in first, and then #756 will need to solve a minor merge conflict (a new file created in both branches).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server.js
Outdated
@@ -3113,7 +3114,7 @@ cache(function(data, match, sendBadge, request) { | |||
})); | |||
|
|||
// GitHub release-download-count integration. | |||
camp.route(/^\/github\/downloads\/([^\/]+)\/([^\/]+)(\/[^\/]+)?\/([^\/]+)\.(svg|png|gif|jpg|json)$/, | |||
camp.route(/^\/github\/downloads\/([^\/]+)\/([^\/]+)(\/.+)?\/([^\/]+)\.(svg|png|gif|jpg|json)$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reset this change? ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulmelnikow also from the #756 pr
@paulmelnikow done |
After merge this we can close #730 |
I have no clue what's this travis error right now |
I don't see the error. Thanks for the changes! Merging. |
@paulmelnikow #979 that is what happen |
@webcaetano @paulmelnikow I get an error on this in
|
@espadrine yes i do. |
@webcaetano OK thanks a lot! Don't worry, there's no rush, I won't look at it until next Saturday (but I will definitely look at it on Saturday if the PR is ready ☺) |
Can someone explain to me how to use this The link here generates a hard-coded size and I was thinking I somewhere need to input my repo's url or maybe the badge's server is smart enough to know the repo's URL from the server that requests the image and construct a file size (but then again.. what does it really measures...which file size) I'm stuck on how am I supposed to use this badge and find zero information on how should this badge be used in the docs. simply dumping it there only shows a hard-coded value that I do not see a way to change |
Hi, thanks for your question. Sorry this isn't clear. If you go to https://shields.io/#/examples/size and click on the badge you'll see a page for the badge, which shows an example badge URL: https://img.shields.io/github/size/webcaetano/craft/build/phaser-craft.min.js.svg webcaetano/craft is the repo and build/phaser-craft.min.js is the filename. Hope that helps! |
New badge with specific Github file size information.
Related issue : #730