@stacksjs/github 0.75.151 → 0.75.153

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/client.d.ts CHANGED
@@ -17,6 +17,15 @@ export declare function ghFetch(url: string, attempt?: number): Promise<Response
17
17
  */
18
18
  export declare function mapWithConcurrency<T, R>(items: T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]>;
19
19
  export declare const GITHUB_API: 'https://api.github.com';
20
+ /**
21
+ * `X-GitHub-Api-Version`.
22
+ *
23
+ * GitHub dates its REST API versions and keeps a version serving for at least
24
+ * 24 months after its successor ships, so this is a value to review rather than
25
+ * one that breaks without notice. It was written at both header builders below
26
+ * (stacksjs/stacks#2859).
27
+ */
28
+ export declare const GITHUB_API_VERSION: '2022-11-28';
20
29
  export declare interface GitHubClientOptions {
21
30
  token?: string
22
31
  apiUrl?: string
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- export const GITHUB_API="https://api.github.com";function getToken(){const token=process.env.GITHUB_TOKEN;if(!token)throw Error("GITHUB_TOKEN environment variable is required");return token}function resolveToken(token){if(token)return token;return getToken()}export function ghHeaders(){return{Authorization:`Bearer ${getToken()}`,Accept:"application/vnd.github+json","X-GitHub-Api-Version":"2022-11-28"}}export function githubHeaders(token){return{Authorization:`Bearer ${resolveToken(token)}`,Accept:"application/vnd.github+json","X-GitHub-Api-Version":"2022-11-28"}}function retryDelay(res,attempt){if(!(res.status===429||res.status===403&&(res.headers.get("x-ratelimit-remaining")==="0"||!!res.headers.get("retry-after"))))return null;const retryAfterHeader=res.headers.get("retry-after"),resetHeader=res.headers.get("x-ratelimit-reset");if(retryAfterHeader)return Number(retryAfterHeader)*1000;if(resetHeader)return Math.max(0,Number(resetHeader)*1000-Date.now())+500;return 1000*2**attempt}export async function githubRequest(path,init={},options={},attempt=0){const fetcher=options.fetch??globalThis.fetch,url=path.startsWith("http")?path:`${options.apiUrl??GITHUB_API}${path.startsWith("/")?path:`/${path}`}`,response=await fetcher(url,{...init,headers:{...githubHeaders(options.token),...init.headers}});if(response.ok||attempt>=3)return response;const waitMs=retryDelay(response,attempt);if(waitMs===null)return response;await new Promise((resolve)=>setTimeout(resolve,Math.min(waitMs,30000)));return githubRequest(path,init,options,attempt+1)}export async function githubJson(path,init={},options={}){const response=await githubRequest(path,init,options);if(!response.ok){const payload=await response.text();let message=payload;try{message=JSON.parse(payload).message||payload}catch{}throw Error(`GitHub API ${response.status}: ${message||response.statusText}`)}if(response.status===204)return;return await response.json()}export async function ghFetch(url,attempt=0){const res=await fetch(url,{headers:ghHeaders()});if(res.ok||attempt>=3)return res;if(!(res.status===429||res.status===403&&(res.headers.get("x-ratelimit-remaining")==="0"||res.headers.get("retry-after"))))return res;const retryAfterHeader=res.headers.get("retry-after"),resetHeader=res.headers.get("x-ratelimit-reset");let waitMs=1000*2**attempt;if(retryAfterHeader)waitMs=Number(retryAfterHeader)*1000;else if(resetHeader)waitMs=Math.max(0,Number(resetHeader)*1000-Date.now())+500;await new Promise((r)=>setTimeout(r,Math.min(waitMs,30000)));return ghFetch(url,attempt+1)}export async function mapWithConcurrency(items,limit,fn){const results=Array.from({length:items.length});let next=0;async function worker(){while(!0){const i=next++;if(i>=items.length)return;results[i]=await fn(items[i])}}await Promise.all(Array.from({length:Math.min(limit,items.length)},()=>worker()));return results}
1
+ export const GITHUB_API="https://api.github.com",GITHUB_API_VERSION="2022-11-28";function getToken(){const token=process.env.GITHUB_TOKEN;if(!token)throw Error("GITHUB_TOKEN environment variable is required");return token}function resolveToken(token){if(token)return token;return getToken()}export function ghHeaders(){return githubHeaders()}export function githubHeaders(token){return{Authorization:`Bearer ${resolveToken(token)}`,Accept:"application/vnd.github+json","X-GitHub-Api-Version":GITHUB_API_VERSION}}function retryDelay(res,attempt){if(!(res.status===429||res.status===403&&(res.headers.get("x-ratelimit-remaining")==="0"||!!res.headers.get("retry-after"))))return null;const retryAfterHeader=res.headers.get("retry-after"),resetHeader=res.headers.get("x-ratelimit-reset");if(retryAfterHeader)return Number(retryAfterHeader)*1000;if(resetHeader)return Math.max(0,Number(resetHeader)*1000-Date.now())+500;return 1000*2**attempt}export async function githubRequest(path,init={},options={},attempt=0){const fetcher=options.fetch??globalThis.fetch,url=path.startsWith("http")?path:`${options.apiUrl??GITHUB_API}${path.startsWith("/")?path:`/${path}`}`,response=await fetcher(url,{...init,headers:{...githubHeaders(options.token),...init.headers}});if(response.ok||attempt>=3)return response;const waitMs=retryDelay(response,attempt);if(waitMs===null)return response;await new Promise((resolve)=>setTimeout(resolve,Math.min(waitMs,30000)));return githubRequest(path,init,options,attempt+1)}export async function githubJson(path,init={},options={}){const response=await githubRequest(path,init,options);if(!response.ok){const payload=await response.text();let message=payload;try{message=JSON.parse(payload).message||payload}catch{}throw Error(`GitHub API ${response.status}: ${message||response.statusText}`)}if(response.status===204)return;return await response.json()}export async function ghFetch(url,attempt=0){const res=await fetch(url,{headers:ghHeaders()});if(res.ok||attempt>=3)return res;if(!(res.status===429||res.status===403&&(res.headers.get("x-ratelimit-remaining")==="0"||res.headers.get("retry-after"))))return res;const retryAfterHeader=res.headers.get("retry-after"),resetHeader=res.headers.get("x-ratelimit-reset");let waitMs=1000*2**attempt;if(retryAfterHeader)waitMs=Number(retryAfterHeader)*1000;else if(resetHeader)waitMs=Math.max(0,Number(resetHeader)*1000-Date.now())+500;await new Promise((r)=>setTimeout(r,Math.min(waitMs,30000)));return ghFetch(url,attempt+1)}export async function mapWithConcurrency(items,limit,fn){const results=Array.from({length:items.length});let next=0;async function worker(){while(!0){const i=next++;if(i>=items.length)return;results[i]=await fn(items[i])}}await Promise.all(Array.from({length:Math.min(limit,items.length)},()=>worker()));return results}
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ export type {
33
33
  * single dimension without pulling the whole snapshot through.
34
34
  */
35
35
  export { fetchBotPRCounts, fetchPullRequestCounts } from './bots';
36
- export { ghFetch, ghHeaders, githubHeaders, githubJson, githubRequest, GITHUB_API, mapWithConcurrency } from './client';
36
+ export { ghFetch, ghHeaders, githubHeaders, githubJson, githubRequest, GITHUB_API, GITHUB_API_VERSION, mapWithConcurrency } from './client';
37
37
  export { clearDashboardCache, getDashboardData } from './dashboard';
38
38
  export { detectNewlyFailedRuns } from './failure-detector';
39
39
  export { fetchAllRepos } from './repos';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{fetchBotPRCounts,fetchPullRequestCounts}from"./bots";export{ghFetch,ghHeaders,githubHeaders,githubJson,githubRequest,GITHUB_API,mapWithConcurrency}from"./client";export{clearDashboardCache,getDashboardData}from"./dashboard";export{detectNewlyFailedRuns}from"./failure-detector";export{fetchAllRepos}from"./repos";export{fetchRepoActiveRuns}from"./runners";export{fetchRunJobs,fetchWorkflowRuns}from"./run-history";export{detectRunnerPressure}from"./runner-pressure-detector";export{fetchFailedJobs,fetchRepoStatus}from"./runs";export{createPullRequestWithFiles,fetchRepositoryFile,fetchRepositoryTree}from"./pull-requests";
1
+ export{fetchBotPRCounts,fetchPullRequestCounts}from"./bots";export{ghFetch,ghHeaders,githubHeaders,githubJson,githubRequest,GITHUB_API,GITHUB_API_VERSION,mapWithConcurrency}from"./client";export{clearDashboardCache,getDashboardData}from"./dashboard";export{detectNewlyFailedRuns}from"./failure-detector";export{fetchAllRepos}from"./repos";export{fetchRepoActiveRuns}from"./runners";export{fetchRunJobs,fetchWorkflowRuns}from"./run-history";export{detectRunnerPressure}from"./runner-pressure-detector";export{fetchFailedJobs,fetchRepoStatus}from"./runs";export{createPullRequestWithFiles,fetchRepositoryFile,fetchRepositoryTree}from"./pull-requests";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/github",
3
3
  "type": "module",
4
- "version": "0.75.151",
4
+ "version": "0.75.153",
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": [