-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonlydust.ts
60 lines (50 loc) · 1.35 KB
/
onlydust.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { promises as fs } from 'fs';
import axios from 'axios';
interface Config {
hack_url: string;
project_url_prefix: string;
}
interface Project {
id: string;
slug: string;
}
interface HackData {
projects: Project[];
}
interface ProjectData {
organizations: {
repos: {
htmlUrl: string;
isIncludedInProject: boolean;
}[];
}[];
}
async function getRepoUrls(): Promise<string[]> {
try {
// Read config.json
const configData = await fs.readFile('config.json', 'utf-8');
const config: Config = JSON.parse(configData);
// Fetch hack data
const hackResponse = await axios.get<HackData>(config.hack_url);
const hackData = hackResponse.data;
// Fetch project details and collect repo URLs
const repoUrls: string[] = [];
for (const project of hackData.projects) {
const projectUrl = `${config.project_url_prefix}${project.slug}`;
const projectResponse = await axios.get<ProjectData>(projectUrl);
const projectData = projectResponse.data;
projectData.organizations.forEach(org => {
org.repos.forEach(repo => {
if (repo.isIncludedInProject) {
repoUrls.push(repo.htmlUrl);
}
});
});
}
return repoUrls;
} catch (error) {
console.error('Error fetching repo URLs:', error);
return [];
}
}
export default getRepoUrls;