fix: corrected github recent commits
This commit is contained in:
@@ -68,18 +68,28 @@ export function RightBarContent() {
|
|||||||
onMount(() => {
|
onMount(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
|
// Fetch more commits to account for deduplication
|
||||||
const [ghCommits, gtCommits, ghActivity, gtActivity] =
|
const [ghCommits, gtCommits, ghActivity, gtActivity] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
api.gitActivity.getGitHubCommits
|
api.gitActivity.getGitHubCommits
|
||||||
.query({ limit: 3 })
|
.query({ limit: 6 })
|
||||||
.catch(() => []),
|
.catch(() => []),
|
||||||
api.gitActivity.getGiteaCommits.query({ limit: 3 }).catch(() => []),
|
api.gitActivity.getGiteaCommits.query({ limit: 6 }).catch(() => []),
|
||||||
api.gitActivity.getGitHubActivity.query().catch(() => []),
|
api.gitActivity.getGitHubActivity.query().catch(() => []),
|
||||||
api.gitActivity.getGiteaActivity.query().catch(() => [])
|
api.gitActivity.getGiteaActivity.query().catch(() => [])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setGithubCommits(ghCommits);
|
// Take first 3 from GitHub
|
||||||
setGiteaCommits(gtCommits);
|
const displayedGithubCommits = ghCommits.slice(0, 3);
|
||||||
|
|
||||||
|
// Deduplicate Gitea commits - only against the 3 shown in GitHub section
|
||||||
|
const githubShas = new Set(displayedGithubCommits.map((c) => c.sha));
|
||||||
|
const uniqueGiteaCommits = gtCommits.filter(
|
||||||
|
(commit) => !githubShas.has(commit.sha)
|
||||||
|
);
|
||||||
|
|
||||||
|
setGithubCommits(displayedGithubCommits);
|
||||||
|
setGiteaCommits(uniqueGiteaCommits.slice(0, 3));
|
||||||
setGithubActivity(ghActivity);
|
setGithubActivity(ghActivity);
|
||||||
setGiteaActivity(gtActivity);
|
setGiteaActivity(gtActivity);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
`github-commits-${input.limit}`,
|
`github-commits-${input.limit}`,
|
||||||
CACHE_CONFIG.GIT_ACTIVITY_CACHE_TTL_MS,
|
CACHE_CONFIG.GIT_ACTIVITY_CACHE_TTL_MS,
|
||||||
async () => {
|
async () => {
|
||||||
const reposResponse = await fetchWithTimeout(
|
// Use Events API to get recent push events - much more efficient
|
||||||
`https://api.github.com/users/MikeFreno/repos?sort=pushed&per_page=10`,
|
const eventsResponse = await fetchWithTimeout(
|
||||||
|
`https://api.github.com/users/MikeFreno/events/public?per_page=100`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${env.GITHUB_API_TOKEN}`,
|
Authorization: `Bearer ${env.GITHUB_API_TOKEN}`,
|
||||||
@@ -44,30 +45,38 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await checkResponse(reposResponse);
|
await checkResponse(eventsResponse);
|
||||||
const repos = await reposResponse.json();
|
const events = await eventsResponse.json();
|
||||||
const allCommits: GitCommit[] = [];
|
const allCommits: GitCommit[] = [];
|
||||||
|
|
||||||
for (const repo of repos) {
|
// Extract push events and fetch commit details
|
||||||
if (allCommits.length >= input.limit * 3) break; // Get extra to sort later
|
for (const event of events) {
|
||||||
|
if (event.type !== "PushEvent") continue;
|
||||||
|
if (allCommits.length >= input.limit * 5) break; // Get extra to ensure we have enough
|
||||||
|
|
||||||
|
const repoName = event.repo.name;
|
||||||
|
const commitSha = event.payload.head;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const commitsResponse = await fetchWithTimeout(
|
// Fetch the actual commit details to get the message
|
||||||
`https://api.github.com/repos/${repo.full_name}/commits?per_page=5`,
|
const commitResponse = await fetchWithTimeout(
|
||||||
|
`https://api.github.com/repos/${repoName}/commits/${commitSha}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${env.GITHUB_API_TOKEN}`,
|
Authorization: `Bearer ${env.GITHUB_API_TOKEN}`,
|
||||||
Accept: "application/vnd.github.v3+json"
|
Accept: "application/vnd.github.v3+json"
|
||||||
},
|
},
|
||||||
timeout: 10000
|
timeout: 5000
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (commitsResponse.ok) {
|
if (commitResponse.ok) {
|
||||||
const commits = await commitsResponse.json();
|
const commit = await commitResponse.json();
|
||||||
for (const commit of commits) {
|
|
||||||
|
// Filter for your commits
|
||||||
if (
|
if (
|
||||||
commit.author?.login === "MikeFreno" ||
|
commit.author?.login === "MikeFreno" ||
|
||||||
|
commit.author?.login === "mikefreno" ||
|
||||||
commit.commit?.author?.email?.includes("mike")
|
commit.commit?.author?.email?.includes("mike")
|
||||||
) {
|
) {
|
||||||
allCommits.push({
|
allCommits.push({
|
||||||
@@ -80,29 +89,29 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
"Unknown",
|
"Unknown",
|
||||||
date:
|
date:
|
||||||
commit.commit?.author?.date || new Date().toISOString(),
|
commit.commit?.author?.date || new Date().toISOString(),
|
||||||
repo: repo.full_name,
|
repo: repoName,
|
||||||
url: `https://github.com/${repo.full_name}/commit/${commit.sha}`
|
url: `https://github.com/${repoName}/commit/${commit.sha}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (
|
if (
|
||||||
error instanceof NetworkError ||
|
error instanceof NetworkError ||
|
||||||
error instanceof TimeoutError
|
error instanceof TimeoutError
|
||||||
) {
|
) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Network error fetching commits for ${repo.full_name}, skipping`
|
`Network error fetching commit ${commitSha} for ${repoName}, skipping`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
`Error fetching commits for ${repo.full_name}:`,
|
`Error fetching commit ${commitSha} for ${repoName}:`,
|
||||||
error
|
error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Already sorted by event date, but sort again by commit date to be precise
|
||||||
allCommits.sort(
|
allCommits.sort(
|
||||||
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()
|
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user