-
-
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
[BitBucket GitHub] fixes and tests for BitBucket service integration #1315
Conversation
Other similar endpoints e.g: BitBucket PRs, GitHub PRs, Github Issues etc present this as a metric. BitBucket issues should behave consistently
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.
These are awesome! You're on fire! 🔥
service-tests/helpers/validators.js
Outdated
@@ -37,6 +37,8 @@ const isStarRating = withRegex(/^(?=.{5}$)(\u2605{0,5}[\u00BC\u00BD\u00BE]?\u260 | |||
// Required to be > 0, beacuse accepting zero masks many problems. | |||
const isMetric = withRegex(/^[1-9][0-9]*[kMGTPEZY]?$/); | |||
|
|||
const isMetricOpenIssues = withRegex(/^[0-9]+[kMGTPEZY]? open$/); |
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 we make sure this is nonzero, as with isMetric
? We've had broken code which displayed 0 on a malformed response.
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.
Alternatively we could add a test with API mock which will allow expect specific value in result.
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 is legitimate for this to be zero if there are actually zero open issues though. In the GitHub tests (on master), you've got a mix of tests that are looking for [0-9]+...
(e.g: https://github.com/badges/shields/blob/master/service-tests/github.js#L69-L74 ) and others looking for [1-9][0-9]+...
(e.g: https://github.com/badges/shields/blob/master/service-tests/github.js#L80-L85 ).
Do you think we should extract both regexes and add tests for both cases, or should we always validate a non-zero value?
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.
True, though as long as we pick a project that is likely to stay around, there will always be open issues. I'm always fine with additional tests using mocks if the integrated tests don't seem satisfactory.
I think using /^[1-9][0-9]*[kMGTPEZY]? open$/
would be fine for both open issues and open issues by label. Does that answer your question?
service-tests/bitbucket.js
Outdated
|
||
t.create('issues-raw (invalid)') | ||
.get('/issues-raw/atlassian/not-a-repo.json') | ||
.expectJSON({ name: 'issues', value: 'invalid' }); |
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.
How about displaying repo not found
instead of invalid
? Someone asked for repo which does not exist.
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 catch block might potentially catch errors other than repo doesn't exist
-
This behaviour is consistent with the output of other endpoints. e.g:
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.
Okay, though is there another way to detect the "not found" case? Agree with @platan that it would be better to detect it and return a helpful message. It lets the user know where the problem lies.
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, didn't see this: #1315 (comment)
server.js
Outdated
@@ -4277,6 +4280,9 @@ cache(function(data, match, sendBadge, request) { | |||
try { | |||
var data = JSON.parse(buffer); | |||
var pullrequests = data.size; | |||
if (typeof pullrequests === 'undefined') { |
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.
In tests I can see that this code is used to handle case, when repo if not found (please correct me if I'm wrong). In this case API will return 404 status code (e.g. https://bitbucket.org/api/2.0/repositories/atlassian/python-bitbucket/pullrequests_NOT_FOUND/?limit=0&state=OPEN
). How about checking status code before parsing response body?
Have you know a case when status code is 200 and data.size
is undefined?
@platan - I can't think of another case where should be valid for count/size to be undefined with a |
other invalid status codes or exceptions will be caught with genreric 'invalid'
updated based on latest review comments |
Github service tests passing locally 👍 Thanks! |
@@ -4246,11 +4246,18 @@ cache(function(data, match, sendBadge, request) { | |||
try { | |||
var data = JSON.parse(buffer); | |||
var issues = data.count; | |||
badgeData.text[1] = issues + (isRaw? '': ' open'); | |||
if (res.statusCode !== 200) { |
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 already merged, but I think next time we could check status code before parsing response body.
undefined
i.e: do this:![invalid](https://user-images.githubusercontent.com/6025893/33528467-b8d5f5a2-d858-11e7-9e9a-f9139f3769e3.png)
![undefined_open](https://user-images.githubusercontent.com/6025893/33528470-c5af2712-d858-11e7-98b1-6e289613cd09.png)
not this: