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

Add a [pub] publisher badge #7715

Merged
merged 7 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
49 changes: 49 additions & 0 deletions services/pub/pub-publisher.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'

const schema = Joi.object({
publisherId: Joi.string().allow(null).required(),
}).required()

class PubPublisher extends BaseJsonService {
static category = 'other'

static route = {
base: 'pub/publisher',
pattern: ':packageName',
}

static examples = [
{
title: 'Pub Publisher',
namedParams: { packageName: 'dart.dev' },
staticPreview: {
label: 'publisher',
message: 'dart.dev',
devoncarew marked this conversation as resolved.
Show resolved Hide resolved
color: 'blue',
},
calebcartwright marked this conversation as resolved.
Show resolved Hide resolved
keywords: ['dart', 'dartlang'],
},
]

static defaultBadgeData = { label: 'publisher' }

async fetch({ packageName }) {
return this._requestJson({
schema,
url: `https://pub.dev/api/packages/${packageName}/publisher`,
})
}

async handle({ packageName }) {
const data = await this.fetch({ packageName })
const publisher = data.publisherId
return {
label: 'publisher',
message: publisher == null ? 'unverified' : publisher,
color: publisher == null ? 'red' : 'blue',
devoncarew marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

export { PubPublisher }
devoncarew marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions services/pub/pub-publisher.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ServiceTester } from '../tester.js'
export const t = new ServiceTester({
id: 'PubPublisher',
title: 'Pub Publisher',
pathPrefix: '/pub',
})
devoncarew marked this conversation as resolved.
Show resolved Hide resolved

t.create('package publisher').get('/publisher/path.json').expectBadge({
devoncarew marked this conversation as resolved.
Show resolved Hide resolved
label: 'publisher',
message: 'dart.dev',
})

t.create('package not verified publisher')
.get('/publisher/utf.json')
devoncarew marked this conversation as resolved.
Show resolved Hide resolved
.expectBadge({
label: 'publisher',
message: 'unverified',
color: 'red',
})

t.create('package not found')
.get('/publisher/does-not-exist.json')
devoncarew marked this conversation as resolved.
Show resolved Hide resolved
.expectBadge({
label: 'publisher',
message: 'not found',
})