Skip to content

Commit

Permalink
revert: ⏪ remove fetching commits from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
slugb0t committed Aug 28, 2024
1 parent 4fd4f61 commit 738c098
Showing 1 changed file with 85 additions and 85 deletions.
170 changes: 85 additions & 85 deletions ui/server/api/dashboard/[owner]/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,91 +84,91 @@ export default defineEventHandler(async (event) => {
})
.toArray();

// For the first 10 repositories, get the latest commit details
for (let index = 0; index < installations.length; index++) {
let latestCommitSha = "";
let latestCommitMessage = "";
let latestCommitUrl = "";
let latestCommitDate = "";
const installation = installations[index];

// Update the db to include ownerIsOrganization
await installationCollection.updateMany(
{
owner,
ownerIsOrganization: { $exists: false },
},
{
$set: {
ownerIsOrganization,
},
},
);

// if entry does not commit details fetch them
if (
installation.latestCommitSha &&
installation.latestCommitMessage &&
installation.latestCommitUrl &&
installation.latestCommitDate
) {
continue;
}

const repo = installation.repo as string;

try {
const commitResponse = await fetch(
`https://api.github.com/repos/${owner}/${repo}/commits`,
{
headers: {
Authorization: `Bearer ${user.access_token}`,
},
},
);

if (commitResponse.ok) {
const commits = await commitResponse.json();

if (Array.isArray(commits) && commits.length > 0) {
latestCommitSha = commits[0]?.sha || "";
latestCommitMessage = commits[0]?.commit?.message || "";
latestCommitUrl = commits[0]?.html_url || "";
latestCommitDate = commits[0]?.commit?.author?.date || "";
}
}
} catch (error) {
console.error(
`Failed to fetch commits for the repository ${repo} for the owner ${owner}`,
);

console.error(error);
}

installations[index] = {
...installation,
latestCommitDate,
latestCommitMessage,
latestCommitSha,
latestCommitUrl,
};

// Update the db with the latest commit details
await installationCollection.updateOne(
{
owner,
repo,
},
{
$set: {
latestCommitDate,
latestCommitMessage,
latestCommitSha,
latestCommitUrl,
},
},
);
}
// // For the first 10 repositories, get the latest commit details
// for (let index = 0; index < installations.length; index++) {
// let latestCommitSha = "";
// let latestCommitMessage = "";
// let latestCommitUrl = "";
// let latestCommitDate = "";
// const installation = installations[index];

// // Update the db to include ownerIsOrganization
// await installationCollection.updateMany(
// {
// owner,
// ownerIsOrganization: { $exists: false },
// },
// {
// $set: {
// ownerIsOrganization,
// },
// },
// );

// // if entry does not commit details fetch them
// if (
// installation.latestCommitSha &&
// installation.latestCommitMessage &&
// installation.latestCommitUrl &&
// installation.latestCommitDate
// ) {
// continue;
// }

// const repo = installation.repo as string;

// try {
// const commitResponse = await fetch(
// `https://api.github.com/repos/${owner}/${repo}/commits`,
// {
// headers: {
// Authorization: `Bearer ${user.access_token}`,
// },
// },
// );

// if (commitResponse.ok) {
// const commits = await commitResponse.json();

// if (Array.isArray(commits) && commits.length > 0) {
// latestCommitSha = commits[0]?.sha || "";
// latestCommitMessage = commits[0]?.commit?.message || "";
// latestCommitUrl = commits[0]?.html_url || "";
// latestCommitDate = commits[0]?.commit?.author?.date || "";
// }
// }
// } catch (error) {
// console.error(
// `Failed to fetch commits for the repository ${repo} for the owner ${owner}`,
// );

// console.error(error);
// }

// installations[index] = {
// ...installation,
// latestCommitDate,
// latestCommitMessage,
// latestCommitSha,
// latestCommitUrl,
// };

// // Update the db with the latest commit details
// await installationCollection.updateOne(
// {
// owner,
// repo,
// },
// {
// $set: {
// latestCommitDate,
// latestCommitMessage,
// latestCommitSha,
// latestCommitUrl,
// },
// },
// );
// }

return installations.map((installation) => ({
action_count: installation.action_count as number,
Expand Down

0 comments on commit 738c098

Please sign in to comment.