Skip to content

Commit

Permalink
[greasyfork] Add Greasy Fork rating badges (#8087)
Browse files Browse the repository at this point in the history
* Add greasy fork rating badges

* refactor: combine rating classes

* refactor: remove Base from class name

* Change to a single badge with all values

* Add unit tests for GreasyForkRatingCount.render

* Average totals in color algorithm

* chore(deps): bump moment from 2.29.3 to 2.29.4 (#8170)

Bumps [moment](https://github.com/moment/moment) from 2.29.3 to 2.29.4.
- [Release notes](https://github.com/moment/moment/releases)
- [Changelog](https://github.com/moment/moment/blob/develop/CHANGELOG.md)
- [Commits](moment/moment@2.29.3...2.29.4)

---
updated-dependencies:
- dependency-name: moment
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>

* chore(deps-dev): bump @typescript-eslint/eslint-plugin (#8183)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.30.0 to 5.30.5.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.30.5/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>

* chore(deps): bump @sentry/node from 7.4.1 to 7.5.1 (#8174)

Bumps [@sentry/node](https://github.com/getsentry/sentry-javascript) from 7.4.1 to 7.5.1.
- [Release notes](https://github.com/getsentry/sentry-javascript/releases)
- [Changelog](https://github.com/getsentry/sentry-javascript/blob/master/CHANGELOG.md)
- [Commits](getsentry/sentry-javascript@7.4.1...7.5.1)

---
updated-dependencies:
- dependency-name: "@sentry/node"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>

* chore(deps): bump simple-icons from 7.3.0 to 7.4.0 (#8181)

Bumps [simple-icons](https://github.com/simple-icons/simple-icons) from 7.3.0 to 7.4.0.
- [Release notes](https://github.com/simple-icons/simple-icons/releases)
- [Commits](simple-icons/simple-icons@7.3.0...7.4.0)

---
updated-dependencies:
- dependency-name: simple-icons
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>

* chore(deps-dev): bump nodemon from 2.0.18 to 2.0.19 (#8179)

Bumps [nodemon](https://github.com/remy/nodemon) from 2.0.18 to 2.0.19.
- [Release notes](https://github.com/remy/nodemon/releases)
- [Commits](remy/nodemon@v2.0.18...v2.0.19)

---
updated-dependencies:
- dependency-name: nodemon
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>

* Add [ROS] version service (#8169)

* Add [ROS] version service

* review feedback

* add spaces

* add spaces round pipe in [conda] badge (#8189)

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>

* refactor(deps): Replace moment with dayjs (#8192)

* chore(deps): bump @sentry/node from 7.5.1 to 7.6.0 (#8197)

Bumps [@sentry/node](https://github.com/getsentry/sentry-javascript) from 7.5.1 to 7.6.0.
- [Release notes](https://github.com/getsentry/sentry-javascript/releases)
- [Changelog](https://github.com/getsentry/sentry-javascript/blob/master/CHANGELOG.md)
- [Commits](getsentry/sentry-javascript@7.5.1...7.6.0)

---
updated-dependencies:
- dependency-name: "@sentry/node"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix missing `dayjs` -> `moment` (#8204)

Co-authored-by: Caleb Cartwright <[email protected]>

* chore(deps): bump ioredis from 5.1.0 to 5.2.0 (#8201)

Bumps [ioredis](https://github.com/luin/ioredis) from 5.1.0 to 5.2.0.
- [Release notes](https://github.com/luin/ioredis/releases)
- [Changelog](https://github.com/luin/ioredis/blob/main/CHANGELOG.md)
- [Commits](redis/ioredis@v5.1.0...v5.2.0)

---
updated-dependencies:
- dependency-name: ioredis
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>

* chore(deps): bump fast-xml-parser from 4.0.8 to 4.0.9 (#8203)

Bumps [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) from 4.0.8 to 4.0.9.
- [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases)
- [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md)
- [Commits](NaturalIntelligence/fast-xml-parser@v4.0.8...v4.0.9)

---
updated-dependencies:
- dependency-name: fast-xml-parser
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* revert rebase

* Add test for all good ratings

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
Co-authored-by: Jacob Bandes-Storch <[email protected]>
Co-authored-by: chris48s <[email protected]>
Co-authored-by: chase <[email protected]>
Co-authored-by: Caleb Cartwright <[email protected]>
  • Loading branch information
7 people authored Jul 22, 2022
1 parent c64bb7e commit 6012570
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
40 changes: 40 additions & 0 deletions services/greasyfork/greasyfork-rating.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { floorCount as floorCountColor } from '../color-formatters.js'
import { metric } from '../text-formatters.js'
import BaseGreasyForkService from './greasyfork-base.js'

export default class GreasyForkRatingCount extends BaseGreasyForkService {
static category = 'rating'
static route = { base: 'greasyfork', pattern: 'rating-count/:scriptId' }

static examples = [
{
title: 'Greasy Fork',
namedParams: { scriptId: '407466' },
staticPreview: this.render({ good: 17, ok: 2, bad: 3 }),
},
]

static defaultBadgeData = { label: 'rating' }

static render({ good, ok, bad }) {
let color = 'lightgrey'
const total = good + bad + ok
if (total > 0) {
const score = (good * 3 + ok * 2 + bad * 1) / total - 1
color = floorCountColor(score, 1, 1.5, 2)
}
return {
message: `${metric(good)} good, ${metric(ok)} ok, ${metric(bad)} bad`,
color,
}
}

async handle({ scriptId }) {
const data = await this.fetch({ scriptId })
return this.constructor.render({
good: data.good_ratings,
ok: data.ok_ratings,
bad: data.bad_ratings,
})
}
}
31 changes: 31 additions & 0 deletions services/greasyfork/greasyfork-rating.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test, given } from 'sazerac'
import GreasyForkRatingCount from './greasyfork-rating.service.js'

describe('GreasyForkRatingCount', function () {
test(GreasyForkRatingCount.render, () => {
given({ good: 0, ok: 0, bad: 30 }).expect({
message: '0 good, 0 ok, 30 bad',
color: 'red',
})
given({ good: 10, ok: 20, bad: 30 }).expect({
message: '10 good, 20 ok, 30 bad',
color: 'yellow',
})
given({ good: 10, ok: 20, bad: 10 }).expect({
message: '10 good, 20 ok, 10 bad',
color: 'yellowgreen',
})
given({ good: 20, ok: 10, bad: 0 }).expect({
message: '20 good, 10 ok, 0 bad',
color: 'green',
})
given({ good: 30, ok: 0, bad: 0 }).expect({
message: '30 good, 0 ok, 0 bad',
color: 'brightgreen',
})
given({ good: 0, ok: 0, bad: 0 }).expect({
message: '0 good, 0 ok, 0 bad',
color: 'lightgrey',
})
})
})
14 changes: 14 additions & 0 deletions services/greasyfork/greasyfork-rating.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('Rating Count')
.get('/rating-count/407466.json')
.expectBadge({
label: 'rating',
message: Joi.string().regex(/^\d+ good, \d+ ok, \d+ bad$/),
})

t.create('Rating Count (not found)')
.get('/rating-count/000000.json')
.expectBadge({ label: 'rating', message: 'not found' })

0 comments on commit 6012570

Please sign in to comment.