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

[gem cdnjs appveyor] refactor ruby gems service #1680

Merged
merged 4 commits into from
May 10, 2018

Conversation

chris48s
Copy link
Member

@chris48s chris48s commented May 9, 2018

This time I've tackled a slightly more ambitious refactor. There's a few bits that would be useful to get feedback on. I will mark up the diff with comments..

chris48s added 4 commits May 9, 2018 20:11
This change to loadServiceClasses() allows us to define
services which either export a single service class e.g:

module.exports = class Cdnjs extends BaseService {
  //...
}

or more than one. e.g:

module.exports = {
  GemVersion,
  GemDownloads,
  GemOwner,
  GemRank,
}
- move badge code to service classes
- throw exceptions for errors
- use let and const
- change tests to expect 'downloads' label for error badges
- general tidying
This allows (for example) GemVersion and GemDownloads
both to use the example label 'Gem'

downloads = metric(versionData.downloads_count);
} else {
throw new InvalidResponse('invalid', new Error('version is null'));
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm passing a new Error() here because InvalidResponse expects underlyingError to exist. I suspect this is something we might end up doing a lot. Maybe it would be better if underlyingError were optional in the exception classes? Also InvalidResponse and Inaccessible expect their params in different orders. I can see that there's a case for both params being optional. Maybe it would be better to change the signatures so we can pass both of them an object with optional keys prettyMessage and underlyingError? That would make it easier for either/both to be optional and make the interface more consistent.

@shields-ci
Copy link

Messages
📖

✨ Thanks for your contribution to Shields, @chris48s!

📖

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

Generated by 🚫 dangerJS

@@ -87,7 +87,7 @@ t.create('version downloads (valid, specific version)')

t.create('version downloads (package not found)')
.get('/dv/not-a-package/4.1.0.json')
.expectJSON({name: 'downloads@4.1.0', value: 'not found'});
.expectJSON({name: 'downloads', value: 'not found'});
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the easiest thing to do where a badge may have a custom label like downloads@stable etc is to establish the convention that the error badges always use the default label instead of trying to pass a custom label when we throw an exception. This is what I've done here. Does anyone have an example of where this would not be a good idea?

Copy link
Member

Choose a reason for hiding this comment

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

Can't think of any badges where this would be a problem.

}
});

return serviceClasses;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is sensible that we should change loadServiceClasses() so we can define a service file gem.js which exports multiple classes, like this:

module.exports = {
  GemVersion,
  GemDownloads,
  GemOwner,
  GemRank,
}

instead of forcing one class per file, but I'm open to feedback on this point.

Copy link
Member

@RedSparr0w RedSparr0w left a comment

Choose a reason for hiding this comment

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

Nice work on this PR, Changes look good to me!

@chris48s
Copy link
Member Author

Cheers. I'll merge this as it is for now and have a look at optional params on the exception classes as another issue.

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.

3 participants