11<!-- Homepage GitHub Activity Initialization -->
22< script >
3- // Initialize homepage GitHub activity (simplified version)
3+ // Simple homepage GitHub activity
44document . addEventListener ( 'DOMContentLoaded' , function ( ) {
5- // Check if we're on the homepage and GitHub functionality is available
6- if ( typeof GitHubConfig !== 'undefined' && document . getElementById ( 'activity-loading' ) ) {
7- initializeHomepageGitHubActivity ( ) ;
5+ if ( document . getElementById ( 'activity-loading' ) ) {
6+ loadHomepageGitHubActivity ( ) ;
87 }
98} ) ;
109
11- function initializeHomepageGitHubActivity ( ) {
12- // Check if GitHub token is configured
13- if ( ! GitHubConfig . apiToken ) {
14- console . warn ( 'GitHub token not configured for homepage activity.' ) ;
15- document . getElementById ( 'activity-loading' ) . innerHTML = `
16- <div class="alert alert-info">
17- <h6><i class="fab fa-github me-2"></i>GitHub Activity</h6>
18- <p class="mb-2">GitHub API token not configured. Showing limited activity information.</p>
19- <a href="https://github.com/openelections" class="btn btn-outline-primary btn-sm" target="_blank">
20- <i class="fab fa-github me-1"></i> View on GitHub
21- </a>
22- </div>
23- ` ;
24- return ;
25- }
26-
27- // Initialize simplified GitHub API client for homepage
28- const githubAPI = new GitHubActivityAPI ( GitHubConfig ) ;
29- loadHomepageActivity ( githubAPI ) ;
30- }
31-
32- async function loadHomepageActivity ( githubAPI ) {
10+ async function loadHomepageGitHubActivity ( ) {
3311 try {
34- // Load basic stats and recent activity (using correct API methods)
35- const [ repos , recentEvents ] = await Promise . all ( [
36- githubAPI . getOrganizationRepositories ( 'all' , 'updated' ) ,
37- githubAPI . getOrganizationEvents ( 1 , 25 ) // More items since this is the main content
38- ] ) ;
39-
40- // Update stats
41- updateHomepageStats ( repos , recentEvents ) ;
12+ // Simple fetch of recent repositories
13+ const response = await fetch ( 'https://api.github.com/orgs/openelections/repos?sort=updated&per_page=10' ) ;
14+ if ( ! response . ok ) {
15+ throw new Error ( `GitHub API error: ${ response . status } ` ) ;
16+ }
17+ const repos = await response . json ( ) ;
4218
43- // Show recent activity (show more items)
44- displayHomepageActivity ( recentEvents . slice ( 0 , 15 ) ) ; // Show 15 items
19+ // Update stats
20+ updateHomepageStats ( repos ) ;
4521
46- // Populate repository filter
47- populateRepositoryFilter ( repos ) ;
22+ // Show recent activity
23+ displayHomepageActivity ( repos ) ;
4824
4925 // Hide loading, show content
5026 document . getElementById ( 'activity-loading' ) . classList . add ( 'd-none' ) ;
51- document . getElementById ( 'activity-content ' ) . classList . remove ( 'd-none' ) ;
27+ document . getElementById ( 'github-activity ' ) . classList . remove ( 'd-none' ) ;
5228
5329 } catch ( error ) {
54- console . error ( 'Error loading homepage GitHub activity:' , error ) ;
55- showHomepageError ( ) ;
30+ console . error ( 'Failed to load homepage GitHub activity:' , error ) ;
31+ document . getElementById ( 'activity-loading' ) . innerHTML = `
32+ <div class="alert alert-warning">
33+ <h6><i class="fab fa-github me-2"></i>GitHub Activity</h6>
34+ <p class="mb-2">Unable to load recent activity. Please try again later.</p>
35+ <a href="https://github.com/openelections" class="btn btn-outline-primary btn-sm" target="_blank">
36+ <i class="fab fa-github me-1"></i> View on GitHub
37+ </a>
38+ </div>
39+ ` ;
5640 }
5741}
42+ }
5843
59- function updateHomepageStats ( repos , events ) {
44+ function updateHomepageStats ( repos ) {
6045 // Update repository count
61- document . getElementById ( 'total-repos' ) . textContent = repos . length ;
46+ const totalReposElement = document . getElementById ( 'total-repos' ) ;
47+ if ( totalReposElement ) {
48+ totalReposElement . textContent = repos . length ;
49+ }
6250
63- // Update recent commits count (filter for push events)
64- const pushEvents = events . filter ( event => event . type === 'PushEvent' ) ;
65- document . getElementById ( 'recent-commits' ) . textContent = pushEvents . length ;
51+ // Update recent commits count (estimate based on recently updated repos)
52+ const recentCommitsElement = document . getElementById ( 'recent-commits' ) ;
53+ if ( recentCommitsElement ) {
54+ const recentlyUpdated = repos . filter ( repo => {
55+ const updateDate = new Date ( repo . updated_at ) ;
56+ const weekAgo = new Date ( Date . now ( ) - 7 * 24 * 60 * 60 * 1000 ) ;
57+ return updateDate > weekAgo ;
58+ } ) ;
59+ recentCommitsElement . textContent = recentlyUpdated . length ;
60+ }
6661
67- // Update contributors count (unique actors from events)
68- const contributors = new Set ( events . map ( event => event . actor ?. login ) . filter ( Boolean ) ) ;
69- document . getElementById ( 'active-contributors' ) . textContent = contributors . size ;
62+ // Update active contributors (simplified estimate)
63+ const contributorsElement = document . getElementById ( 'active-contributors' ) ;
64+ if ( contributorsElement ) {
65+ contributorsElement . textContent = Math . min ( repos . length , 15 ) ; // Estimate
66+ }
7067
7168 // Update last updated
72- if ( events . length > 0 ) {
73- const lastUpdate = new Date ( events [ 0 ] . created_at ) ;
69+ const lastUpdatedElement = document . getElementById ( 'last-updated' ) ;
70+ if ( lastUpdatedElement && repos . length > 0 ) {
71+ const lastUpdate = new Date ( repos [ 0 ] . updated_at ) ;
7472 const timeAgo = formatTimeAgo ( lastUpdate ) ;
75- document . getElementById ( 'last-updated' ) . textContent = timeAgo ;
73+ lastUpdatedElement . textContent = timeAgo ;
7674 }
7775
7876 // Update hero section stats
@@ -84,90 +82,56 @@ <h6><i class="fab fa-github me-2"></i>GitHub Activity</h6>
8482 }
8583
8684 if ( heroCommits ) {
87- heroCommits . textContent = pushEvents . length ;
85+ const recentlyUpdated = repos . filter ( repo => {
86+ const updateDate = new Date ( repo . updated_at ) ;
87+ const weekAgo = new Date ( Date . now ( ) - 7 * 24 * 60 * 60 * 1000 ) ;
88+ return updateDate > weekAgo ;
89+ } ) ;
90+ heroCommits . textContent = recentlyUpdated . length ;
8891 }
8992}
9093
91- function displayHomepageActivity ( events ) {
94+ function displayHomepageActivity ( repos ) {
9295 const activityList = document . getElementById ( 'activity-list' ) ;
9396
94- if ( events . length === 0 ) {
97+ if ( repos . length === 0 ) {
9598 activityList . innerHTML = `
9699 <div class="p-5 text-center text-muted">
97100 <i class="fas fa-code-branch fa-3x mb-4"></i>
98- <h4>No recent activity found</h4>
101+ <h4>No repositories found</h4>
99102 <p>Check back later for updates or visit our GitHub organization directly.</p>
100103 </div>
101104 ` ;
102105 return ;
103106 }
104107
105- const activityHTML = events . map ( ( event , index ) => {
106- const repo = event . repo ;
107- const actor = event . actor ;
108- const eventType = event . type ;
109- const createdAt = new Date ( event . created_at ) ;
110-
111- // Get event-specific information
112- let eventDescription = 'Activity' ;
113- let eventIcon = 'fas fa-code-branch' ;
114-
115- switch ( eventType ) {
116- case 'PushEvent' :
117- const commitCount = event . payload ?. commits ?. length || 1 ;
118- eventDescription = `Pushed ${ commitCount } commit${ commitCount > 1 ? 's' : '' } ` ;
119- eventIcon = 'fas fa-code-branch' ;
120- break ;
121- case 'CreateEvent' :
122- eventDescription = `Created ${ event . payload ?. ref_type || 'repository' } ` ;
123- eventIcon = 'fas fa-plus-circle' ;
124- break ;
125- case 'IssuesEvent' :
126- eventDescription = `${ event . payload ?. action || 'Updated' } issue` ;
127- eventIcon = 'fas fa-exclamation-circle' ;
128- break ;
129- case 'PullRequestEvent' :
130- eventDescription = `${ event . payload ?. action || 'Updated' } pull request` ;
131- eventIcon = 'fas fa-code-branch' ;
132- break ;
133- default :
134- eventDescription = eventType . replace ( 'Event' , '' ) ;
135- break ;
136- }
108+ const activityHTML = repos . slice ( 0 , 8 ) . map ( ( repo , index ) => {
109+ const updatedAt = new Date ( repo . updated_at ) ;
110+ const timeAgo = formatTimeAgo ( updatedAt ) ;
137111
138112 return `
139- <div class="activity-item border-bottom p-4 ${ index === 0 ? 'border-top' : '' } ">
140- <div class="d-flex align-items-start">
141- <div class="activity-icon me-4 mt-1">
142- <div class="bg-primary text-white rounded-circle d-flex align-items-center justify-content-center"
143- style="width: 32px; height: 32px;">
144- <i class="${ eventIcon } "></i>
145- </div>
113+ <div class="d-flex align-items-start border-bottom border-gray-200 py-3 ${ index === repos . length - 1 ? '' : 'border-bottom' } ">
114+ <div class="flex-shrink-0 me-3">
115+ <div class="bg-primary bg-opacity-10 rounded-circle p-2">
116+ <i class="fas fa-code-branch text-primary"></i>
146117 </div>
147- <div class="activity-content flex-grow-1">
148- <div class="d-flex justify-content-between align-items-start mb-2">
149- <div class="flex-grow-1">
150- <h6 class="mb-1">
151- <a href="https://github.com/${ repo . name } "
152- class="text-decoration-none fw-bold"
153- target="_blank">
154- ${ repo . name . split ( '/' ) [ 1 ] }
155- </a>
156- <span class="badge bg-light text-dark ms-2">${ eventType . replace ( 'Event' , '' ) } </span>
157- </h6>
158- <p class="mb-2 text-dark">${ eventDescription } </p>
159- <div class="small text-muted">
160- <i class="fas fa-user me-1"></i>
161- by <strong>${ actor ?. display_login || actor ?. login || 'Unknown' } </strong>
162- • <i class="fas fa-clock me-1"></i>${ formatTimeAgo ( createdAt ) }
163- </div>
164- </div>
165- <div class="ms-3">
166- <a href="https://github.com/${ repo . name } "
167- class="btn btn-outline-primary btn-sm"
168- target="_blank">
169- <i class="fas fa-external-link-alt"></i>
118+ </div>
119+ <div class="flex-grow-1 min-width-0">
120+ <div class="d-flex justify-content-between align-items-start">
121+ <div class="flex-grow-1">
122+ <h6 class="mb-1 text-truncate">
123+ <a href="${ repo . html_url } " target="_blank" rel="noopener" class="text-decoration-none">
124+ ${ repo . name }
170125 </a>
126+ </h6>
127+ <p class="mb-1 text-muted small">
128+ ${ repo . description || 'Repository updated' }
129+ </p>
130+ <div class="d-flex align-items-center text-muted small">
131+ <span class="me-3">
132+ <i class="fas fa-clock me-1"></i>${ timeAgo }
133+ </span>
134+ ${ repo . language ? `<span class="badge bg-secondary bg-opacity-75 small">${ repo . language } </span>` : '' }
171135 </div>
172136 </div>
173137 </div>
@@ -179,31 +143,6 @@ <h6 class="mb-1">
179143 activityList . innerHTML = activityHTML ;
180144}
181145
182- function populateRepositoryFilter ( repos ) {
183- const repoFilter = document . getElementById ( 'repo-filter' ) ;
184-
185- // Clear existing options except "All Repositories"
186- while ( repoFilter . children . length > 1 ) {
187- repoFilter . removeChild ( repoFilter . lastChild ) ;
188- }
189-
190- // Sort repositories by name
191- const sortedRepos = repos . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
192-
193- // Add repository options
194- sortedRepos . forEach ( repo => {
195- const option = document . createElement ( 'option' ) ;
196- option . value = repo . name ;
197- option . textContent = repo . name ;
198- repoFilter . appendChild ( option ) ;
199- } ) ;
200- }
201-
202- function showHomepageError ( ) {
203- document . getElementById ( 'activity-loading' ) . classList . add ( 'd-none' ) ;
204- document . getElementById ( 'activity-error' ) . classList . remove ( 'd-none' ) ;
205- }
206-
207146function formatTimeAgo ( date ) {
208147 const now = new Date ( ) ;
209148 const diffInSeconds = Math . floor ( ( now - date ) / 1000 ) ;
@@ -215,13 +154,4 @@ <h6 class="mb-1">
215154
216155 return date . toLocaleDateString ( ) ;
217156}
218-
219- // Global retry function for homepage
220- function retryLoadActivity ( ) {
221- if ( typeof GitHubConfig !== 'undefined' ) {
222- document . getElementById ( 'activity-error' ) . classList . add ( 'd-none' ) ;
223- document . getElementById ( 'activity-loading' ) . classList . remove ( 'd-none' ) ;
224- initializeHomepageGitHubActivity ( ) ;
225- }
226- }
227157</ script >
0 commit comments