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

[SourceForge] Added badges for SourceForge #9078

Merged
merged 12 commits into from
Apr 17, 2023
13 changes: 13 additions & 0 deletions services/sourceforge/sourceforge-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BaseJsonService } from '../index.js'

export default class BaseSourceForgeService extends BaseJsonService {
async fetch({ project, schema }) {
return this._requestJson({
url: `https://sourceforge.net/rest/p/${project}/`,
schema,
errorMessages: {
404: 'project not found',
},
})
}
}
54 changes: 54 additions & 0 deletions services/sourceforge/sourceforge-commit-count.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { metric } from '../text-formatters.js'

const schema = Joi.object({
commit_count: Joi.number().required(),
}).required()

export default class SourceforgeCommitCount extends BaseJsonService {
static category = 'activity'

static route = {
base: 'sourceforge/commit-count',
pattern: ':project',
}

static examples = [
{
title: 'SourceForge commit count',
namedParams: {
project: 'guitarix',
},
staticPreview: this.render({
commitCount: 1365,
}),
},
]

static defaultBadgeData = { label: 'commit count' }

static render({ commitCount }) {
return {
message: metric(commitCount),
color: 'blue',
}
}

async fetch({ project }) {
return this._requestJson({
url: `https://sourceforge.net/rest/p/${project}/git`,
schema,
errorMessages: {
404: 'project not found',
},
})
}

async handle({ project }) {
const body = await this.fetch({ project })
return this.constructor.render({
commitCount: body.commit_count,
})
}
}
11 changes: 11 additions & 0 deletions services/sourceforge/sourceforge-commit-count.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isMetric } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('commit count')
.get('/guitarix.json')
.expectBadge({ label: 'commit count', message: isMetric })

t.create('commit count (project not found)')
.get('/that-doesnt-exist.json')
.expectBadge({ label: 'commit count', message: 'project not found' })
43 changes: 43 additions & 0 deletions services/sourceforge/sourceforge-contributors.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Joi from 'joi'
import { renderContributorBadge } from '../contributor-count.js'
import BaseSourceForgeService from './sourceforge-base.js'

const schema = Joi.object({
developers: Joi.array().required(),
}).required()

export default class SourceforgeContributors extends BaseSourceForgeService {
static category = 'activity'

static route = {
base: 'sourceforge/contributors',
pattern: ':project',
}

static examples = [
{
title: 'SourceForge contributors',
namedParams: {
project: 'guitarix',
},
staticPreview: this.render({
contributorCount: 9,
}),
},
]

static defaultBadgeData = { label: 'contributors' }

static render({ contributorCount }) {
return renderContributorBadge({
contributorCount,
})
}

async handle({ project }) {
const body = await this.fetch({ project, schema })
return this.constructor.render({
contributorCount: body.developers.length,
})
}
}
11 changes: 11 additions & 0 deletions services/sourceforge/sourceforge-contributors.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isMetric } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('contributors')
.get('/guitarix.json')
.expectBadge({ label: 'contributors', message: isMetric })

t.create('contributors (project not found)')
.get('/that-doesnt-exist.json')
.expectBadge({ label: 'contributors', message: 'project not found' })
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ const intervalMap = {
},
}

export default class Sourceforge extends BaseJsonService {
export default class SourceforgeDownloads extends BaseJsonService {
static category = 'downloads'

static route = {
base: 'sourceforge',
base: 'sourceforge/downloads',
pattern: ':interval(dt|dm|dw|dd)/:project/:folder*',
}

static examples = [
{
title: 'SourceForge',
title: 'SourceForge Downloads',
pattern: ':interval(dt|dm|dw|dd)/:project',
namedParams: {
interval: 'dm',
Expand All @@ -49,7 +49,7 @@ export default class Sourceforge extends BaseJsonService {
}),
},
{
title: 'SourceForge',
title: 'SourceForge Downloads (folder)',
pattern: ':interval(dt|dm|dw|dd)/:project/:folder',
namedParams: {
interval: 'dm',
Expand Down
42 changes: 42 additions & 0 deletions services/sourceforge/sourceforge-languages.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import BaseSourceForgeService from './sourceforge-base.js'

const schema = Joi.object({
categories: Joi.object({
language: Joi.array().required(),
}).required(),
}).required()

export default class SourceforgeLanguages extends BaseSourceForgeService {
static category = 'analysis'

static route = {
base: 'sourceforge/languages',
pattern: ':project',
}

static examples = [
{
title: 'SourceForge languages',
namedParams: {
project: 'mingw',
},
staticPreview: this.render(6),
},
]

static defaultBadgeData = { label: 'languages' }

static render(languages) {
return {
message: metric(languages),
color: 'blue',
}
}

async handle({ project }) {
const body = await this.fetch({ project, schema })
return this.constructor.render(body.categories.language.length)
}
}
11 changes: 11 additions & 0 deletions services/sourceforge/sourceforge-languages.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isMetric } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('languages')
.get('/guitarix.json')
.expectBadge({ label: 'languages', message: isMetric })

t.create('languages (project not found)')
.get('/that-doesnt-exist.json')
.expectBadge({ label: 'languages', message: 'project not found' })
61 changes: 61 additions & 0 deletions services/sourceforge/sourceforge-last-commit.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { formatDate } from '../text-formatters.js'
import { age as ageColor } from '../color-formatters.js'

const schema = Joi.object({
commits: Joi.array()
.items(
Joi.object({
committed_date: Joi.string().required(),
}).required()
)
.required(),
}).required()

export default class SourceforgeLastCommit extends BaseJsonService {
static category = 'activity'

static route = {
base: 'sourceforge/last-commit',
pattern: ':project',
}

static examples = [
{
title: 'SourceForge last commit',
namedParams: {
project: 'guitarix',
},
staticPreview: this.render({
commitDate: 1653556285,
}),
},
]

static defaultBadgeData = { label: 'last commit' }

static render({ commitDate }) {
return {
message: formatDate(new Date(commitDate)),
color: ageColor(new Date(commitDate)),
}
}
Av32000 marked this conversation as resolved.
Show resolved Hide resolved

async fetch({ project }) {
return this._requestJson({
url: `https://sourceforge.net/rest/p/${project}/git/commits`,
schema,
errorMessages: {
404: 'project not found',
},
})
}

async handle({ project }) {
const body = await this.fetch({ project })
return this.constructor.render({
commitDate: body.commits[0].committed_date,
})
}
}
11 changes: 11 additions & 0 deletions services/sourceforge/sourceforge-last-commit.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isFormattedDate } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('last commit')
.get('/guitarix.json')
.expectBadge({ label: 'last commit', message: isFormattedDate })

t.create('last commit (project not found)')
.get('/that-doesnt-exist.json')
.expectBadge({ label: 'last commit', message: 'project not found' })
48 changes: 48 additions & 0 deletions services/sourceforge/sourceforge-platform.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Joi from 'joi'
import BaseSourceForgeService from './sourceforge-base.js'

const schema = Joi.object({
categories: Joi.object({
os: Joi.array()
.items({
fullname: Joi.string().required(),
})
.required(),
}).required(),
}).required()

export default class SourceforgePlatform extends BaseSourceForgeService {
static category = 'platform-support'

static route = {
base: 'sourceforge/platform',
pattern: ':project',
}

static examples = [
{
title: 'SourceForge Platform',
namedParams: {
project: 'guitarix',
},
staticPreview: this.render({
platforms: ['linux', 'bsd'],
}),
},
]

static defaultBadgeData = { label: 'platform' }

static render({ platforms }) {
return {
message: platforms.join(' | '),
}
}

async handle({ project }) {
const body = await this.fetch({ project, schema })
return this.constructor.render({
platforms: body.categories.os.map(obj => obj.fullname),
})
}
}
11 changes: 11 additions & 0 deletions services/sourceforge/sourceforge-platform.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('platform')
.get('/guitarix.json')
.expectBadge({ label: 'platform', message: Joi.string().required() })

t.create('platform (project not found)')
.get('/that-doesnt-exist.json')
.expectBadge({ label: 'platform', message: 'project not found' })