From 78124a009f83f25b381aed985137bd9af773a9fb Mon Sep 17 00:00:00 2001 From: zhengyi Date: Fri, 29 Dec 2023 23:12:58 +0800 Subject: [PATCH] :sparkles: Add git support for gitee Fix https://git.mczhengyi.top/zhengyi/halo-render/issues/5 --- demo/index.js | 4 +++ src/utils/git-processor/git-processor.ts | 4 ++- src/utils/git-processor/gitee-utils.ts | 35 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/utils/git-processor/gitee-utils.ts diff --git a/demo/index.js b/demo/index.js index 616ede5..eacc530 100644 --- a/demo/index.js +++ b/demo/index.js @@ -50,6 +50,10 @@ git:[@github/justice2001/halo-plugin-vditor] --- +git:[@gitee/blossom-editor/blossom] + +--- + drive:baidu name: 网站资源集合 link: https://www.baidu.com/ diff --git a/src/utils/git-processor/git-processor.ts b/src/utils/git-processor/git-processor.ts index 674951b..3b911dd 100644 --- a/src/utils/git-processor/git-processor.ts +++ b/src/utils/git-processor/git-processor.ts @@ -1,10 +1,12 @@ import {getGitHubInfo} from "./github-utils"; import {HALO_RENDER_CACHE_VERSION, LANGUAGE_COLOR, RENDER_CLASS} from "../../constant"; +import {getGiteeInfo} from "./gitee-utils"; export const cache: {[key: string]: RepoInfo|-1} = {} export const utils: {[key: string]: (args: IGitArgs) => Promise} = { - "github": getGitHubInfo + "github": getGitHubInfo, + "gitee": getGiteeInfo } export const icons: {[key: string]: string} = { diff --git a/src/utils/git-processor/gitee-utils.ts b/src/utils/git-processor/gitee-utils.ts new file mode 100644 index 0000000..c1a9cf5 --- /dev/null +++ b/src/utils/git-processor/gitee-utils.ts @@ -0,0 +1,35 @@ +import {IGitArgs, RepoInfo} from "./git-processor"; + +export async function getGiteeInfo(args: IGitArgs): Promise { + const info = await fetch(`https://gitee.com/api/v5/repos/${args.owner}/${args.repo}`) + const json = await info.json() + console.log(info) + if (info.status !== 200) return new Promise((resolve, reject) => { + reject({ + code: info.status, + msg: json['message'] + }) + }) + const topics: Array = [] + json["project_labels"].forEach((label: { + id: number; + name: string; + ident: string + }) => { + topics.push(label.name) + }) + return { + platform: "gitee", + url: json["html_url"], + owner: json["owner"]["login"], + name: json["name"], + stars: json["stargazers_count"], + watchers: json["watchers_count"], + language: json["language"], + description: json["description"], + openIssues: json["open_issues_count"], + lastPush: json["pushed_at"], + forks: json["forks_count"], + topic: topics + } +}