mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-04 15:57:33 +01:00
fix(scorecard): --now bounds every windowed line; recommended-harness week is 83 PRs (GST-135)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
959c8a6a4f
commit
40fe5c008e
7 files changed
+119
-43
No files matched your search
@@ -95,21 +95,27 @@ export interface CiJob { id: number; name: string; conclusion: string | null; st
|
||||
|
||||
const PAGE = 100;
|
||||
|
||||
/** The runs API's `created` filter, by UTC day (both ends inclusive): `>=since`, or `since..until` when the window has an end. */
|
||||
export function createdFilter(since: string, until?: string): string {
|
||||
return `created=${encodeURIComponent(until ? `${since.slice(0, 10)}..${until.slice(0, 10)}` : `>=${since.slice(0, 10)}`)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every completed run of `workflow` created at or after `since`, newest first,
|
||||
* paging until a page is short or older than `since`. A failure on any page
|
||||
* throws: a partial history is never reported as a complete one.
|
||||
* Every completed run of `workflow` created at or after `since` (and before
|
||||
* `until` when given), newest first, paging until a page is short or older
|
||||
* than `since`. A failure on any page throws: a partial history is never
|
||||
* reported as a complete one.
|
||||
*/
|
||||
export function listWorkflowRuns(client: GhClient, repo: string, workflow: string,
|
||||
opts: { since: string; branch?: string; event?: string; maxPages?: number }): CiRun[] {
|
||||
opts: { since: string; until?: string; branch?: string; event?: string; maxPages?: number }): CiRun[] {
|
||||
const out: CiRun[] = [];
|
||||
const query = [`status=completed`, `per_page=${PAGE}`, `created=${encodeURIComponent(`>=${opts.since.slice(0, 10)}`)}`,
|
||||
const query = [`status=completed`, `per_page=${PAGE}`, createdFilter(opts.since, opts.until),
|
||||
...(opts.branch ? [`branch=${encodeURIComponent(opts.branch)}`] : []), ...(opts.event ? [`event=${encodeURIComponent(opts.event)}`] : [])];
|
||||
for (let page = 1; page <= (opts.maxPages ?? 20); page++) {
|
||||
const body = client.getJson(`repos/${repo}/actions/workflows/${workflow}/runs?${query.join('&')}&page=${page}`) as { workflow_runs?: any[] };
|
||||
const runs = Array.isArray(body?.workflow_runs) ? body.workflow_runs : [];
|
||||
for (const run of runs) {
|
||||
if (String(run.created_at) < opts.since) continue;
|
||||
if (String(run.created_at) < opts.since || (opts.until && Date.parse(String(run.created_at)) >= Date.parse(opts.until))) continue;
|
||||
if ((opts.branch && run.head_branch !== opts.branch) || (opts.event && run.event !== opts.event)) continue;
|
||||
out.push({ id: Number(run.id), attempt: Number(run.run_attempt ?? 1), sha: String(run.head_sha ?? ''), branch: String(run.head_branch ?? ''),
|
||||
event: String(run.event ?? ''), status: String(run.status ?? ''), conclusion: run.conclusion ?? null,
|
||||
|
||||
Reference in new issue
Block a user