-
-
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] Fix undefined badges #1816
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.
Changes look good!
👍
this is a rather strange way for GitHub to report when a repo is not found: {
"message": "Validation Failed",
"errors": [
{
"message": "The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.",
"resource": "Search",
"field": "q",
"code": "invalid"
}
],
"documentation_url": "https://developer.github.com/v3/search/"
} Do you think it would be worth checking the |
I get your point and I did think about that alternative as well, but I felt slightly less enthusiastic about it:
Does this make sense? |
No worries, I think it should be fine as is 👍 |
I'll have a go at fixing the other badges in the coming days, we can think about it some more in the meantime and see how it looks once everything is done. 😉 |
e8725df
to
5fb061a
Compare
@@ -74,7 +74,7 @@ t.create('License - API rate limit exceeded') | |||
message: "API rate limit exceeded for 123.123.123.123. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", | |||
documentation_url: "https://developer.github.com/v3/#rate-limiting" | |||
})) | |||
.expectJSON({ name: 'license', value: 'inaccessible', colorB: colorsB.lightgrey }); | |||
.expectJSON({ name: 'license', value: 'invalid', colorB: colorsB.lightgrey }); |
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 change is due to the default error-helper.js handling. Wouldn't inaccessible
be more appropriate for 403 responses for all badges?
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 could be worth updating the error-helper to something similar to this:
defaultErrorMessages = {
404: 'not found',
418: "I'm a teapot",
};
const checkErrorResponse = function(badgeData, err, res, errorMessage = 'not found') {
if (typeof errorMessage === 'string')
errorMessage = {...defaultErrorMessages, ...{404: errorMessage}}
else
errorMessage = {...defaultErrorMessages, ...errorMessage};
if (err != null) {
badgeData.text[1] = 'inaccessible';
badgeData.colorscheme = 'red';
return true;
} else if (errorMessage[res.statusCode] !== undefined) {
badgeData.text[1] = errorMessage[res.statusCode];
badgeData.colorscheme = 'lightgrey';
return true;
} else if (res.statusCode !== 200) {
badgeData.text[1] = 'invalid';
badgeData.colorscheme = 'lightgrey';
return true;
} else {
return false;
}
};
//Usage:
checkErrorResponse(badgeData, err, res, {403: 'repo not found'}); // 403: repo not found
checkErrorResponse(badgeData, err, res, 'repo not found'); // 404: repo not found
checkErrorResponse(badgeData, err, res, {403: 'repo not found', 404: 'repo not found'}); // 403, 404: repo not found
That way if services return a strange error code, we can still set a relevant error 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.
inaccessible would be a nice way to convey a permission problem. For our badges, thoguh, it usually means the service can't be reached.
Maybe not authorized?
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, "not authorized" may be better suited for 403 response codes. "access denied" is a good alternative as well. I'm leaning towards a separate PR though, as this has not got much to do with "undefined" in GitHub badges.
210b715
to
4247937
Compare
Is this waiting for another review? Let me know if you need me to take another look. |
Yes, I wouldn't mind someone taking a look at the final result! 👍 |
lib/github-helpers.js
Outdated
@@ -10,10 +11,19 @@ function checkStateColor(s) { | |||
return { pending: 'dbab09', success: '2cbe4e', failure: 'cb2431', error: 'cb2431' }[s]; | |||
} | |||
|
|||
function checkErrorResponse(badgeData, err, res, notFoundMessage = 'repo not found') { | |||
const isError = standardCheckErrorResponse(badgeData, err, res, notFoundMessage); | |||
if (res && res.statusCode === 422) { |
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's not completely clear whether we need the side effect of standardCheckErrorResponse
in this case. If we don't, would it be clearer to move this if
to the top of the function, and then return standardCheckErrorResponse(...)
?
lib/github-helpers.spec.js
Outdated
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const { assert } = chai; |
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 use the expect
forms like most of our 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.
Done, we should probably revisit error-helper.spec.js as well at some point, and possibly some other specs. 😉
lib/github-helpers.spec.js
Outdated
const { assert } = chai; | ||
const { checkErrorResponse } = require('./github-helpers'); | ||
|
||
chai.use(require('chai-as-promised')); |
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 could be removed.
This pull request addresses issue #1768.
I noticed that many other GitHub badges were suffering from this same problem, but for now I've only fixed it for the "issues" badge and will wait for some initial feedback before tackling the other ones. 😉