From b4487415f89cb65326798389805213f88a49ed40 Mon Sep 17 00:00:00 2001 From: Amio Jin Date: Wed, 28 Jun 2023 10:50:05 +0800 Subject: [PATCH] feat: migrate /codeclimate (#614) --- libs/badge-list.ts | 1 - libs/badge-list2.ts | 2 ++ next.config.js | 1 + {api- => pages/api}/codeclimate.ts | 17 +++++++++++++---- vercel.json | 4 ---- 5 files changed, 16 insertions(+), 9 deletions(-) rename {api- => pages/api}/codeclimate.ts (88%) diff --git a/libs/badge-list.ts b/libs/badge-list.ts index 30d02b3a..27b0a929 100644 --- a/libs/badge-list.ts +++ b/libs/badge-list.ts @@ -41,7 +41,6 @@ export const liveBadgeList = [ 'codecov', 'codacy', 'coveralls', - 'codeclimate', 'azure-pipelines', // quality & metrics 'snyk', diff --git a/libs/badge-list2.ts b/libs/badge-list2.ts index 8510e529..0fb39afe 100644 --- a/libs/badge-list2.ts +++ b/libs/badge-list2.ts @@ -3,6 +3,7 @@ import github from '../pages/api/github' import npm from '../pages/api/npm' import bundlephobia from '../pages/api/bundlephobia' import packagephobia from '../pages/api/packagephobia' +import codeclimate from '../pages/api/codeclimate' import chromeWebStore from '../pages/api/chrome-web-store' import hackage from '../pages/api/hackage' import pypi from '../pages/api/pypi' @@ -16,6 +17,7 @@ export default { npm: npm.meta, bundlephobia: bundlephobia.meta, packagephobia: packagephobia.meta, + codeclimate: codeclimate.meta, 'chrome-web-store': chromeWebStore.meta, hackage: hackage.meta, pypi: pypi.meta, diff --git a/next.config.js b/next.config.js index 7d16b5d4..7d22d768 100644 --- a/next.config.js +++ b/next.config.js @@ -46,6 +46,7 @@ const nextConfig = { '/npm', '/bundlephobia', '/packagephobia', + '/codeclimate', '/chrome-web-store', '/hackage', '/ppm', diff --git a/api-/codeclimate.ts b/pages/api/codeclimate.ts similarity index 88% rename from api-/codeclimate.ts rename to pages/api/codeclimate.ts index 757da3bd..7258564b 100644 --- a/api-/codeclimate.ts +++ b/pages/api/codeclimate.ts @@ -1,6 +1,9 @@ -import got from '../libs/got' -import { coverage as cov, scale } from '../libs/utils' -import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler' +import got from '../../libs/got' +import { coverage as cov, scale } from '../../libs/utils' +import { createBadgenHandler, PathArgs } from '../../libs/create-badgen-handler-next' +import type { BadgenParams } from '../../libs/types' + + export default createBadgenHandler({ title: 'Code Climate', @@ -18,7 +21,7 @@ export default createBadgenHandler({ } }) -async function handler ({ topic, owner, repo }: PathArgs) { +async function handler ({ topic, owner, repo }: PathArgs): Promise { const api = `https://api.codeclimate.com/v1/repos?github_slug=${owner}/${repo}` const result = await got(api).json() const meta = result.data[0] @@ -105,6 +108,12 @@ const getReport = async (repoId, reportId, type, topic) => { status: cov(attributes.rating.measure.value), color: scale('coverage')(attributes.rating.measure.value) } + default: + return { + subject: 'codeclimate', + status: 'unknown topic', + color: 'gray' + } } } diff --git a/vercel.json b/vercel.json index a9bd6de7..b484e5cb 100644 --- a/vercel.json +++ b/vercel.json @@ -30,10 +30,6 @@ "source": "/codacy/:match*", "destination": "https://v2022.badgen.net/codacy/:match*" }, - { - "source": "/codeclimate/:match*", - "destination": "https://v2022.badgen.net/codeclimate/:match*" - }, { "source": "/codecov/:match*", "destination": "https://v2022.badgen.net/codecov/:match*"