Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalie Abrams committed Feb 20, 2025
1 parent c00a24b commit c975376
Showing 1 changed file with 88 additions and 82 deletions.
170 changes: 88 additions & 82 deletions website/src/scripts/update-gh-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,108 @@ import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';


export const __dirname = path.dirname(fileURLToPath(import.meta.url));

async function updateReposData() {
try {
const responses = await Promise.all(
repos.map((repo) =>
fetch(`https://api.github.com/repos/${repo}`, {
headers: {
Accept: "application/json",
"User-Agent": "Cloudflare Worker",
Authorization: `Bearer ${process.env.GH_API_KEY}`,
},
})
),
);

// Check if any response failed
for (const response of responses) {
if (!response.ok) {
throw new Error(`GitHub API request failed: ${response.statusText}`);
}
}

async function updateReposData() {
const repositories = await Promise.all(responses.map((res) => res.json()));
const filePath = path.join(__dirname, '../data/repositories.json');
await fs.writeFile(filePath, JSON.stringify(repositories, null, 2));
} catch (error) {
console.error("Error fetching repos:", error);
const filePath = path.join(__dirname, '../data/repositories.json');
await fs.writeFile(filePath, '[]');
process.exit(1);
}
}

async function updateMembersData() {
try {
const responses = await Promise.all(
contributors.map((user) =>
fetch(`https://api.github.com/users/${user}`, {
headers: {
Accept: "application/json",
"User-Agent": "Cloudflare Worker",
Authorization: `Bearer ${process.env.GH_API_KEY}`,
},
})
),
);

// Check if any response failed
for (const response of responses) {
if (!response.ok) {
throw new Error(`GitHub API request failed: ${response.statusText}`);
}
}

const members = await Promise.all(responses.map((res) => res.json()));
const filePath = path.join(__dirname, '../data/members.json');
await fs.writeFile(filePath, JSON.stringify(members, null, 2));
} catch (error) {
console.error("Error fetching members:", error);
const filePath = path.join(__dirname, '../data/members.json');
await fs.writeFile(filePath, '[]');
process.exit(1);
}
}

//Get repositories data
try {
const responses = await Promise.all(
repos.map((repo) =>
fetch(`https://api.github.com/repos/${repo}`, {
async function updateCommitsData() {
try {
const responses = await Promise.all(
repos.flatMap((repo) =>
kunaicoMembers.map((author) =>
fetch(`https://api.github.com/repos/${repo}/commits?author=${author}`, {
headers: {
Accept: "application/json",
"User-Agent": "Cloudflare Worker",
Authorization: `Bearer ${process.env.GH_API_KEY}`,
},
})
),
);
const repositories = await Promise.all(responses.map((res) => res.json()));

// Write the repositories data to a JSON file
const filePath = path.join(__dirname, '../data/repositories.json');
await fs.writeFile(filePath, JSON.stringify(repositories, null, 2));

} catch (error) {
console.error("Error fetching repos:", error);
//empty repositories.json file
const filePath = path.join(__dirname, '../data/repositories.json');
await fs.writeFile(filePath, '');
process.exit(1);
}
}
)
),
);

updateReposData();

async function updateMembersData() {
try {
const responses = await Promise.all(
contributors.map((user) =>
fetch(`https://api.github.com/users/${user}`, {
headers: {
Accept: "application/json",
"User-Agent": "Cloudflare Worker",
Authorization: `Bearer ${process.env.GH_API_KEY}`,
},
})
),
);
const members = await Promise.all(responses.map((res) => res.json()));

// Write the members data to a JSON file
const filePath = path.join(__dirname, '../data/members.json');
await fs.writeFile(filePath, JSON.stringify(members, null, 2));

} catch (error) {
console.error("Error fetching members:", error);
//empty members.json file
const filePath = path.join(__dirname, '../data/members.json');
await fs.writeFile(filePath, '');
process.exit(1);
// Check if any response failed
for (const response of responses) {
if (!response.ok) {
throw new Error(`GitHub API request failed: ${response.statusText}`);
}
}
}

updateMembersData()

async function updateCommitsData() {
try {
const responses = await Promise.all(
repos.flatMap((repo) =>
kunaicoMembers.map((author) =>
fetch(`https://api.github.com/repos/${repo}/commits?author=${author}`, {
headers: {
Accept: "application/json",
"User-Agent": "Cloudflare Worker",
Authorization: `Bearer ${process.env.GH_API_KEY}`,
},
})
)),
);
const commits = await Promise.all(responses.map((res) => res.json()));
const flattenedCommits = commits.flat(); // Flatten the array of commits
// Write the commits data to a JSON file
const filePath = path.join(__dirname, '../data/commits.json');
await fs.writeFile(filePath, JSON.stringify(flattenedCommits, null, 2));


} catch (error) {
console.error("Error fetching commits:", error);
//empty commits.json file
const filePath = path.join(__dirname, '../data/commits.json');
await fs.writeFile(filePath, '');
process.exit(1);
}
const commits = await Promise.all(responses.map((res) => res.json()));
const flattenedCommits = commits.flat();
const filePath = path.join(__dirname, '../data/commits.json');
await fs.writeFile(filePath, JSON.stringify(flattenedCommits, null, 2));
} catch (error) {
console.error("Error fetching commits:", error);
const filePath = path.join(__dirname, '../data/commits.json');
await fs.writeFile(filePath, '[]');
process.exit(1);
}
}

updateCommitsData()
// Run functions sequentially to avoid overwhelming the GitHub API
await updateReposData();
await updateMembersData();
await updateCommitsData();

0 comments on commit c975376

Please # to comment.