From 3e1b3caaec9c7525ef2641ebc29bb57447d0b787 Mon Sep 17 00:00:00 2001 From: "Peter M. Elias" Date: Sat, 28 Dec 2024 03:34:39 -0800 Subject: [PATCH] fix: resolve typescript errors and add buildUrl utility - Fix headers type assertion issue - Add buildUrl utility function for URL parameter handling --- src/github/common/utils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/github/common/utils.ts b/src/github/common/utils.ts index ef2fc0bb..0e6f731a 100644 --- a/src/github/common/utils.ts +++ b/src/github/common/utils.ts @@ -14,11 +14,21 @@ async function parseResponseBody(response: Response): Promise { return response.text(); } +export function buildUrl(baseUrl: string, params: Record): string { + const url = new URL(baseUrl); + Object.entries(params).forEach(([key, value]) => { + if (value !== undefined) { + url.searchParams.append(key, value.toString()); + } + }); + return url.toString(); +} + export async function githubRequest( url: string, options: RequestOptions = {} ): Promise { - const headers = { + const headers: Record = { "Accept": "application/vnd.github.v3+json", "Content-Type": "application/json", ...options.headers,