mirror of
https://github.com/ivabus/gui
synced 2025-06-08 00:00:27 +03:00
#183 show license from github
This commit is contained in:
parent
e2a08a62dc
commit
6bdc612af4
2 changed files with 15 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import type { Contributor } from '@tea/ui/types';
|
import type { Contributor, Package } from '@tea/ui/types';
|
||||||
const yaml = window.require('yaml');
|
const yaml = window.require('yaml');
|
||||||
|
|
||||||
export async function getPackageYaml(pkgYamlUrl: string) {
|
export async function getPackageYaml(pkgYamlUrl: string) {
|
||||||
|
@ -37,3 +37,12 @@ export async function getContributors(owner: string, repo: string): Promise<Cont
|
||||||
}
|
}
|
||||||
return contributors;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { getPackages } from '@api';
|
||||||
import Fuse from 'fuse.js';
|
import Fuse from 'fuse.js';
|
||||||
import { getPackage } from '@api';
|
import { getPackage } from '@api';
|
||||||
|
|
||||||
import { getReadme, getContributors } from '$libs/github';
|
import { getReadme, getContributors, getRepoAsPackage } from '$libs/github';
|
||||||
|
|
||||||
export default function initPackagesStore() {
|
export default function initPackagesStore() {
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
@ -52,14 +52,16 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
||||||
};
|
};
|
||||||
if (pkg.github) {
|
if (pkg.github) {
|
||||||
const [owner, repo] = pkg.github.split('/');
|
const [owner, repo] = pkg.github.split('/');
|
||||||
const [readme, contributors] = await Promise.all([
|
const [readme, contributors, repoData] = await Promise.all([
|
||||||
getReadme(owner, repo),
|
getReadme(owner, repo),
|
||||||
getContributors(owner, repo)
|
getContributors(owner, repo),
|
||||||
|
getRepoAsPackage(owner, repo)
|
||||||
]);
|
]);
|
||||||
if (readme) {
|
if (readme) {
|
||||||
updatedPackage.readme_md = readme;
|
updatedPackage.readme_md = readme;
|
||||||
}
|
}
|
||||||
updatedPackage.contributors = contributors;
|
updatedPackage.contributors = contributors;
|
||||||
|
updatedPackage.license = repoData.license;
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePackageProp(guiPkg.full_name!, updatedPackage);
|
updatePackageProp(guiPkg.full_name!, updatedPackage);
|
||||||
|
|
Loading…
Reference in a new issue