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

migrate some services from examples to openApi part 46; affects [codeclimate librariesio nexus] and securityheaders #9933

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
70 changes: 35 additions & 35 deletions services/codeclimate/codeclimate-analysis.service.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Joi from 'joi'
import { colorScale, letterScore } from '../color-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService, NotFound } from '../index.js'
import { keywords, isLetterGrade, fetchRepo } from './codeclimate-common.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'
import { isLetterGrade, fetchRepo } from './codeclimate-common.js'

const schema = Joi.object({
data: Joi.object({
Expand Down Expand Up @@ -93,43 +93,43 @@ export default class CodeclimateAnalysis extends BaseJsonService {
':variant(maintainability|maintainability-percentage|tech-debt|issues)/:user/:repo',
}

static examples = [
{
title: 'Code Climate maintainability',
pattern:
':format(maintainability|maintainability-percentage)/:user/:repo',
namedParams: {
format: 'maintainability',
user: 'tensorflow',
repo: 'models',
static openApi = {
'/codeclimate/{variant}/{user}/{repo}': {
get: {
summary: 'Code Climate maintainability',
parameters: pathParams(
{
name: 'variant',
example: 'maintainability',
schema: {
type: 'string',
enum: ['maintainability', 'maintainability-percentage'],
},
},
{ name: 'user', example: 'tensorflow' },
{ name: 'repo', example: 'models' },
),
},
staticPreview: this.render({
variant: 'maintainability',
maintainabilityLetter: 'F',
}),
keywords,
},
{
title: 'Code Climate issues',
pattern: 'issues/:user/:repo',
namedParams: { user: 'twbs', repo: 'bootstrap' },
staticPreview: this.render({
variant: 'issues',
issueCount: '89',
}),
keywords,
'/codeclimate/tech-debt/{user}/{repo}': {
get: {
summary: 'Code Climate issues',
parameters: pathParams(
{ name: 'user', example: 'tensorflow' },
{ name: 'repo', example: 'models' },
),
},
},
{
title: 'Code Climate technical debt',
pattern: 'tech-debt/:user/:repo',
namedParams: { user: 'tensorflow', repo: 'models' },
staticPreview: this.render({
variant: 'tech-debt',
techDebtPercentage: 3.0,
}),
keywords,
'/codeclimate/issues/{user}/{repo}': {
get: {
summary: 'Code Climate technical debt',
parameters: pathParams(
{ name: 'user', example: 'tensorflow' },
{ name: 'repo', example: 'models' },
),
},
},
]
}

static render({ variant, ...props }) {
const { render } = variantMap[variant]
Expand Down
2 changes: 1 addition & 1 deletion services/codeclimate/codeclimate-analysis.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ t.create('issues when outer user repos query returns multiple items')
relationships: {
latest_default_branch_snapshot: {
data: {
id: '64786eee4fedea000101580d',
id: '65ae115f34117d0001055101',
type: 'snapshots',
},
},
Expand Down
4 changes: 1 addition & 3 deletions services/codeclimate/codeclimate-common.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Joi from 'joi'
import { NotFound } from '../index.js'

const keywords = ['codeclimate']

const isLetterGrade = Joi.equal('A', 'B', 'C', 'D', 'E', 'F').required()

const repoSchema = Joi.object({
Expand Down Expand Up @@ -39,4 +37,4 @@ async function fetchRepo(serviceInstance, { user, repo }) {
return repoInfos
}

export { keywords, isLetterGrade, fetchRepo }
export { isLetterGrade, fetchRepo }
32 changes: 16 additions & 16 deletions services/codeclimate/codeclimate-coverage.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi'
import { coveragePercentage, letterScore } from '../color-formatters.js'
import { BaseJsonService, NotFound } from '../index.js'
import { keywords, isLetterGrade, fetchRepo } from './codeclimate-common.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'
import { isLetterGrade, fetchRepo } from './codeclimate-common.js'

const schema = Joi.object({
data: Joi.object({
Expand All @@ -21,22 +21,22 @@ export default class CodeclimateCoverage extends BaseJsonService {
pattern: ':format(coverage|coverage-letter)/:user/:repo',
}

static examples = [
{
title: 'Code Climate coverage',
namedParams: {
format: 'coverage',
user: 'codeclimate',
repo: 'codeclimate',
static openApi = {
'/codeclimate/{format}/{user}/{repo}': {
get: {
summary: 'Code Climate coverage',
parameters: pathParams(
{
name: 'format',
example: 'coverage',
schema: { type: 'string', enum: this.getEnum('format') },
},
{ name: 'user', example: 'codeclimate' },
{ name: 'repo', example: 'codeclimate' },
),
},
staticPreview: this.render({
format: 'coverage',
percentage: 95.123,
letter: 'A',
}),
keywords,
},
]
}

static render({ wantLetter, percentage, letter }) {
if (wantLetter) {
Expand Down
2 changes: 1 addition & 1 deletion services/codeclimate/codeclimate-coverage.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ t.create('test coverage when outer user repos query returns multiple items')
},
latest_default_branch_test_report: {
data: {
id: '6463c8a3e3bc340001004bce',
id: '65a1662cb0077b00013cb4de',
Copy link
Member Author

@chris48s chris48s Feb 11, 2024

Choose a reason for hiding this comment

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

I feel like this is not a sustainable solution for this test, but I think I'm not going to deal with re-writing this test in this PR as it is a bit of a yak-shave that isn't really related to the original point of this PR.

type: 'test_reports',
},
},
Expand Down
70 changes: 18 additions & 52 deletions services/librariesio/librariesio-dependencies.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import LibrariesIoBase from './librariesio-base.js'
import {
transform,
Expand All @@ -24,62 +25,27 @@ class LibrariesIoProjectDependencies extends LibrariesIoBase {
pattern: ':platform/:scope(@[^/]+)?/:packageName/:version?',
}

static examples = [
{
title: 'Libraries.io dependency status for latest release',
pattern: ':platform/:packageName',
namedParams: {
platform: 'hex',
packageName: 'phoenix',
static openApi = {
'/librariesio/release/{platform}/{packageName}': {
get: {
summary: 'Libraries.io dependency status for latest release',
parameters: pathParams(
{ name: 'platform', example: 'npm' },
{ name: 'packageName', example: '@babel/core' },
),
},
staticPreview: renderDependenciesBadge({
deprecatedCount: 0,
outdatedCount: 1,
}),
},
{
title: 'Libraries.io dependency status for specific release',
pattern: ':platform/:packageName/:version',
namedParams: {
platform: 'hex',
packageName: 'phoenix',
version: '1.0.3',
'/librariesio/release/{platform}/{packageName}/{version}': {
get: {
summary: 'Libraries.io dependency status for specific release',
parameters: pathParams(
{ name: 'platform', example: 'npm' },
{ name: 'packageName', example: '@babel/core' },
{ name: 'version', example: '7.0.0' },
),
},
staticPreview: renderDependenciesBadge({
deprecatedCount: 0,
outdatedCount: 3,
}),
},
{
title:
'Libraries.io dependency status for latest release, scoped npm package',
pattern: ':platform/:scope/:packageName',
namedParams: {
platform: 'npm',
scope: '@babel',
packageName: 'core',
},
staticPreview: renderDependenciesBadge({
deprecatedCount: 8,
outdatedCount: 0,
}),
},
{
title:
'Libraries.io dependency status for specific release, scoped npm package',
pattern: ':platform/:scope/:packageName/:version',
namedParams: {
platform: 'npm',
scope: '@babel',
packageName: 'core',
version: '7.0.0',
},
staticPreview: renderDependenciesBadge({
deprecatedCount: 12,
outdatedCount: 0,
}),
},
]
}

static _cacheLength = 900

Expand Down
Loading
Loading