1010async function loadHomepageGitHubActivity ( ) {
1111 try {
1212 // Simple fetch of recent repositories
13- const response = await fetch ( 'https://api.github.com/orgs/openelections/repos?sort=updated&per_page=10 ' ) ;
13+ const response = await fetch ( 'https://api.github.com/orgs/openelections/repos?sort=updated&per_page=100 ' ) ;
1414 if ( ! response . ok ) {
1515 throw new Error ( `GitHub API error: ${ response . status } ` ) ;
1616 }
1717 const repos = await response . json ( ) ;
1818
19+ // Fetch recent commits from the most active repositories
20+ const recentCommits = await fetchRecentCommits ( repos . slice ( 0 , 10 ) ) ;
21+
1922 // Update stats
20- updateHomepageStats ( repos ) ;
23+ updateHomepageStats ( repos , recentCommits ) ;
2124
2225 // Show recent activity
23- displayHomepageActivity ( repos ) ;
26+ displayHomepageActivity ( recentCommits ) ;
2427
2528 // Hide loading, show content
2629 document . getElementById ( 'activity-loading' ) . classList . add ( 'd-none' ) ;
27- document . getElementById ( 'github- activity' ) . classList . remove ( 'd-none' ) ;
30+ document . getElementById ( 'activity-content ' ) . classList . remove ( 'd-none' ) ;
2831
2932 } catch ( error ) {
3033 console . error ( 'Failed to load homepage GitHub activity:' , error ) ;
@@ -40,34 +43,59 @@ <h6><i class="fab fa-github me-2"></i>GitHub Activity</h6>
4043 }
4144}
4245
43- function updateHomepageStats ( repos ) {
46+ // Function to fetch recent commits from multiple repositories
47+ async function fetchRecentCommits ( repos ) {
48+ const commits = [ ] ;
49+
50+ // Fetch commits from the most recently updated repositories
51+ for ( const repo of repos . slice ( 0 , 8 ) ) {
52+ try {
53+ const commitsResponse = await fetch ( `https://api.github.com/repos/openelections/${ repo . name } /commits?per_page=3` ) ;
54+ if ( commitsResponse . ok ) {
55+ const repoCommits = await commitsResponse . json ( ) ;
56+ repoCommits . forEach ( commit => {
57+ commits . push ( {
58+ ...commit ,
59+ repository : repo
60+ } ) ;
61+ } ) ;
62+ }
63+ } catch ( error ) {
64+ console . warn ( `Failed to fetch commits for ${ repo . name } :` , error ) ;
65+ }
66+ }
67+
68+ // Sort all commits by date and return the most recent
69+ return commits
70+ . sort ( ( a , b ) => new Date ( b . commit . author . date ) - new Date ( a . commit . author . date ) )
71+ . slice ( 0 , 15 ) ;
72+ }
73+
74+ function updateHomepageStats ( repos , commits ) {
4475 // Update repository count
4576 const totalReposElement = document . getElementById ( 'total-repos' ) ;
4677 if ( totalReposElement ) {
4778 totalReposElement . textContent = repos . length ;
4879 }
4980
50- // Update recent commits count (estimate based on recently updated repos)
81+ // Update recent commits count
5182 const recentCommitsElement = document . getElementById ( 'recent-commits' ) ;
5283 if ( recentCommitsElement ) {
53- const recentlyUpdated = repos . filter ( repo => {
54- const updateDate = new Date ( repo . updated_at ) ;
55- const weekAgo = new Date ( Date . now ( ) - 7 * 24 * 60 * 60 * 1000 ) ;
56- return updateDate > weekAgo ;
57- } ) ;
58- recentCommitsElement . textContent = recentlyUpdated . length ;
84+ recentCommitsElement . textContent = commits . length ;
5985 }
6086
61- // Update active contributors (simplified estimate )
87+ // Update active contributors (unique commit authors )
6288 const contributorsElement = document . getElementById ( 'active-contributors' ) ;
6389 if ( contributorsElement ) {
64- contributorsElement . textContent = Math . min ( repos . length , 15 ) ; // Estimate
90+ const uniqueAuthors = new Set ( commits . map ( c => c . commit . author . name ) ) ;
91+ contributorsElement . textContent = uniqueAuthors . size ;
6592 }
6693
6794 // Update last updated
6895 const lastUpdatedElement = document . getElementById ( 'last-updated' ) ;
69- if ( lastUpdatedElement && repos . length > 0 ) {
70- const lastUpdate = new Date ( repos [ 0 ] . updated_at ) ;
96+ if ( lastUpdatedElement && commits . length > 0 ) {
97+ const lastCommit = commits [ 0 ] ;
98+ const lastUpdate = new Date ( lastCommit . commit . author . date ) ;
7199 const timeAgo = formatTimeAgo ( lastUpdate ) ;
72100 lastUpdatedElement . textContent = timeAgo ;
73101 }
@@ -81,35 +109,32 @@ <h6><i class="fab fa-github me-2"></i>GitHub Activity</h6>
81109 }
82110
83111 if ( heroCommits ) {
84- const recentlyUpdated = repos . filter ( repo => {
85- const updateDate = new Date ( repo . updated_at ) ;
86- const weekAgo = new Date ( Date . now ( ) - 7 * 24 * 60 * 60 * 1000 ) ;
87- return updateDate > weekAgo ;
88- } ) ;
89- heroCommits . textContent = recentlyUpdated . length ;
112+ heroCommits . textContent = commits . length ;
90113 }
91114}
92115
93- function displayHomepageActivity ( repos ) {
116+ function displayHomepageActivity ( commits ) {
94117 const activityList = document . getElementById ( 'activity-list' ) ;
95118
96- if ( repos . length === 0 ) {
119+ if ( commits . length === 0 ) {
97120 activityList . innerHTML = `
98121 <div class="p-5 text-center text-muted">
99122 <i class="fas fa-code-branch fa-3x mb-4"></i>
100- <h4>No repositories found</h4>
123+ <h4>No recent commits found</h4>
101124 <p>Check back later for updates or visit our GitHub organization directly.</p>
102125 </div>
103126 ` ;
104127 return ;
105128 }
106129
107- const activityHTML = repos . slice ( 0 , 8 ) . map ( ( repo , index ) => {
108- const updatedAt = new Date ( repo . updated_at ) ;
109- const timeAgo = formatTimeAgo ( updatedAt ) ;
130+ const activityHTML = commits . slice ( 0 , 8 ) . map ( ( commit , index ) => {
131+ const commitDate = new Date ( commit . commit . author . date ) ;
132+ const timeAgo = formatTimeAgo ( commitDate ) ;
133+ const commitMessage = commit . commit . message . split ( '\n' ) [ 0 ] ; // First line only
134+ const shortSha = commit . sha . substring ( 0 , 7 ) ;
110135
111136 return `
112- <div class="d-flex align-items-start border-bottom border-gray-200 py-3 ${ index === repos . length - 1 ? '' : 'border-bottom' } ">
137+ <div class="d-flex align-items-start border-bottom border-gray-200 py-3 ${ index === commits . length - 1 ? '' : 'border-bottom' } ">
113138 <div class="flex-shrink-0 me-3">
114139 <div class="bg-primary bg-opacity-10 rounded-circle p-2">
115140 <i class="fas fa-code-branch text-primary"></i>
@@ -119,20 +144,30 @@ <h4>No repositories found</h4>
119144 <div class="d-flex justify-content-between align-items-start">
120145 <div class="flex-grow-1">
121146 <h6 class="mb-1 text-truncate">
122- <a href="${ repo . html_url } " target="_blank" rel="noopener" class="text-decoration-none">
123- ${ repo . name }
147+ <a href="${ commit . repository . html_url } " target="_blank" rel="noopener" class="text-decoration-none">
148+ ${ commit . repository . name }
124149 </a>
125150 </h6>
126- <p class="mb-1 text-muted small">
127- ${ repo . description || 'Repository updated' }
151+ <p class="mb-1 text-dark small">
152+ ${ commitMessage }
128153 </p>
129154 <div class="d-flex align-items-center text-muted small">
155+ <span class="me-3">
156+ <i class="fas fa-user me-1"></i>${ commit . commit . author . name }
157+ </span>
130158 <span class="me-3">
131159 <i class="fas fa-clock me-1"></i>${ timeAgo }
132160 </span>
133- ${ repo . language ? `<span class="badge bg-secondary bg-opacity-75 small">${ repo . language } </span>` : '' }
161+ <span class="badge bg-secondary bg-opacity-75 small">
162+ <i class="fas fa-code me-1"></i>${ shortSha }
163+ </span>
134164 </div>
135165 </div>
166+ <div class="ms-3">
167+ <a href="${ commit . html_url } " class="btn btn-outline-primary btn-sm" target="_blank" rel="noopener">
168+ <i class="fas fa-external-link-alt"></i>
169+ </a>
170+ </div>
136171 </div>
137172 </div>
138173 </div>
0 commit comments