From 1e5b85114bb0db264f504cede929344a8c2c7bb7 Mon Sep 17 00:00:00 2001 From: Samantha Lu Date: Sun, 30 Aug 2026 19:59:10 +0000 Subject: [PATCH 1/2] add devcontainer file for project 1A build checkpoint --- .devcontainer/Dockerfile | 5 +++++ .devcontainer/devcontainer.json | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..2ef28b9f --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,5 @@ +FROM mcr.microsoft.com/devcontainers/base:ubuntu + +RUN apt-get update \ + && apt-get install -y python3 python3-pip make g++ \ + && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..887bfac9 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,11 @@ +{ + "name": "opencode", + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/michidk/devcontainers-features/bun:1": { + "version": "1.3.0" + } + } +} From e89daee53096bb0c6959c872ab885c33d3c93047 Mon Sep 17 00:00:00 2001 From: Samantha Lu Date: Sun, 6 Sep 2026 04:09:09 +0000 Subject: [PATCH 2/2] Refactor retry boolean via helper file and write tests --- script/github/close-prs-retry-helper.ts | 5 ++++ script/github/close-prs.test.ts | 38 +++++++++++++++++++++++++ script/github/close-prs.ts | 4 ++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 script/github/close-prs-retry-helper.ts create mode 100644 script/github/close-prs.test.ts diff --git a/script/github/close-prs-retry-helper.ts b/script/github/close-prs-retry-helper.ts new file mode 100644 index 00000000..6efd8c22 --- /dev/null +++ b/script/github/close-prs-retry-helper.ts @@ -0,0 +1,5 @@ +export function validRetry(status: number, retryMs: number, attempt: number): boolean { + const isValidRetryStatus = (status === 403 || status === 429 || status >= 500) + const canRetry = retryMs > 0 && attempt < 10 + return isValidRetryStatus && canRetry + } \ No newline at end of file diff --git a/script/github/close-prs.test.ts b/script/github/close-prs.test.ts new file mode 100644 index 00000000..2f4ac77a --- /dev/null +++ b/script/github/close-prs.test.ts @@ -0,0 +1,38 @@ +import {describe, expect, test} from "bun:test" +import {validRetry} from "./close-prs-retry-helper" + +//syntac and formatting sourced from https://oneuptime.com/blog/post/2026-01-31-bun-testing/view + +//describe wfor grouping +describe("validRetry", ()=> { + //individual tests + test("yes retry for 403 response", ()=> { + expect(validRetry(403, 1000, 0)).toBe(true) + }) + + test("yes retry for 429 response", ()=> { + expect(validRetry(429, 1000, 0)).toBe(true) + }) + + test("yes retry for 500 or higher response", ()=> { + expect(validRetry(500, 1000, 0)).toBe(true) + expect(validRetry(503, 1000, 0)).toBe(true) + + }) + + test("no retry for any other response type/number", ()=> { + expect(validRetry(200, 1000, 0)).toBe(false) + expect(validRetry(404, 1000, 0)).toBe(false) + + }) + + + test("no retry for zero delay", ()=> { + expect(validRetry(403, 0, 0)).toBe(false) + }) + + + test("no retry if maximum attempts reached", ()=> { + expect(validRetry(403, 1000, 10)).toBe(false) + }) +}) \ No newline at end of file diff --git a/script/github/close-prs.ts b/script/github/close-prs.ts index 6b10db3e..d5ce7377 100755 --- a/script/github/close-prs.ts +++ b/script/github/close-prs.ts @@ -1,6 +1,7 @@ #!/usr/bin/env bun import { parseArgs } from "util" +import { validRetry } from "./close-prs-retry-helper" const defaultRepo = process.env.GITHUB_REPOSITORY ?? "" const defaultAgeMonths = 1 @@ -315,8 +316,9 @@ async function githubRequest(path: string, init: RequestInit, attempt = 0): Prom : response.status >= 500 ? Math.min(300_000, 10_000 * 2 ** attempt) : 0 + - if ((response.status === 403 || response.status === 429 || response.status >= 500) && retryMs > 0 && attempt < 10) { + if (validRetry(response.status, retryMs, attempt)) { console.warn(`GitHub request failed; sleeping ${Math.ceil(retryMs / 1000)}s before retry ${attempt + 1}`) await sleep(retryMs) return githubRequest(path, init, attempt + 1)