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

[greasyfork] Add Greasy Fork rating badges #8087

Merged
merged 26 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e11b8fc
Add greasy fork rating badges
DenverCoder1 Jun 16, 2022
e9da438
refactor: combine rating classes
DenverCoder1 Jun 16, 2022
a2473e4
refactor: remove Base from class name
DenverCoder1 Jun 16, 2022
4230be0
Merge branch 'master' into userscript-ratings
DenverCoder1 Jun 16, 2022
0972b68
Change to a single badge with all values
DenverCoder1 Jun 19, 2022
123b855
Merge branch 'master' into userscript-ratings
DenverCoder1 Jun 19, 2022
34d783b
Merge branch 'badges:master' into userscript-ratings
DenverCoder1 Jul 6, 2022
0310b70
Add unit tests for GreasyForkRatingCount.render
DenverCoder1 Jul 6, 2022
c05f81b
Merge branch 'badges:master' into userscript-ratings
DenverCoder1 Jul 8, 2022
ece8728
Average totals in color algorithm
DenverCoder1 Jul 8, 2022
58c1c30
chore(deps): bump moment from 2.29.3 to 2.29.4 (#8170)
dependabot[bot] Jul 8, 2022
13e0302
chore(deps-dev): bump @typescript-eslint/eslint-plugin (#8183)
dependabot[bot] Jul 10, 2022
05d4eb7
chore(deps): bump @sentry/node from 7.4.1 to 7.5.1 (#8174)
dependabot[bot] Jul 10, 2022
f617fac
chore(deps): bump simple-icons from 7.3.0 to 7.4.0 (#8181)
dependabot[bot] Jul 10, 2022
3bc0201
chore(deps-dev): bump nodemon from 2.0.18 to 2.0.19 (#8179)
dependabot[bot] Jul 10, 2022
665aa75
Add [ROS] version service (#8169)
jtbandes Jul 12, 2022
e7788d8
add spaces round pipe in [conda] badge (#8189)
chris48s Jul 12, 2022
ef1e285
refactor(deps): Replace moment with dayjs (#8192)
DenverCoder1 Jul 15, 2022
5f82696
chore(deps): bump @sentry/node from 7.5.1 to 7.6.0 (#8197)
dependabot[bot] Jul 16, 2022
1c73730
Fix missing `dayjs` -> `moment` (#8204)
chxseh Jul 16, 2022
28c4fcd
chore(deps): bump ioredis from 5.1.0 to 5.2.0 (#8201)
dependabot[bot] Jul 17, 2022
b1630fb
chore(deps): bump fast-xml-parser from 4.0.8 to 4.0.9 (#8203)
dependabot[bot] Jul 18, 2022
782dabd
revert rebase
DenverCoder1 Jul 18, 2022
5727bc1
Merge branch 'master' into userscript-ratings
DenverCoder1 Jul 18, 2022
93b0f73
Add test for all good ratings
DenverCoder1 Jul 18, 2022
d867aee
Merge branch 'master' into userscript-ratings
DenverCoder1 Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`,
Copy link
Member

Choose a reason for hiding this comment

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

suppose the only other thing to consider here would be whether or not to include the stats when there's 0 of a type of feedback. for example with the test results combo badge we won't display 0 failed if all the tests passed.

I don't have strong opinions, and would be fine proceeding with this as is, just wanted to gauge your thoughts on whether we should do something similar here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think having all 3 numbers makes the most sense since there are only 3 types of ratings and it shows how many of each type. It would correspond well with the website which shows a number for all categories even if it is 0:

image

If some categories were left out, it would make it less obvious that the ratings are in distinct categories and for those unfamiliar with the site to know which ones are missing.

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',
})
DenverCoder1 marked this conversation as resolved.
Show resolved Hide resolved
})
})
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' })