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

[BitBucket GitHub] fixes and tests for BitBucket service integration #1315

Merged
merged 7 commits into from
Dec 5, 2017

Conversation

chris48s
Copy link
Member

@chris48s chris48s commented Dec 3, 2017

  • Add test suite for BitBucket service integration
  • Present BitBucket issues as a metric (for consistency with BitBucket PR endpoint and GitHub endpoints)
  • Factor out a shared regex
  • Fail cleanly if count is undefined

i.e: do this: invalid
not this: undefined_open

Other similar endpoints
e.g: BitBucket PRs, GitHub PRs, Github Issues etc
present this as a metric.

BitBucket issues should behave consistently
@chris48s
Copy link
Member Author

chris48s commented Dec 3, 2017

I expect the GH failures are caused by #979 rather than stuff I've broken. If it makes it easier to review, I could back out 3611916 so only the BitBucket tests need to be run.

@paulmelnikow paulmelnikow added the service-badge Accepted and actionable changes, features, and bugs label Dec 3, 2017
Copy link
Member

@paulmelnikow paulmelnikow left a 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! 🔥

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

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.

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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?

@paulmelnikow
Copy link
Member

I expect the GH failures are caused by #979 rather than stuff I've broken. If it makes it easier to review, I could back out 3611916 so only the BitBucket tests need to be run.

No need, I'll just run the Github tests locally before merging. They are green right now. ✅


t.create('issues-raw (invalid)')
.get('/issues-raw/atlassian/not-a-repo.json')
.expectJSON({ name: 'issues', value: 'invalid' });
Copy link
Member

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.

Copy link
Member Author

@chris48s chris48s Dec 4, 2017

Choose a reason for hiding this comment

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

  1. This catch block might potentially catch errors other than repo doesn't exist

  2. This behaviour is consistent with the output of other endpoints. e.g:

Copy link
Member

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.

Copy link
Member

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

@platan platan Dec 4, 2017

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?

@chris48s
Copy link
Member Author

chris48s commented Dec 4, 2017

@platan - I can't think of another case where should be valid for count/size to be undefined with a 200 OK response so I have changed the condition to check for if (res.statusCode !== 200) 👍

other invalid status codes or exceptions
will be caught with genreric 'invalid'
@chris48s
Copy link
Member Author

chris48s commented Dec 5, 2017

updated based on latest review comments

@paulmelnikow
Copy link
Member

Github service tests passing locally 👍

Thanks!

@paulmelnikow paulmelnikow merged commit 433d69b into badges:master Dec 5, 2017
@@ -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) {
Copy link
Member

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.

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.

None yet

3 participants