@stacksjs/github 0.75.38 → 0.75.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dashboard.js +1 -1
- package/package.json +1 -1
package/dist/dashboard.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fetchPullRequestCounts}from"./bots";import{mapWithConcurrency}from"./client";import{fetchAllRepos}from"./repos";import{fetchRepoActiveRuns}from"./runners";import{fetchRepoStatus}from"./runs";const DEFAULT_TTL_MS=30000,DEFAULT_CACHE_PATH=".cache/dashboard.json",DEFAULT_RUNNER_CAP=20,DASHBOARD_CACHE_VERSION=2,caches=new Map;function entryFor(path){let e=caches.get(path);if(!e){e={data:null,savedAt:0,inflight:null,diskLoaded:!1};caches.set(path,e)}return e}async function loadCacheFromDisk(entry,path){if(entry.diskLoaded)return;entry.diskLoaded=!0;try{const file=Bun.file(path);if(!await file.exists())return;const stored=await file.json();if(stored.version!==DASHBOARD_CACHE_VERSION)return;entry.data=stored.data;entry.savedAt=stored.savedAt}catch{}}async function saveCacheToDisk(path,data,savedAt){try{await Bun.write(path,JSON.stringify({version:DASHBOARD_CACHE_VERSION,data,savedAt}))}catch(err){console.warn("[github/dashboard] cache write failed:",err)}}async function buildDashboardData(opts){const orgs=opts.orgs,runnerCaps=opts.runnerCaps??{},defaultRunnerCap=opts.defaultRunnerCap??DEFAULT_RUNNER_CAP,repos=await fetchAllRepos(orgs,opts.ignoreRepos),statuses=await mapWithConcurrency(repos,8,(r)=>fetchRepoStatus(r.owner,r.name,r.default_branch)),prCountMaps=await Promise.all(orgs.flatMap((org)=>[fetchPullRequestCounts(org,"head:buddy
|
|
1
|
+
import{fetchPullRequestCounts}from"./bots";import{mapWithConcurrency}from"./client";import{fetchAllRepos}from"./repos";import{fetchRepoActiveRuns}from"./runners";import{fetchRepoStatus}from"./runs";const DEFAULT_TTL_MS=30000,DEFAULT_CACHE_PATH=".cache/dashboard.json",DEFAULT_RUNNER_CAP=20,DASHBOARD_CACHE_VERSION=2,caches=new Map;function entryFor(path){let e=caches.get(path);if(!e){e={data:null,savedAt:0,inflight:null,diskLoaded:!1};caches.set(path,e)}return e}async function loadCacheFromDisk(entry,path){if(entry.diskLoaded)return;entry.diskLoaded=!0;try{const file=Bun.file(path);if(!await file.exists())return;const stored=await file.json();if(stored.version!==DASHBOARD_CACHE_VERSION)return;entry.data=stored.data;entry.savedAt=stored.savedAt}catch{}}async function saveCacheToDisk(path,data,savedAt){try{await Bun.write(path,JSON.stringify({version:DASHBOARD_CACHE_VERSION,data,savedAt}))}catch(err){console.warn("[github/dashboard] cache write failed:",err)}}async function buildDashboardData(opts){const orgs=opts.orgs,runnerCaps=opts.runnerCaps??{},defaultRunnerCap=opts.defaultRunnerCap??DEFAULT_RUNNER_CAP,repos=await fetchAllRepos(orgs,opts.ignoreRepos),statuses=await mapWithConcurrency(repos,8,(r)=>fetchRepoStatus(r.owner,r.name,r.default_branch)),prCountMaps=await Promise.all(orgs.flatMap((org)=>[fetchPullRequestCounts(org,"head:buddy").then((m)=>({type:"buddy-bot",map:m})),fetchPullRequestCounts(org,"author:app/github-actions -head:buddy").then((m)=>({type:"actions",map:m}))])),buddyBotCounts=new Map,actionsCounts=new Map;for(const{type,map}of prCountMaps){const target=type==="buddy-bot"?buddyBotCounts:actionsCounts;for(const[k,v]of map)target.set(k,(target.get(k)??0)+v)}for(const s of statuses){const buddyBotCount=buddyBotCounts.get(s.fullName)??0,aCount=actionsCounts.get(s.fullName)??0;s.buddyBotPRs=buddyBotCount;s.actionsPRs=aCount;if(buddyBotCount>0)s.buddyBotPRsUrl=`https://github.com/${s.fullName}/pulls?q=${encodeURIComponent("is:pr is:open head:buddy")}`;if(aCount>0)s.actionsPRsUrl=`https://github.com/${s.fullName}/pulls?q=${encodeURIComponent("is:pr is:open author:app/github-actions -head:buddy")}`}const runnerCounts=await mapWithConcurrency(repos,8,async(r)=>({owner:r.owner,...await fetchRepoActiveRuns(r.owner,r.name)})),runners={};for(const org of orgs)runners[org]={running:0,queued:0,cap:runnerCaps[org]??defaultRunnerCap};for(const c of runnerCounts){if(!runners[c.owner])runners[c.owner]={running:0,queued:0,cap:runnerCaps[c.owner]??defaultRunnerCap};runners[c.owner].running+=c.running;runners[c.owner].queued+=c.queued}const order={failure:0,error:1,pending:2,success:3,no_runs:4};statuses.sort((a,b)=>(order[a.status]??5)-(order[b.status]??5));return{repos:statuses,fetchedAt:new Date().toISOString(),total:statuses.length,passing:statuses.filter((r)=>r.status==="success").length,failing:statuses.filter((r)=>r.status==="failure"||r.status==="error").length,pending:statuses.filter((r)=>r.status==="pending").length,noRuns:statuses.filter((r)=>r.status==="no_runs").length,runners}}export async function getDashboardData(opts){const ttl=opts.cacheTtlMs??DEFAULT_TTL_MS,path=opts.cachePath??DEFAULT_CACHE_PATH,entry=entryFor(path);await loadCacheFromDisk(entry,path);const now=Date.now();if(entry.data){if(now-entry.savedAt>=ttl&&!entry.inflight){entry.inflight=buildDashboardData(opts).then(async(data)=>{entry.data=data;entry.savedAt=Date.now();await saveCacheToDisk(path,data,entry.savedAt);return data}).finally(()=>{entry.inflight=null});entry.inflight.catch((err)=>console.warn("[github/dashboard] refresh failed:",err))}return entry.data}if(!entry.inflight)entry.inflight=buildDashboardData(opts).then(async(data)=>{entry.data=data;entry.savedAt=Date.now();await saveCacheToDisk(path,data,entry.savedAt);return data}).finally(()=>{entry.inflight=null});return entry.inflight}export function clearDashboardCache(cachePath=DEFAULT_CACHE_PATH){caches.delete(cachePath)}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/github",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.75.
|
|
4
|
+
"version": "0.75.40",
|
|
5
5
|
"description": "GitHub API client used by Stacks framework features (dashboard CI surface, notifications, runner alerts).",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|