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

[HackerNews] Show User Karma #7411

Merged
merged 11 commits into from
Dec 28, 2021
Merged

[HackerNews] Show User Karma #7411

merged 11 commits into from
Dec 28, 2021

Conversation

tapanchudasama
Copy link
Contributor

No description provided.

@shields-ci
Copy link

shields-ci commented Dec 22, 2021

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

Generated by 🚫 dangerJS against 216246e

@calebcartwright calebcartwright added the service-badge Accepted and actionable changes, features, and bugs label Dec 22, 2021
@shields-cd shields-cd temporarily deployed to shields-staging-pr-7411 December 22, 2021 19:06 Inactive
Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

Thanks for making your first contribution. I've left a few comments but its looking in pretty good shape already

services/hackernews/hackernews-user-karma.tester.js Outdated Show resolved Hide resolved
services/hackernews/hackernews-user-karma.service.js Outdated Show resolved Hide resolved
@tapanchudasama
Copy link
Contributor Author

Thanks for making your first contribution. I've left a few comments but its looking in pretty good shape already

Actually its my second. 😄 First was this. But this is a new account so it might seem new.

@shields-cd shields-cd temporarily deployed to shields-staging-pr-7411 December 23, 2021 12:37 Inactive
@shields-cd shields-cd temporarily deployed to shields-staging-pr-7411 December 23, 2021 12:40 Inactive
Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

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

Few thoughts from my end, inline below

]

static defaultBadgeData = {
label: 'HackerNews User Karma',
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of a mouthful for a label, and I'd argue, going against the grain of the branding/promotional clause in our badge specification. There are a few cases where our default badge label has the service name included because we felt it was necessary to qualify/describe the value in the message.

However, I'm not sure that's the case here. Consider in reference our other social-style badges, including the Reddit Karma badge which is combined karma (I'm not sure what "combined" means in that context, but the main point is that the label doesn't include "Reddit").

https://shields.io/category/social

I think we should change this to:

Suggested change
label: 'HackerNews User Karma',
label: 'User Karma',

or

Suggested change
label: 'HackerNews User Karma',
label: 'Karma',

Comment on lines 54 to 70
transform({ json }) {
if (json == null) {
throw new NotFound({ prettyMessage: 'user not found' })
}

const { karma, id } = json
return { karma, id }
}

async handle({ userid }) {
const json = await this.fetch({ userid })
const { karma, id } = this.transform({ json })
return this.constructor.render({
karma,
userid: id,
})
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a difference in the id value in the response vs the userid value we already have via the route parameter?

If not then perhaps consider doing the null check inline with the same early throw/bail, and then calling the render function (with or without the deconstructing).

It's great to see the application of the common transform pattern, especially when we have complex logic that's much more easily tested directly via a unit test. However, in this case the canonical not found scenario can be easily exercised already and we aren't really doing anything else but deconstructing and then building a new object.

Just food for thought, don't feel obligated to make any changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this makes sense. transform does not do much work apart from throwing Error. If it was doing some object manipulation, then it would make sense to use it.

I think we can remove it.

services/text-formatters.js Show resolved Hide resolved
@shields-cd shields-cd temporarily deployed to shields-staging-pr-7411 December 27, 2021 10:38 Inactive
@shields-cd shields-cd temporarily deployed to shields-staging-pr-7411 December 27, 2021 10:45 Inactive
@shields-cd shields-cd temporarily deployed to shields-staging-pr-7411 December 27, 2021 11:11 Inactive
Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

couple of v minor things and this is done 👍

static examples = [
{
title: 'HackerNews User Karma',
namedParams: { id: 'drumstick' },
Copy link
Member

Choose a reason for hiding this comment

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

This example give me 'user not found'. Lets replace it with one that does

Suggested change
namedParams: { id: 'drumstick' },
namedParams: { id: 'pg' },

Comment on lines 62 to +63
given(22222222222222222222222222).expect('22Y')
given(-999).expect('-999')
Copy link
Member

Choose a reason for hiding this comment

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

lets add a test for zero in here too

Suggested change
given(22222222222222222222222222).expect('22Y')
given(-999).expect('-999')
given(22222222222222222222222222).expect('22Y')
given(0).expect('0')
given(-999).expect('-999')

@shields-cd shields-cd temporarily deployed to shields-staging-pr-7411 December 28, 2021 11:16 Inactive
@chris48s
Copy link
Member

nice - thanks for your contribution

@tedmiston
Copy link

Question here: I assumed since this has been merged, that I'd be able to use it on shields.io. But when I search for "hn" or "hacker news", I get no results.

Am I missing something?

@chris48s
Copy link
Member

chris48s commented Aug 1, 2022

It does exist. Example badge https://img.shields.io/hackernews/user-karma/pg?style=social call

If you search "hackernews", or just "hacker" it shows up. That is.. not amazing, but if you wanted to submit a PR to add a few extra keywords, feel free. Here's an example of a service that defines some extra keywords for the examples:

const keywords = ['python', 'arm', 'raspberry pi']
export default class PiWheelsVersion extends BaseJsonService {
static category = 'version'
static route = { base: 'piwheels/v', pattern: ':wheel', queryParamSchema }
static examples = [
{
title: 'piwheels',
namedParams: { wheel: 'numpy' },
staticPreview: this.render({ version: '1.22.2' }),
keywords,
},
{
title: 'piwheels (including prereleases)',
namedParams: { wheel: 'flask' },
queryParams: {
include_prereleases: null,
},
staticPreview: this.render({ version: '2.0.0rc2' }),
keywords,
},
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants