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

Refactor [Wordpress] services #3324

Merged
merged 9 commits into from
Apr 22, 2019
Merged

Refactor [Wordpress] services #3324

merged 9 commits into from
Apr 22, 2019

Conversation

paulmelnikow
Copy link
Member

@paulmelnikow paulmelnikow commented Apr 17, 2019

  • Prefer inline transforms to take place in handle() rather than render()
  • Avoid inversion of control by removing BaseWordpress#handle(), passing extensionType into fetch(), and removing one layer of subclassing
  • Move “not found” checks into fetch()
  • Cache wordpress versions instead of fetching on each request
  • Start to convert aliases to redirects (there are more of these which could be tackled in a follow-on)
  • Replace at least one route format with a pattern (ref Deprecate route format, replacing with pattern #3329)
  • Partially reorder: name, category, route, examples, defaultBadgeData, render, fetch, handle

Some of this is in line with our established patterns or makes it clearly easier to follow; some of it is arguably stylistic.

- Prefer inline transform in `handle()` over `render()`
- Avoid inversion of control by removing `BaseWordpress#handle()` and passing `extensionType` into `fetch()`
- Move “not found” checks into `fetch()`
- Cache wordpress versions instead of fetching on each request
- Start to convert aliases to redirects (there are more of these which could be tackled in a follow-on)
- Replace at least one route `format` with a `pattern` (I think?)
@paulmelnikow paulmelnikow added the service-badge New or updated service badge label Apr 17, 2019
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3324 April 17, 2019 16:29 Inactive
@shields-ci
Copy link

shields-ci commented Apr 17, 2019

Messages
📖 ✨ Thanks for your contribution to Shields, @paulmelnikow!

Generated by 🚫 dangerJS against 654707d

@paulmelnikow
Copy link
Member Author

This pull request introduces 3 alerts when merging 6481b41 into 5bedbbd - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class
  • 1 for Assignment to constant

Comment posted by LGTM.com

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3324 April 17, 2019 16:40 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3324 April 17, 2019 16:40 Inactive
async function versionColorForWordpressVersion(version) {
const offeredVersions = await getOfferedVersions()

// What is this?
Copy link
Member

Choose a reason for hiding this comment

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

🤣

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 this code has now been moved twice, but probably it should be completely rewritten. This should also have some of its own tests. There is already a lot changing in this PR. I'm not sure it needs to be dealt with now.

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-3324 April 18, 2019 00:53 Inactive
const scaled = (rating / 100) * 5
return {
message: `${scaled.toFixed(1)}/5 (${metric(numRatings)})`,
color: floorCount(scaled, 2, 3, 4),
Copy link
Member

@calebcartwright calebcartwright Apr 21, 2019

Choose a reason for hiding this comment

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

It looks like the legacy service (for Rating) used the fixed/rounded scaled value in the color scale. I think that would technically mean there's a handful of boundary cases with rating values really close to the scale steps that would end up colored differently.

For example if scaled has a value of 2.99 then I believe that would be yellowgreen, but in the legacy service (due to the .toFixed that same badge would have been green.

I'm not sure if that's a possibility given the underlying data, or how likely it would be, but felt it was worth mentioning

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, it seems reasonable to use the rounded display value for the color.

@paulmelnikow paulmelnikow merged commit 5828223 into master Apr 22, 2019
@shields-deployment
Copy link

This pull request was merged to master branch. This change is now waiting for deployment, which will usually happen within a few days. Stay tuned by joining our #ops channel on Discord!

After deployment, changes are copied to gh-pages branch:

@paulmelnikow paulmelnikow deleted the refactor-wordpress branch April 22, 2019 15:45
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