-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
calebcartwright
merged 26 commits into
badges:master
from
DenverCoderOne:userscript-ratings
Jul 22, 2022
Merged
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 e9da438
refactor: combine rating classes
DenverCoder1 a2473e4
refactor: remove Base from class name
DenverCoder1 4230be0
Merge branch 'master' into userscript-ratings
DenverCoder1 0972b68
Change to a single badge with all values
DenverCoder1 123b855
Merge branch 'master' into userscript-ratings
DenverCoder1 34d783b
Merge branch 'badges:master' into userscript-ratings
DenverCoder1 0310b70
Add unit tests for GreasyForkRatingCount.render
DenverCoder1 c05f81b
Merge branch 'badges:master' into userscript-ratings
DenverCoder1 ece8728
Average totals in color algorithm
DenverCoder1 58c1c30
chore(deps): bump moment from 2.29.3 to 2.29.4 (#8170)
dependabot[bot] 13e0302
chore(deps-dev): bump @typescript-eslint/eslint-plugin (#8183)
dependabot[bot] 05d4eb7
chore(deps): bump @sentry/node from 7.4.1 to 7.5.1 (#8174)
dependabot[bot] f617fac
chore(deps): bump simple-icons from 7.3.0 to 7.4.0 (#8181)
dependabot[bot] 3bc0201
chore(deps-dev): bump nodemon from 2.0.18 to 2.0.19 (#8179)
dependabot[bot] 665aa75
Add [ROS] version service (#8169)
jtbandes e7788d8
add spaces round pipe in [conda] badge (#8189)
chris48s ef1e285
refactor(deps): Replace moment with dayjs (#8192)
DenverCoder1 5f82696
chore(deps): bump @sentry/node from 7.5.1 to 7.6.0 (#8197)
dependabot[bot] 1c73730
Fix missing `dayjs` -> `moment` (#8204)
chxseh 28c4fcd
chore(deps): bump ioredis from 5.1.0 to 5.2.0 (#8201)
dependabot[bot] b1630fb
chore(deps): bump fast-xml-parser from 4.0.8 to 4.0.9 (#8203)
dependabot[bot] 782dabd
revert rebase
DenverCoder1 5727bc1
Merge branch 'master' into userscript-ratings
DenverCoder1 93b0f73
Add test for all good ratings
DenverCoder1 d867aee
Merge branch 'master' into userscript-ratings
DenverCoder1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
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.