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

Add [LGTM] service #1672

Merged
merged 4 commits into from
May 5, 2018
Merged

Add [LGTM] service #1672

merged 4 commits into from
May 5, 2018

Conversation

s0
Copy link
Contributor

@s0 s0 commented May 4, 2018

This PR adds the lgtm.com alerts count for a particular project, using the public-facing API.

Full disclosure, I work at Semmle on lgtm.com.

@shields-ci
Copy link

shields-ci commented May 4, 2018

Messages
📖

✨ Thanks for your contribution to Shields, @samlanning!

📖

Thanks for contributing to our documentation. We ❤️ our documentarians!

Generated by 🚫 dangerJS

@s0 s0 mentioned this pull request May 4, 2018
Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

Thanks for adding this and submitting with tests. This looks in good shape already, but I've noted a few points for improvement.

server.js Outdated
var projectId = match[1]; // eg, `g/apache/cloudstack`
var format = match[2];
var url = 'https://lgtm.com/api/v0.1/project/' + projectId + '/details';
var badgeData = getBadgeData('lgtm', data);
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 use the ES6 style let and const (I know we have a lot of code using var, but we're trying to update as we add new code).

server.js Outdated
}
try {
var data = JSON.parse(buffer);
if (data.code === 404) {
Copy link
Member

Choose a reason for hiding this comment

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

Assuming when data.code === 404 the HTTP status code is also 404, this block here and the section above where you're checking for if (err != null) can all be simplified to:

if (checkErrorResponse(badgeData, err, res, 'project not found')) {
  sendBadge(format, badgeData);
  return;
}

it is a very common check, so we have a helper for it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It indeed is, i'll change it

.get('/alerts/g/apache/cloudstack.json')
.expectJSONTypes(Joi.object().keys({
name: 'lgtm',
value: Joi.string().regex(/^[0-9kM.]+ alerts?$/)
Copy link
Member

Choose a reason for hiding this comment

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

I think this regex should allow 'alert' or 'alerts' (i.e: it should pass however many alerts apache/cloudstack has when we run the test).

Copy link
Member

Choose a reason for hiding this comment

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

Sorry - ignore this comment. I've just noticed it is already alerts?$ not alerts$.
My bad

Copy link
Contributor Author

@s0 s0 May 4, 2018

Choose a reason for hiding this comment

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

👍 In fairness, i did originally write it with out the ?, i'll add tests to make sure that it prints it our correctly for different cases with an intercept()


t.create('missing project')
.get('/alerts/g/some-org/this-project-doesnt-exist.json')
.expectJSONTypes(Joi.object().keys({
Copy link
Member

Choose a reason for hiding this comment

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

A bit of project convention: We use .expectJSON() if we're comparing the response to an object literal and .expectJSONTypes() if we're checking the type of the response keys or validating against a regex.

@s0
Copy link
Contributor Author

s0 commented May 4, 2018

Addressed comments :)

try {
const data = JSON.parse(buffer);
if (!('alerts' in data))
throw new Error("Invalid data");
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 change this to be lower case please invalid data

Edit: never mind, just realised we aren't using this for output.

@chris48s chris48s merged commit 45ff94d into badges:master May 5, 2018
@chris48s
Copy link
Member

chris48s commented May 5, 2018

nice one - thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants