33 * Update the org profile README stats block using GitHub GraphQL.
44 *
55 * Env:
6- * ORG - required, your org login (e.g., "my-org")
7- * GH_TOKEN - recommended: a PAT with 'read:org' and 'repo' if you want private repo stats
8- * fallback: GITHUB_TOKEN from Actions (public repos typically OK)
9- *
10- * Notes:
11- * - By default excludes forks and archived repos. Tweak flags below if you want them.
6+ * ORG - required, your org login ("kir-rescomp")
7+ * GH_TOKEN - a token; PAT with read:org + repo if you want private repos included,
8+ * otherwise the default GITHUB_TOKEN works for public.
129 */
1310const fs = require ( "fs" ) ;
1411const path = require ( "path" ) ;
1512const https = require ( "https" ) ;
1613
17- const ORG = process . env . ORG ;
14+ const ORG = process . env . ORG || "kir-rescomp" ;
1815const GH_TOKEN = process . env . GH_TOKEN || process . env . GITHUB_TOKEN ;
19- if ( ! ORG ) {
20- console . error ( "Missing ORG environment variable." ) ;
21- process . exit ( 1 ) ;
22- }
2316if ( ! GH_TOKEN ) {
2417 console . error ( "Missing GH_TOKEN/GITHUB_TOKEN environment variable." ) ;
2518 process . exit ( 1 ) ;
2619}
2720
28- // Tweak filters here :
21+ // Tweak filters:
2922const INCLUDE_FORKS = false ;
3023const INCLUDE_ARCHIVED = false ;
31- // privacy: null => both; "PUBLIC" or "PRIVATE" to restrict
32- const PRIVACY = null ; // or "PUBLIC" | "PRIVATE"
24+ // null => both public & private; or "PUBLIC" / "PRIVATE"
25+ const PRIVACY = null ;
3326
3427const README_PATH = path . join ( process . cwd ( ) , "profile" , "README.md" ) ;
3528
@@ -67,7 +60,6 @@ const gql = (query, variables) =>
6760 req . end ( ) ;
6861 } ) ;
6962
70- // One page of repos at a time, aggregating counts per repo.
7163const REPO_PAGE_SIZE = 50 ;
7264
7365const REPOS_QUERY = `
@@ -116,13 +108,10 @@ async function fetchAllRepos() {
116108 const page = data ?. organization ?. repositories ;
117109 if ( ! page ) break ;
118110 let nodes = page . nodes || [ ] ;
119- if ( ! INCLUDE_ARCHIVED ) {
120- nodes = nodes . filter ( ( r ) => ! r . isArchived ) ;
121- }
111+ if ( ! INCLUDE_ARCHIVED ) nodes = nodes . filter ( ( r ) => ! r . isArchived ) ;
122112 all . push ( ...nodes ) ;
123- if ( page . pageInfo . hasNextPage ) {
124- after = page . pageInfo . endCursor ;
125- } else break ;
113+ if ( page . pageInfo . hasNextPage ) after = page . pageInfo . endCursor ;
114+ else break ;
126115 }
127116 return all ;
128117}
@@ -133,19 +122,11 @@ function formatNumber(n) {
133122
134123function renderMarkdown ( stats , topRepos ) {
135124 const {
136- repoCount,
137- totalCommits,
138- openIssues,
139- closedIssues,
140- openPRs,
141- closedPRs,
142- mergedPRs,
143- stars,
144- forks,
125+ repoCount, totalCommits, openIssues, closedIssues,
126+ openPRs, closedPRs, mergedPRs, stars, forks,
145127 } = stats ;
146128
147129 const lines = [ ] ;
148-
149130 lines . push ( `### 📊 Organisation Stats for **${ ORG } **` ) ;
150131 lines . push ( "" ) ;
151132 lines . push ( "| Metric | Count |" ) ;
@@ -160,7 +141,7 @@ function renderMarkdown(stats, topRepos) {
160141 lines . push ( `| Stars | ${ formatNumber ( stars ) } |` ) ;
161142 lines . push ( `| Forks | ${ formatNumber ( forks ) } |` ) ;
162143 lines . push ( "" ) ;
163- lines . push ( `<sub>Updated: ${ new Date ( ) . toISOString ( ) . replace ( "T" , " " ) . replace ( "Z" , " UTC" ) } </sub>` ) ;
144+ lines . push ( `<sub>Updated: ${ new Date ( ) . toISOString ( ) . replace ( "T" , " " ) . replace ( "Z" , " UTC" ) } </sub>` ) ;
164145 lines . push ( "" ) ;
165146
166147 if ( topRepos . length ) {
@@ -170,31 +151,20 @@ function renderMarkdown(stats, topRepos) {
170151 lines . push ( "|---|---:|---:|---:|---:|---:|" ) ;
171152 for ( const r of topRepos ) {
172153 lines . push (
173- `| [${ r . name } ](https://github.com/${ ORG } /${ r . name } ) | ${ formatNumber (
174- r . commits
175- ) } | ${ formatNumber ( r . issuesOpen ) } | ${ formatNumber (
176- r . prsOpen
177- ) } | ${ formatNumber ( r . stars ) } | ${ formatNumber ( r . forks ) } |`
154+ `| [${ r . name } ](https://github.com/${ ORG } /${ r . name } ) | ${ formatNumber ( r . commits ) } | ${ formatNumber ( r . issuesOpen ) } | ${ formatNumber ( r . prsOpen ) } | ${ formatNumber ( r . stars ) } | ${ formatNumber ( r . forks ) } |`
178155 ) ;
179156 }
180157 lines . push ( "" ) ;
181158 }
182-
183159 return lines . join ( "\n" ) ;
184160}
185161
186162function replaceStatsSection ( readme , newBlock ) {
187163 const start = "<!-- ORG-STATS:START -->" ;
188164 const end = "<!-- ORG-STATS:END -->" ;
189- const pattern = new RegExp (
190- `${ start } [\\s\\S]*?${ end } ` ,
191- "m"
192- ) ;
165+ const pattern = new RegExp ( `${ start } [\\s\\S]*?${ end } ` , "m" ) ;
193166 const replacement = `${ start } \n${ newBlock } \n${ end } ` ;
194- if ( ! pattern . test ( readme ) ) {
195- // If markers missing, append at end
196- return `${ readme . trim ( ) } \n\n${ replacement } \n` ;
197- }
167+ if ( ! pattern . test ( readme ) ) return `${ readme . trim ( ) } \n\n${ replacement } \n` ;
198168 return readme . replace ( pattern , replacement ) ;
199169}
200170
@@ -203,22 +173,16 @@ function replaceStatsSection(readme, newBlock) {
203173 const repos = await fetchAllRepos ( ) ;
204174
205175 const aggregated = {
206- repoCount : 0 ,
207- totalCommits : 0 ,
208- openIssues : 0 ,
209- closedIssues : 0 ,
210- openPRs : 0 ,
211- closedPRs : 0 ,
212- mergedPRs : 0 ,
213- stars : 0 ,
214- forks : 0 ,
176+ repoCount : 0 , totalCommits : 0 ,
177+ openIssues : 0 , closedIssues : 0 ,
178+ openPRs : 0 , closedPRs : 0 , mergedPRs : 0 ,
179+ stars : 0 , forks : 0 ,
215180 } ;
216181
217182 const perRepo = [ ] ;
218183
219184 for ( const r of repos ) {
220- const commits =
221- r . defaultBranchRef ?. target ?. history ?. totalCount ?? 0 ;
185+ const commits = r . defaultBranchRef ?. target ?. history ?. totalCount ?? 0 ;
222186 const issuesOpen = r . issues ?. totalCount ?? 0 ;
223187 const issuesClosed = r . issuesClosed ?. totalCount ?? 0 ;
224188 const prsOpen = r . pullRequests ?. totalCount ?? 0 ;
@@ -237,17 +201,9 @@ function replaceStatsSection(readme, newBlock) {
237201 aggregated . stars += stars ;
238202 aggregated . forks += forks ;
239203
240- perRepo . push ( {
241- name : r . name ,
242- commits,
243- issuesOpen,
244- prsOpen,
245- stars,
246- forks,
247- } ) ;
204+ perRepo . push ( { name : r . name , commits, issuesOpen, prsOpen, stars, forks } ) ;
248205 }
249206
250- // top 10 by commits
251207 perRepo . sort ( ( a , b ) => b . commits - a . commits ) ;
252208 const topRepos = perRepo . slice ( 0 , 10 ) ;
253209
0 commit comments