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

Added support for new Code Climate scores #1236

Merged
merged 6 commits into from
Nov 6, 2017

Conversation

Nickersoft
Copy link
Contributor

One think to note: unlike the previous CC badges, the new API uses badge tokens associated with repos to retrieve SVG badges for users (as opposed to just the repo name). As a result, the new badges have to first make a request to the CC API to get the token associated with the repo, then make another request to get information regarding the badge. Also due to this, it was difficult to write tests that test for invalid response headers. Everything else should be covered though.

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.

Looks good, thanks!

});

t.create('test coverage score')
.get('/tc/Nickersoft/dql.json')
Copy link
Member

Choose a reason for hiding this comment

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

For consistency with a couple other badges, could you change /tc/ to /c/ for coverage?

badgeData.colorscheme = 'red';
}
sendBadge(format, badgeData);
} catch(e) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this the "project not found" case? Is it possible to test that more explicitly above, so you can reserve the catch for "something went wrong" and return invalid instead of not found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not exactly sure... I copied these code blocks from the existing CodeClimate blocks. Could you elaborate on when "not found" vs. "invalid" vs. "unknown" should be displayed?

Copy link
Member

Choose a reason for hiding this comment

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

  • When someone is asking for a nonexistent project, we should display something really clear and helpful like project not found, which tells them they have spelled something wrong, the project isn't public, etc.
  • On the other hand unknown would mean CodeClimate has the project but for some reason can't answer the question, like some kind of error occurred when trying to compute it.
  • And invalid is like a 500 error: something went wrong on our side or their side when we tried to fetch the information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I gotcha. I tried to fixed the errors to be more appropriate, so take a look when you can.

@paulmelnikow
Copy link
Member

As a result, the new badges have to first make a request to the CC API to get the token associated with the repo, then make another request to get information regarding the badge. Also due to this, it was difficult to write tests that test for invalid response headers. Everything else should be covered though.

I think you should be able to accomplish this by mocking both requests. You can either using nock chaining or make two calls to .intercept().

@paulmelnikow paulmelnikow added the service-badge New or updated service badge label Oct 31, 2017
server.js Outdated
}));


// Code Climate maintainability
Copy link
Member

Choose a reason for hiding this comment

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

Could this be merged with the coverage badge above as there is only a few lines difference.
example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! I went ahead and merged the two :)

2) Corrected error messages
3) Merged two new CodeClimate methods
@Nickersoft
Copy link
Contributor Author

@paulmelnikow So I've been trying to nock requests, and while I can get the response JSON to match, it still keeps failing with the following error:

AssertionError [ERR_ASSERTION]: Mocks not yet satisfied

I tried looking at the nock repo, but the top issues I found regarding this seemed to be from 2012. Any insight as to what causes this kind of error?

@paulmelnikow
Copy link
Member

I think that means is that you're setting up requests that aren't actually getting made.

I've worked with Nock some, and recently started helping to maintain it… a common complaint is that it's not easy to understand when things have gone wrong.

If you'd like to push your failing tests to a branch I'd be happy to look into it.

@Nickersoft
Copy link
Contributor Author

@paulmelnikow Okay, just pushed those tests. I'd like if possible to keep the badge ID of my Nickersoft repo out of the equation, but theoretically, the server is making a request to that exact endpoint and nocking it still results in the error. Let me know whatcha think.

@paulmelnikow
Copy link
Member

I got the tests passing but I can't push my changes. Could you check the "Allow edits from maintainers" box so I can do that?

@Nickersoft
Copy link
Contributor Author

@paulmelnikow Sorry, just seeing this now.. it looked like the box was already checked but I un-checked it and re-checked it just to be sure. Let me know if it still won't let you.

@paulmelnikow
Copy link
Member

Odd! I just tried it again and it's still telling me I can't push.

I opened Nickersoft#1. Maybe it's easiest to merge them in that way.

Switch to https + fix tests
@Nickersoft
Copy link
Contributor Author

@paulmelnikow Yup! It's merged into my branch now :)

@paulmelnikow paulmelnikow merged commit 632c70b into badges:master Nov 6, 2017
@paulmelnikow
Copy link
Member

Thanks!

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.

3 participants