From 6bdc612af45214dad9b0326feb4b40b632954dec Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 10 Feb 2023 09:26:13 +0800 Subject: [PATCH] #183 show license from github --- modules/desktop/src/libs/github.ts | 11 ++++++++++- modules/desktop/src/libs/stores/pkgs.ts | 8 +++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/desktop/src/libs/github.ts b/modules/desktop/src/libs/github.ts index ce476d4..e528e00 100644 --- a/modules/desktop/src/libs/github.ts +++ b/modules/desktop/src/libs/github.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import type { Contributor } from '@tea/ui/types'; +import type { Contributor, Package } from '@tea/ui/types'; const yaml = window.require('yaml'); export async function getPackageYaml(pkgYamlUrl: string) { @@ -37,3 +37,12 @@ export async function getContributors(owner: string, repo: string): Promise> { + const req = await axios.get(`https://api.github.com/repos/${owner}/${repo}`); + const pkg: Partial = {}; + if (req.data) { + pkg.license = req.data?.license?.name || ''; + } + return pkg; +} diff --git a/modules/desktop/src/libs/stores/pkgs.ts b/modules/desktop/src/libs/stores/pkgs.ts index 9e1dcda..bebeacd 100644 --- a/modules/desktop/src/libs/stores/pkgs.ts +++ b/modules/desktop/src/libs/stores/pkgs.ts @@ -4,7 +4,7 @@ import { getPackages } from '@api'; import Fuse from 'fuse.js'; import { getPackage } from '@api'; -import { getReadme, getContributors } from '$libs/github'; +import { getReadme, getContributors, getRepoAsPackage } from '$libs/github'; export default function initPackagesStore() { let initialized = false; @@ -52,14 +52,16 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}). }; if (pkg.github) { const [owner, repo] = pkg.github.split('/'); - const [readme, contributors] = await Promise.all([ + const [readme, contributors, repoData] = await Promise.all([ getReadme(owner, repo), - getContributors(owner, repo) + getContributors(owner, repo), + getRepoAsPackage(owner, repo) ]); if (readme) { updatedPackage.readme_md = readme; } updatedPackage.contributors = contributors; + updatedPackage.license = repoData.license; } updatePackageProp(guiPkg.full_name!, updatedPackage);