#183 show license from github

This commit is contained in:
neil 2023-02-10 09:26:13 +08:00
parent e2a08a62dc
commit 6bdc612af4
2 changed files with 15 additions and 4 deletions

View file

@ -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<Cont
}
return contributors;
}
export async function getRepoAsPackage(owner: string, repo: string): Promise<Partial<Package>> {
const req = await axios.get(`https://api.github.com/repos/${owner}/${repo}`);
const pkg: Partial<Package> = {};
if (req.data) {
pkg.license = req.data?.license?.name || '';
}
return pkg;
}

View file

@ -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);