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] File Size #745

Merged
merged 15 commits into from
May 1, 2017
Merged

[Github] File Size #745

merged 15 commits into from
May 1, 2017

Conversation

webcaetano
Copy link
Contributor

filesizebage

New badge with specific Github file size information.

Related issue : #730

@webcaetano webcaetano mentioned this pull request Jul 19, 2016
Copy link
Contributor Author

@webcaetano webcaetano left a 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

@paulmelnikow paulmelnikow added the service-badge New or updated service badge label Mar 27, 2017
@olivierlacan
Copy link
Member

So this is displaying the git repo size? This could be confused with some binary package size. Maybe this would be more appropriate?

I used lightgrey here because I don't really see why the size should be displayed in green. The size isn't positive or negative, it's just informational.

@webcaetano
Copy link
Contributor Author

webcaetano commented Apr 8, 2017

@olivierlacan hi,
Not repo size. File size.
For client-side libraries ( lodash , underscore , phaser , etc ...) showing their compiled main .min file
Its easier to lib display if it is lightweight on readme.md

@paulmelnikow
Copy link
Member

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'
};
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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?

@webcaetano webcaetano changed the title [New badge] Github file size Add New badge Github file size Apr 29, 2017
@webcaetano webcaetano changed the title Add New badge Github file size [GithubFileSize] Github file size Apr 29, 2017
@webcaetano webcaetano changed the title [GithubFileSize] Github file size [githubFileSize] Github file size Apr 29, 2017
@webcaetano webcaetano changed the title [githubFileSize] Github file size [github] Github file size Apr 29, 2017
@webcaetano webcaetano changed the title [github] Github file size [Github] Github file size Apr 29, 2017
@webcaetano webcaetano changed the title [Github] Github file size [Github] File Size Apr 29, 2017
@webcaetano
Copy link
Contributor Author

webcaetano commented Apr 29, 2017

@paulmelnikow done
Awesome job on this new testing setup. 👍
I might create a new PR populating this new github service-test

@paulmelnikow
Copy link
Member

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;
}
Copy link
Member

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…)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 pick that commit into this branch?

.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)$/)
}));
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

webcaetano added a commit to webcaetano/shields that referenced this pull request Apr 29, 2017
webcaetano added a commit to webcaetano/shields that referenced this pull request Apr 29, 2017
@webcaetano webcaetano closed this Apr 29, 2017
@webcaetano
Copy link
Contributor Author

Moved to #976

@paulmelnikow
Copy link
Member

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.

@webcaetano
Copy link
Contributor Author

@paulmelnikow ok i'll organize this

@webcaetano
Copy link
Contributor Author

@paulmelnikow this is done.
Atomic PRs make sense. Make things more splited and organized.
I'll reorganize #976 now

.expectJSONTypes(Joi.object().keys({
name: Joi.equal('size'),
value: Joi.string().regex(/^unknown file$/),
}));
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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?

Copy link
Contributor Author

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

value: Joi.string().regex(/^unknown file$/),
}));

t.create('downloads for release without slash')
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 remove these download tests?

Copy link
Contributor Author

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?

Copy link
Member

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).

Copy link
Contributor Author

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)$/,
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 reset this change? ^^

Copy link
Contributor Author

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

@webcaetano
Copy link
Contributor Author

@paulmelnikow done
Lmk if you need any changes.
I'll keep my eyes on the #976

@webcaetano
Copy link
Contributor Author

After merge this we can close #730

@webcaetano
Copy link
Contributor Author

I have no clue what's this travis error right now

@paulmelnikow
Copy link
Member

I don't see the error.

Thanks for the changes! Merging.

@paulmelnikow paulmelnikow merged commit a6d81f2 into badges:master May 1, 2017
@paulmelnikow paulmelnikow added this to the Next Deploy milestone May 1, 2017
@webcaetano
Copy link
Contributor Author

@paulmelnikow #979 that is what happen

@espadrine
Copy link
Member

@webcaetano @paulmelnikow I get an error on this in npm run test:services. Do you have a clue what happens by any chance? @Daniel15 We can't enable that to be part of npm test unless all of it passes.

1) Github File size 
        [ GET http://localhost:1111/github/size/webcaetano/craft/build/craft.min.js.json ]:
     ValidationError: child "value" fails because ["value" with value "repo or file not found" fails to match the required pattern: /^[0-9]*[.]?[0-9]+\s(B|kB|MB|GB|TB|PB|EB|ZB|YB)$/]
      at Object.exports.process (node_modules/joi/lib/errors.js:181:19)
      at Object._validateWithOptions (node_modules/joi/lib/types/any/index.js:651:31)
      at Object.root.validate (node_modules/joi/lib/index.js:121:23)
      at Object.pathMatch.matchJSONTypes (node_modules/icedfrisby/lib/pathMatch.js:299:9)
      at node_modules/icedfrisby/lib/icedfrisby.js:721:10
      at IcedFrisbyNock._invokeExpects (node_modules/icedfrisby/lib/icedfrisby.js:1200:33)
      at node_modules/icedfrisby/lib/icedfrisby.js:1179:29
      at Request.runCallback [as _callback] (node_modules/icedfrisby/lib/icedfrisby.js:561:11)
      at Request.self.callback (node_modules/request/request.js:188:22)
      at Request.<anonymous> (node_modules/request/request.js:1171:10)
      at IncomingMessage.<anonymous> (node_modules/request/request.js:1091:12)
      at endReadableNT (_stream_readable.js:975:12)
      at _combinedTickCallback (internal/process/next_tick.js:80:11)
      at process._tickDomainCallback (internal/process/next_tick.js:128:9)

@webcaetano
Copy link
Contributor Author

@espadrine yes i do.
That was my fault. I changed the file name of my repo recently.
@espadrine i'll make a PR fixing that

@espadrine
Copy link
Member

@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 ☺)

@webcaetano
Copy link
Contributor Author

@espadrine #1066

@yairEO
Copy link

yairEO commented Sep 19, 2018

Can someone explain to me how to use this size shield?
I'm extremely confused.

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

@paulmelnikow
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants