Skip to content

Commit 3e1b3ca

Browse files
committed
fix: resolve typescript errors and add buildUrl utility
- Fix headers type assertion issue - Add buildUrl utility function for URL parameter handling
1 parent 272e269 commit 3e1b3ca

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/github/common/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ async function parseResponseBody(response: Response): Promise<unknown> {
1414
return response.text();
1515
}
1616

17+
export function buildUrl(baseUrl: string, params: Record<string, string | number | undefined>): string {
18+
const url = new URL(baseUrl);
19+
Object.entries(params).forEach(([key, value]) => {
20+
if (value !== undefined) {
21+
url.searchParams.append(key, value.toString());
22+
}
23+
});
24+
return url.toString();
25+
}
26+
1727
export async function githubRequest(
1828
url: string,
1929
options: RequestOptions = {}
2030
): Promise<unknown> {
21-
const headers = {
31+
const headers: Record<string, string> = {
2232
"Accept": "application/vnd.github.v3+json",
2333
"Content-Type": "application/json",
2434
...options.headers,

0 commit comments

Comments
 (0)