Skip to content

Commit 79a27e9

Browse files
committed
refactor(github): build request headers once
GitHubApi built the accept and x-github-api-version pair inline at three request sites (tryList, request, tryGraphql). One private headers() method now returns the pair, and the raw media-type read passes its own accept. Nothing on the wire changes.
1 parent e6a9867 commit 79a27e9

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

‎src/github/api.ts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ export class GitHubApi implements GitHubClient {
221221
});
222222
}
223223

224+
private headers(accept = "application/vnd.github+json"): Record<string, string> {
225+
return { accept, "x-github-api-version": this.apiVersion };
226+
}
227+
224228
async tryRequest(
225229
method: string,
226230
path: string,
@@ -295,10 +299,7 @@ export class GitHubApi implements GitHubClient {
295299
url: path,
296300
per_page: options?.perPage ?? PAGE_SIZE,
297301
page: 1,
298-
headers: {
299-
accept: "application/vnd.github+json",
300-
"x-github-api-version": this.apiVersion,
301-
},
302+
headers: this.headers(),
302303
} as unknown as Parameters<RequestInterface>[0];
303304
try {
304305
for await (const _page of this.octokit.paginate.iterator(request, firstPage)) {
@@ -357,10 +358,7 @@ export class GitHubApi implements GitHubClient {
357358
const response = await this.octokit.request({
358359
method,
359360
url: path,
360-
headers: {
361-
accept: options?.accept ?? "application/vnd.github+json",
362-
"x-github-api-version": this.apiVersion,
363-
},
361+
headers: this.headers(options?.accept),
364362
// The body is the tree the scan inspected, so octokit never reshapes the payload and the wire carries exactly what was scanned.
365363
...(payload === undefined ? {} : { data: secretScan.value.payload }),
366364
} as unknown as Parameters<InstanceType<typeof ActionOctokit>["request"]>[0]);
@@ -437,10 +435,7 @@ export class GitHubApi implements GitHubClient {
437435
response = (await this.octokit.request({
438436
method: "POST",
439437
url: "/graphql",
440-
headers: {
441-
accept: "application/vnd.github+json",
442-
"x-github-api-version": this.apiVersion,
443-
},
438+
headers: this.headers(),
444439
// operationName makes the request self-describing on the wire (the mock dispatches on it).
445440
data: { query: op.query, operationName: op.name, variables: scan.value.payload },
446441
} as unknown as Parameters<InstanceType<typeof ActionOctokit>["request"]>[0])) as {

0 commit comments

Comments
 (0)