Implement dataset page v0.1 + Home improvements (#892)
* [examples/openspending][xl]: implement dataset page v0.1, add pagination to the datasets grid * [examples/openspending][m] - fix build + add tests --------- Co-authored-by: Luccas Mateus de Medeiros Gomes <luccasmmg@gmail.com>
This commit is contained in:
@@ -98,6 +98,7 @@ export interface TabularDataResource {
|
||||
key?: string;
|
||||
path?: string;
|
||||
size?: number;
|
||||
bytes?: number;
|
||||
}
|
||||
|
||||
export interface Field {
|
||||
|
||||
@@ -5,13 +5,14 @@ export function loadDataPackage(datapackage: FiscalDataPackage, repo): Project {
|
||||
return {
|
||||
name: datapackage.name,
|
||||
title: datapackage.title,
|
||||
description: datapackage.description || null,
|
||||
owner: {
|
||||
name: repo.owner.login,
|
||||
logo: repo.owner.avatar_url,
|
||||
// TODO: make this title work
|
||||
title: repo.owner.login,
|
||||
},
|
||||
repo: { name: repo, full_name: repo.full_name },
|
||||
repo: { name: repo.name, full_name: repo.full_name, url: repo.html_url },
|
||||
files: datapackage.resources,
|
||||
author: datapackage.author ? datapackage.author : null,
|
||||
cityCode: datapackage.cityCode ? datapackage.cityCode : null,
|
||||
|
||||
@@ -5,10 +5,11 @@ import {
|
||||
|
||||
export interface Project {
|
||||
owner: { name: string; logo?: string; title?: string }; // Info about the owner of the data repo
|
||||
repo: { name: string; full_name: string }; // Info about the the data repo
|
||||
repo: { name: string; full_name: string; url: string }; // Info about the the data repo
|
||||
files: TabularDataResource[];
|
||||
name: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
author?: string;
|
||||
cityCode?: string;
|
||||
countryCode?: string;
|
||||
|
||||
@@ -13,8 +13,7 @@ export interface GithubProject {
|
||||
export async function getProjectReadme(
|
||||
owner: string,
|
||||
repo: string,
|
||||
branch: string,
|
||||
readme: string,
|
||||
branch: string = 'main',
|
||||
github_pat?: string
|
||||
) {
|
||||
const octokit = new Octokit({ auth: github_pat });
|
||||
@@ -22,7 +21,7 @@ export async function getProjectReadme(
|
||||
const response = await octokit.rest.repos.getContent({
|
||||
owner,
|
||||
repo,
|
||||
path: readme,
|
||||
path: 'README.md',
|
||||
ref: branch,
|
||||
});
|
||||
const data = response.data as { content?: string };
|
||||
@@ -125,7 +124,6 @@ export async function getProject(project: GithubProject, github_pat?: string) {
|
||||
project.owner,
|
||||
project.repo,
|
||||
project.branch,
|
||||
project.readme,
|
||||
github_pat
|
||||
);
|
||||
|
||||
@@ -185,8 +183,43 @@ export async function getProjectDataPackage(
|
||||
}
|
||||
const decodedContent = Buffer.from(fileContent, 'base64').toString();
|
||||
const datapackage = JSON.parse(decodedContent);
|
||||
return {...datapackage, repo };
|
||||
|
||||
return { ...datapackage, repo };
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllProjectsFromOrg(
|
||||
org: string,
|
||||
branch?: string,
|
||||
github_pat?: string
|
||||
) {
|
||||
const octokit = new Octokit({ auth: github_pat });
|
||||
const repos = await octokit.rest.repos.listForOrg({
|
||||
org,
|
||||
type: 'public',
|
||||
per_page: 100,
|
||||
});
|
||||
let failedProjects = [];
|
||||
const projects = await Promise.all(
|
||||
repos.data.map(async (_repo) => {
|
||||
const project = await getProjectDataPackage(
|
||||
org,
|
||||
_repo.name,
|
||||
branch ? branch : 'main',
|
||||
github_pat
|
||||
);
|
||||
if (!project) {
|
||||
failedProjects.push(_repo.name);
|
||||
return null;
|
||||
}
|
||||
|
||||
return { datapackage: project, repo: _repo };
|
||||
})
|
||||
);
|
||||
return {
|
||||
results: projects.filter((item) => item !== null),
|
||||
failed: failedProjects,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user