@@ -3,7 +3,7 @@ import { Endpoints } from "@octokit/types";
33import store from "store2" ;
44import YAML from "yaml" ;
55
6- import { Repo } from "../types" ;
6+ import { Repo , Repository } from "../types" ;
77import { csvParse , tsvParse } from "d3-dsv" ;
88
99export type listCommitsResponse =
@@ -52,7 +52,15 @@ const getFilesFromRes = (res: any) => {
5252 . map ( ( file : any ) => file . path )
5353 . filter ( ( path : string ) => {
5454 const extension = path . split ( "." ) . pop ( ) || "" ;
55- const validExtensions = [ "csv" , "tsv" , "json" , "geojson" , "topojson" , "yml" , "yaml" ] ;
55+ const validExtensions = [
56+ "csv" ,
57+ "tsv" ,
58+ "json" ,
59+ "geojson" ,
60+ "topojson" ,
61+ "yml" ,
62+ "yaml" ,
63+ ] ;
5664 return (
5765 validExtensions . includes ( extension ) &&
5866 ! ignoredFiles . includes ( path . split ( "/" ) . slice ( - 1 ) [ 0 ] ) &&
@@ -129,7 +137,15 @@ export function fetchDataFile(params: FileParamsWithSHA) {
129137 const { filename, name, owner, sha } = params ;
130138 if ( ! filename ) return [ ] ;
131139 const fileType = filename . split ( "." ) . pop ( ) || "" ;
132- const validTypes = [ "csv" , "tsv" , "json" , "geojson" , "topojson" , "yml" , "yaml" ] ;
140+ const validTypes = [
141+ "csv" ,
142+ "tsv" ,
143+ "json" ,
144+ "geojson" ,
145+ "topojson" ,
146+ "yml" ,
147+ "yaml" ,
148+ ] ;
133149 if ( ! validTypes . includes ( fileType ) ) return [ ] ;
134150
135151 return wretch ( )
@@ -145,24 +161,27 @@ export function fetchDataFile(params: FileParamsWithSHA) {
145161 try {
146162 if ( fileType === "csv" ) {
147163 data = csvParse ( res ) ;
148- } else if ( [ "geojson" , "topojson" ] . includes ( fileType ) || filename . endsWith ( ".geo.json" ) ) {
164+ } else if (
165+ [ "geojson" , "topojson" ] . includes ( fileType ) ||
166+ filename . endsWith ( ".geo.json" )
167+ ) {
149168 data = JSON . parse ( res ) ;
150169 if ( data . features ) {
151170 const features = data . features . map ( ( feature : any ) => {
152- let geometry = { } as Record < string , any >
153- Object . keys ( feature ?. geometry ) . forEach ( key => {
171+ let geometry = { } as Record < string , any > ;
172+ Object . keys ( feature ?. geometry ) . forEach ( ( key ) => {
154173 geometry [ `geometry.${ key } ` ] = feature . geometry [ key ] ;
155- } )
156- let properties = { } as Record < string , any >
157- Object . keys ( feature ?. properties ) . forEach ( key => {
174+ } ) ;
175+ let properties = { } as Record < string , any > ;
176+ Object . keys ( feature ?. properties ) . forEach ( ( key ) => {
158177 properties [ `properties.${ key } ` ] = feature . properties [ key ] ;
159- } )
160- const { geometry : g , properties : p , ...restOfKeys } = feature ;
161- return { ...restOfKeys , ...geometry , ...properties } ;
162- } )
178+ } ) ;
179+ const { geometry : g , properties : p , ...restOfKeys } = feature ;
180+ return { ...restOfKeys , ...geometry , ...properties } ;
181+ } ) ;
163182 // make features the first key of the object
164- const { features : f , ...restOfData } = data
165- data = { features, ...restOfData }
183+ const { features : f , ...restOfData } = data ;
184+ data = { features, ...restOfData } ;
166185 }
167186 } else if ( fileType === "json" ) {
168187 data = JSON . parse ( res ) ;
@@ -246,6 +265,16 @@ export function fetchDataFile(params: FileParamsWithSHA) {
246265 } ) ;
247266}
248267
268+ export async function fetchOrgRepos ( orgName : string ) {
269+ const res = await githubWretch
270+ . url ( `/search/repositories` )
271+ . query ( { q : `topic:flat-data org:${ orgName } ` , per_page : 100 } )
272+ . get ( )
273+ . json ( ) ;
274+
275+ return res . items ;
276+ }
277+
249278const stringifyValue = ( data : any ) => {
250279 if ( typeof data === "object" ) return JSON . stringify ( data , undefined , 2 ) ;
251280 return data . toString ( ) ;
0 commit comments