Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions netlify/functions/batchUpdateMeetingSummariesArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,59 @@ export const handler = async (event, context) => {
const { data: summaries, error } = await supabase
.from('meetingsummaries')
.select('meeting_id, created_at, summary')
.eq('confirmed', true)
.order('created_at', { ascending: true });

if (error) {
console.error('Error retrieving meeting summaries:', error);
return {
statusCode: 500,
body: JSON.stringify({ error: 'Failed to retrieve meeting summaries' }),
};
return { statusCode: 500, body: JSON.stringify({ error: 'Failed to retrieve meeting summaries' }), };
}

// Extract summaries from the retrieved data
const allSummaries = summaries.map(summary => summary.summary);

// Commit all summaries to GitHub in a single file
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
// Group summaries by year
const summariesByYear = {};
summaries.forEach(summary => {
const year = new Date(summary.summary.meetingInfo.date).getFullYear();
if (!summariesByYear[year]) {
summariesByYear[year] = [];
}
summariesByYear[year].push(summary.summary);
});

// Get the current SHA of the file
let currentSHA = null;
try {
const { data: currentFile } = await octokit.repos.getContent({
// Commit summaries to GitHub in separate year folders
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN, });

for (const year in summariesByYear) {
const yearSummaries = summariesByYear[year];
const path = `Data/Meeting-Summaries/${year}/meeting-summaries-array.json`;

// Get the current SHA of the file
let currentSHA = null;
try {
const { data: currentFile } = await octokit.repos.getContent({
owner: "SingularityNET-Archive",
repo: "SingularityNET-Archive",
path,
});
currentSHA = currentFile.sha;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}

await octokit.repos.createOrUpdateFileContents({
owner: "SingularityNET-Archive",
repo: "SingularityNET-Archive",
path: "Data/Meeting-Summaries/meeting-summaries-array.json",
path,
message: `Update meeting summaries for ${year}`,
content: Buffer.from(JSON.stringify(yearSummaries, null, 2)).toString('base64'),
sha: currentSHA,
});
currentSHA = currentFile.sha;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}

const { data } = await octokit.repos.createOrUpdateFileContents({
owner: "SingularityNET-Archive",
repo: "SingularityNET-Archive",
path: "Data/Meeting-Summaries/meeting-summaries-array.json",
message: "Update meeting summaries",
content: Buffer.from(JSON.stringify(allSummaries, null, 2)).toString('base64'),
sha: currentSHA,
});

return {
statusCode: 200,
body: JSON.stringify({ message: 'Meeting summaries updated successfully' }),
};
return { statusCode: 200, body: JSON.stringify({ message: 'Meeting summaries updated successfully' }), };
} catch (error) {
console.error('Error in updateGitHubRepo function:', error);
return {
statusCode: 500,
body: JSON.stringify({ error: 'Failed to update meeting summaries' }),
};
return { statusCode: 500, body: JSON.stringify({ error: 'Failed to update meeting summaries' }), };
}
};
55 changes: 34 additions & 21 deletions netlify/functions/batchUpdateMeetingSummariesById.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function fetchMeetingSummaries(lastProcessedTimestamp) {
const { data: summaries, error } = await supabase
.from('meetingsummaries')
.select('created_at, meeting_id, summary')
.eq('confirmed', true)
.order('created_at', { ascending: true })
.limit(BATCH_SIZE * MAX_CONCURRENT_REQUESTS)
.gt('created_at', lastProcessedTimestamp || '1970-01-01');
Expand All @@ -23,38 +24,50 @@ async function fetchMeetingSummaries(lastProcessedTimestamp) {
function groupSummariesByMeetingId(summaries, allSummaries) {
summaries.forEach(summary => {
const { meeting_id, summary: summaryText } = summary;
if (!allSummaries[meeting_id]) {
allSummaries[meeting_id] = [];
const year = new Date(summaryText.meetingInfo.date).getFullYear();

if (!allSummaries[year]) {
allSummaries[year] = {};
}

if (!allSummaries[year][meeting_id]) {
allSummaries[year][meeting_id] = [];
}
allSummaries[meeting_id].push(summaryText);

allSummaries[year][meeting_id].push(summaryText);
});
}

async function commitSummariesToGitHub(allSummaries) {
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

let currentSHA = null;
try {
const { data: currentFile } = await octokit.repos.getContent({
for (const year in allSummaries) {
const yearSummaries = allSummaries[year];
const path = `Data/Meeting-Summaries/${year}/meeting-summaries-by-id.json`;

let currentSHA = null;
try {
const { data: currentFile } = await octokit.repos.getContent({
owner: "SingularityNET-Archive",
repo: "SingularityNET-Archive",
path,
});
currentSHA = currentFile.sha;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}

await octokit.repos.createOrUpdateFileContents({
owner: "SingularityNET-Archive",
repo: "SingularityNET-Archive",
path: "Data/Meeting-Summaries/meeting-summaries-by-id.json",
path,
message: `Update meeting summaries for ${year}`,
content: Buffer.from(JSON.stringify(yearSummaries, null, 2)).toString('base64'),
sha: currentSHA,
});
currentSHA = currentFile.sha;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}

await octokit.repos.createOrUpdateFileContents({
owner: "SingularityNET-Archive",
repo: "SingularityNET-Archive",
path: "Data/Meeting-Summaries/meeting-summaries-by-id.json",
message: "Update meeting summaries",
content: Buffer.from(JSON.stringify(allSummaries, null, 2)).toString('base64'),
sha: currentSHA,
});
}

async function processAndCommitSummaries() {
Expand Down