just 1 left
This commit is contained in:
@@ -159,6 +159,9 @@ export function RightBarContent() {
|
|||||||
contributions={githubActivity()}
|
contributions={githubActivity()}
|
||||||
title="GitHub Activity"
|
title="GitHub Activity"
|
||||||
/>
|
/>
|
||||||
|
<div>
|
||||||
|
<a href="https://git.freno.me">Self-hosted Git!</a>
|
||||||
|
</div>
|
||||||
<RecentCommits
|
<RecentCommits
|
||||||
commits={giteaCommits()}
|
commits={giteaCommits()}
|
||||||
title="Recent Gitea Commits"
|
title="Recent Gitea Commits"
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`GitHub API error: ${response.statusText}`);
|
throw new Error(`GitHub commits API error: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = await response.json();
|
const events = await response.json();
|
||||||
@@ -69,9 +69,9 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
.input(z.object({ limit: z.number().default(3) }))
|
.input(z.object({ limit: z.number().default(3) }))
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
try {
|
try {
|
||||||
// First, get user's repos
|
// First, get user's repositories
|
||||||
const reposResponse = await fetch(
|
const reposResponse = await fetch(
|
||||||
`${env.GITEA_URL}/api/v1/user/repos`,
|
`${env.GITEA_URL}/api/v1/users/Mike/repos?limit=100`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${env.GITEA_TOKEN}`,
|
Authorization: `token ${env.GITEA_TOKEN}`,
|
||||||
@@ -81,19 +81,19 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!reposResponse.ok) {
|
if (!reposResponse.ok) {
|
||||||
throw new Error(`Gitea API error: ${reposResponse.statusText}`);
|
throw new Error(`Gitea repos API error: ${reposResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const repos = await reposResponse.json();
|
const repos = await reposResponse.json();
|
||||||
const commits: GitCommit[] = [];
|
const allCommits: GitCommit[] = [];
|
||||||
|
|
||||||
// Get commits from each repo
|
// Fetch recent commits from each repo
|
||||||
for (const repo of repos) {
|
for (const repo of repos) {
|
||||||
if (commits.length >= input.limit) break;
|
if (allCommits.length >= input.limit * 3) break; // Get extra to sort later
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const commitsResponse = await fetch(
|
const commitsResponse = await fetch(
|
||||||
`${env.GITEA_URL}/api/v1/repos/${repo.owner.login}/${repo.name}/commits?limit=${input.limit}`,
|
`${env.GITEA_URL}/api/v1/repos/Mike/${repo.name}/commits?limit=5`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${env.GITEA_TOKEN}`,
|
Authorization: `token ${env.GITEA_TOKEN}`,
|
||||||
@@ -103,17 +103,26 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (commitsResponse.ok) {
|
if (commitsResponse.ok) {
|
||||||
const repoCommits = await commitsResponse.json();
|
const commits = await commitsResponse.json();
|
||||||
for (const commit of repoCommits) {
|
for (const commit of commits) {
|
||||||
if (commits.length >= input.limit) break;
|
if (
|
||||||
commits.push({
|
(commit.commit?.author?.email &&
|
||||||
sha: commit.sha.substring(0, 7),
|
commit.commit.author.email.includes("michael@freno.me")) ||
|
||||||
message: commit.commit.message.split("\n")[0],
|
commit.commit.author.email.includes(
|
||||||
author: commit.commit.author.name,
|
"michaelt.freno@gmail.com"
|
||||||
date: commit.commit.author.date,
|
) // Filter for your commits
|
||||||
repo: `${repo.owner.login}/${repo.name}`,
|
) {
|
||||||
url: `${env.GITEA_URL}/${repo.owner.login}/${repo.name}/commit/${commit.sha}`
|
allCommits.push({
|
||||||
});
|
sha: commit.sha?.substring(0, 7) || "unknown",
|
||||||
|
message:
|
||||||
|
commit.commit?.message?.split("\n")[0] || "No message",
|
||||||
|
author: commit.commit?.author?.name || repo.owner.login,
|
||||||
|
date:
|
||||||
|
commit.commit?.author?.date || new Date().toISOString(),
|
||||||
|
repo: repo.full_name,
|
||||||
|
url: `${env.GITEA_URL}/${repo.full_name}/commit/${commit.sha}`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -121,12 +130,12 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by date and return top N
|
// Sort by date and return the most recent
|
||||||
return commits
|
allCommits.sort(
|
||||||
.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()
|
);
|
||||||
)
|
|
||||||
.slice(0, input.limit);
|
return allCommits.slice(0, input.limit);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching Gitea commits:", error);
|
console.error("Error fetching Gitea commits:", error);
|
||||||
return [];
|
return [];
|
||||||
@@ -136,37 +145,61 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
// Get GitHub contribution activity (for heatmap)
|
// Get GitHub contribution activity (for heatmap)
|
||||||
getGitHubActivity: publicProcedure.query(async () => {
|
getGitHubActivity: publicProcedure.query(async () => {
|
||||||
try {
|
try {
|
||||||
const oneYearAgo = new Date();
|
// Use GitHub GraphQL API for contribution data
|
||||||
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
|
const query = `
|
||||||
|
query($userName: String!) {
|
||||||
const response = await fetch(
|
user(login: $userName) {
|
||||||
`https://api.github.com/users/MikeFreno/events?per_page=100`,
|
contributionsCollection {
|
||||||
{
|
contributionCalendar {
|
||||||
headers: {
|
weeks {
|
||||||
Authorization: `Bearer ${env.GITHUB_API_TOKEN}`,
|
contributionDays {
|
||||||
Accept: "application/vnd.github.v3+json"
|
date
|
||||||
|
contributionCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
`;
|
||||||
|
|
||||||
|
const response = await fetch("https://api.github.com/graphql", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${env.GITHUB_API_TOKEN}`,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
query,
|
||||||
|
variables: { userName: "MikeFreno" }
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`GitHub API error: ${response.statusText}`);
|
throw new Error(`GitHub GraphQL API error: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
// Count contributions by day
|
if (data.errors) {
|
||||||
const contributionsByDay = new Map<string, number>();
|
console.error("GitHub GraphQL errors:", data.errors);
|
||||||
|
throw new Error("GraphQL query failed");
|
||||||
for (const event of events) {
|
|
||||||
const date = new Date(event.created_at).toISOString().split("T")[0];
|
|
||||||
contributionsByDay.set(date, (contributionsByDay.get(date) || 0) + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to array format
|
// Extract contribution days from the response
|
||||||
const contributions: ContributionDay[] = Array.from(
|
const contributions: ContributionDay[] = [];
|
||||||
contributionsByDay.entries()
|
const weeks =
|
||||||
).map(([date, count]) => ({ date, count }));
|
data.data?.user?.contributionsCollection?.contributionCalendar?.weeks ||
|
||||||
|
[];
|
||||||
|
|
||||||
|
for (const week of weeks) {
|
||||||
|
for (const day of week.contributionDays) {
|
||||||
|
contributions.push({
|
||||||
|
date: day.date,
|
||||||
|
count: day.contributionCount
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return contributions;
|
return contributions;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -178,22 +211,28 @@ export const gitActivityRouter = createTRPCRouter({
|
|||||||
// Get Gitea contribution activity (for heatmap)
|
// Get Gitea contribution activity (for heatmap)
|
||||||
getGiteaActivity: publicProcedure.query(async () => {
|
getGiteaActivity: publicProcedure.query(async () => {
|
||||||
try {
|
try {
|
||||||
// Get all user repos
|
// Get user's repositories
|
||||||
const reposResponse = await fetch(`${env.GITEA_URL}/api/v1/user/repos`, {
|
const reposResponse = await fetch(
|
||||||
headers: {
|
`${env.GITEA_URL}/api/v1/user/repos?limit=100`,
|
||||||
Authorization: `token ${env.GITEA_TOKEN}`,
|
{
|
||||||
Accept: "application/json"
|
headers: {
|
||||||
|
Authorization: `token ${env.GITEA_TOKEN}`,
|
||||||
|
Accept: "application/json"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
if (!reposResponse.ok) {
|
if (!reposResponse.ok) {
|
||||||
throw new Error(`Gitea API error: ${reposResponse.statusText}`);
|
throw new Error(`Gitea repos API error: ${reposResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const repos = await reposResponse.json();
|
const repos = await reposResponse.json();
|
||||||
const contributionsByDay = new Map<string, number>();
|
const contributionsByDay = new Map<string, number>();
|
||||||
|
|
||||||
// Fetch commits from all repos
|
// Get commits from each repo (last 3 months to avoid too many API calls)
|
||||||
|
const threeMonthsAgo = new Date();
|
||||||
|
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
|
||||||
|
|
||||||
for (const repo of repos) {
|
for (const repo of repos) {
|
||||||
try {
|
try {
|
||||||
const commitsResponse = await fetch(
|
const commitsResponse = await fetch(
|
||||||
|
|||||||
Reference in New Issue
Block a user