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 clojars] refactor clojars, establish BaseJsonService #1702

Merged
merged 4 commits into from
Jun 16, 2018

Conversation

chris48s
Copy link
Member

Refactored the clojars version badge. While I was doing it, I decided we really need to get the abstraction discussed here in place sooner rather than later.

Doing this makes the code for simple badges really terse. For example this reduces the gem version badge implementation down to:

  async handle({repo}) {
    const apiUrl = 'https://rubygems.org/api/v1/gems/' + repo + '.json';
    const json = await this._requestJson(apiUrl);
    const version = json.version;

    return {
      message: versionText(version),
      color: versionColor(version)
    };
  }

@shields-ci
Copy link

shields-ci commented May 25, 2018

Warnings
⚠️

This PR modified the server but none of the service tests. That's okay so long as it's refactoring existing code.

Messages
📖

✨ Thanks for your contribution to Shields, @chris48s!

📖

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

Generated by 🚫 dangerJS

@chris48s chris48s added the service-badge New or updated service badge label May 26, 2018
@PyvesB PyvesB self-requested a review June 13, 2018 16:46
Copy link
Member

@PyvesB PyvesB left a comment

Choose a reason for hiding this comment

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

Looks overall good to me, I've left a few minor comments in the code. 😉


const { BaseJsonService } = require('../base');
const { NotFound } = require('../errors');
const { version: versionColor} = require('../../lib/color-formatters');
Copy link
Member

Choose a reason for hiding this comment

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

Being picky: inconsistent spacing around versionColor ^^

Copy link
Member

Choose a reason for hiding this comment

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

Surprised we don't have an eslint rule for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. I was also surprised this isn't caught by a lint rule. Looks like we would need to configure ESLint's object-curly-spacing rule. If we want to add a convention for this, there's going to be a bunch of other code knocking about that doesn't conform to it so lets do it in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not that familiar with ESLint, but I'm happy to take care of this and dig into it some more. 😉

Copy link
Member

Choose a reason for hiding this comment

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

Actually, after taking a closer look into this, we do have a rule enabled in Prettier. Nevertheless, it's currently awaiting to be enabled as part of #1167.

@@ -94,10 +87,7 @@ class GemDownloads extends BaseService {
version = (version === "stable") ? version : semver.valid(version);
const label = this._getLabel(version, info);
const apiUrl = this._getApiUrl(repo, info);
const json = await this._sendAndCacheRequest(apiUrl, {
headers: { 'Accept': 'application/atom+json,application/json' }
Copy link
Member

Choose a reason for hiding this comment

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

This particular line had a slightly different Accept header, any idea why?

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 was added in #212 but there is no explanation there. It works fine with the standard Accept: application/json it so I didn't see the need to cargo cult it.

static get url() {
return {
base: 'clojars/v',
format: '(.*)',
Copy link
Member

Choose a reason for hiding this comment

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

The old implementation used (.+), I would be inclined to keep it that way. It won't make that much of a difference, but we will avoid capturing an empty string and making a request that we know is incorrect to the Clojars service.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 Good spot. I've also changed it in the other services I have touched in this PR as there is no case for empty string there either. I'll try to remember this as I refactor more services.

@paulmelnikow
Copy link
Member

This is great! Let's get it in! 😁

@chris48s chris48s merged commit f78e6f1 into badges:master Jun 16, 2018
@shields-deployment
Copy link

shields-deployment bot commented Jun 16, 2018

This pull request was merged to master branch. Now this change is waiting for deployment.
Deploys usually happen every few weeks. After deployment changes are copied to gh-pages branch.

This badge displays deployment status:

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.

5 participants