11'use server'
22
3+ import { env } from '@/lib/env'
4+
35/**
46 * Format a number to a human-readable format (e.g., 1000 -> 1k, 1100 -> 1.1k)
57 */
@@ -8,10 +10,8 @@ function formatNumber(num: number): string {
810 return num . toString ( )
911 }
1012
11- // Convert to one decimal place and remove trailing 0
1213 const formatted = ( Math . round ( num / 100 ) / 10 ) . toFixed ( 1 )
1314
14- // Remove .0 if the decimal is 0
1515 return formatted . endsWith ( '.0' ) ? `${ formatted . slice ( 0 , - 2 ) } k` : `${ formatted } k`
1616}
1717
@@ -20,7 +20,7 @@ function formatNumber(num: number): string {
2020 */
2121export async function getFormattedGitHubStars ( ) : Promise < string > {
2222 try {
23- const token = process . env . GITHUB_TOKEN
23+ const token = env . GITHUB_TOKEN
2424
2525 const response = await fetch ( 'https://api.github.com/repos/simstudioai/sim' , {
2626 headers : {
@@ -29,18 +29,176 @@ export async function getFormattedGitHubStars(): Promise<string> {
2929 'User-Agent' : 'SimStudio/1.0' ,
3030 ...( token ? { Authorization : `Bearer ${ token } ` } : { } ) ,
3131 } ,
32- next : { revalidate : 3600 } , // Revalidate every hour
32+ next : { revalidate : 3600 } ,
3333 } )
3434
3535 if ( ! response . ok ) {
3636 console . error ( `GitHub API error: ${ response . status } ${ response . statusText } ` )
37- return formatNumber ( 1200 )
37+ return formatNumber ( 3867 )
3838 }
3939
4040 const data = await response . json ( )
41- return formatNumber ( data . stargazers_count || 1200 )
41+ return formatNumber ( data . stargazers_count || 3867 )
4242 } catch ( error ) {
4343 console . error ( 'Error fetching GitHub stars:' , error )
44- return formatNumber ( 1200 )
44+ return formatNumber ( 3867 )
45+ }
46+ }
47+
48+ interface Contributor {
49+ login : string
50+ avatar_url : string
51+ contributions : number
52+ html_url : string
53+ }
54+
55+ interface CommitData {
56+ sha : string
57+ commit : {
58+ author : {
59+ name : string
60+ email : string
61+ date : string
62+ }
63+ message : string
64+ }
65+ html_url : string
66+ }
67+
68+ interface RepoStats {
69+ stars : number
70+ forks : number
71+ watchers : number
72+ openIssues : number
73+ openPRs : number
74+ }
75+
76+ /**
77+ * Server action to fetch repository statistics
78+ */
79+ export async function getRepositoryStats ( ) : Promise < RepoStats > {
80+ try {
81+ const token = env . GITHUB_TOKEN
82+
83+ const headers = {
84+ Accept : 'application/vnd.github+json' ,
85+ 'X-GitHub-Api-Version' : '2022-11-28' ,
86+ 'User-Agent' : 'SimStudio/1.0' ,
87+ ...( token ? { Authorization : `Bearer ${ token } ` } : { } ) ,
88+ }
89+
90+ const repoResponse = await fetch ( 'https://api.github.com/repos/simstudioai/sim' , {
91+ headers,
92+ next : { revalidate : 3600 } ,
93+ } )
94+
95+ const prsResponse = await fetch (
96+ 'https://api.github.com/repos/simstudioai/sim/pulls?state=open' ,
97+ {
98+ headers,
99+ next : { revalidate : 3600 } ,
100+ }
101+ )
102+
103+ if ( ! repoResponse . ok || ! prsResponse . ok ) {
104+ console . error ( 'GitHub API error fetching repo stats' )
105+ return {
106+ stars : 3867 ,
107+ forks : 581 ,
108+ watchers : 26 ,
109+ openIssues : 23 ,
110+ openPRs : 3 ,
111+ }
112+ }
113+
114+ const repoData = await repoResponse . json ( )
115+ const prsData = await prsResponse . json ( )
116+
117+ return {
118+ stars : repoData . stargazers_count || 3867 ,
119+ forks : repoData . forks_count || 581 ,
120+ watchers : repoData . subscribers_count || 26 ,
121+ openIssues : ( repoData . open_issues_count || 26 ) - prsData . length ,
122+ openPRs : prsData . length || 3 ,
123+ }
124+ } catch ( error ) {
125+ console . error ( 'Error fetching repository stats:' , error )
126+ return {
127+ stars : 3867 ,
128+ forks : 581 ,
129+ watchers : 26 ,
130+ openIssues : 23 ,
131+ openPRs : 3 ,
132+ }
133+ }
134+ }
135+
136+ /**
137+ * Server action to fetch contributors
138+ */
139+ export async function getContributors ( ) : Promise < Contributor [ ] > {
140+ try {
141+ const token = env . GITHUB_TOKEN
142+
143+ const headers = {
144+ Accept : 'application/vnd.github+json' ,
145+ 'X-GitHub-Api-Version' : '2022-11-28' ,
146+ 'User-Agent' : 'SimStudio/1.0' ,
147+ ...( token ? { Authorization : `Bearer ${ token } ` } : { } ) ,
148+ }
149+
150+ const response = await fetch (
151+ 'https://api.github.com/repos/simstudioai/sim/contributors?per_page=100' ,
152+ {
153+ headers,
154+ next : { revalidate : 3600 } ,
155+ }
156+ )
157+
158+ if ( ! response . ok ) {
159+ console . error ( 'GitHub API error fetching contributors' )
160+ return [ ]
161+ }
162+
163+ const contributors = await response . json ( )
164+ return contributors || [ ]
165+ } catch ( error ) {
166+ console . error ( 'Error fetching contributors:' , error )
167+ return [ ]
168+ }
169+ }
170+
171+ /**
172+ * Server action to fetch recent commits for timeline data
173+ */
174+ export async function getCommitsData ( ) : Promise < CommitData [ ] > {
175+ try {
176+ const token = env . GITHUB_TOKEN
177+
178+ const headers = {
179+ Accept : 'application/vnd.github+json' ,
180+ 'X-GitHub-Api-Version' : '2022-11-28' ,
181+ 'User-Agent' : 'SimStudio/1.0' ,
182+ ...( token ? { Authorization : `Bearer ${ token } ` } : { } ) ,
183+ }
184+
185+ const response = await fetch (
186+ 'https://api.github.com/repos/simstudioai/sim/commits?per_page=100' ,
187+ {
188+ headers,
189+ next : { revalidate : 3600 } ,
190+ }
191+ )
192+
193+ if ( ! response . ok ) {
194+ console . error ( 'GitHub API error fetching commits' )
195+ return [ ]
196+ }
197+
198+ const commits = await response . json ( )
199+ return commits || [ ]
200+ } catch ( error ) {
201+ console . error ( 'Error fetching commits:' , error )
202+ return [ ]
45203 }
46204}
0 commit comments