Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/github/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ export class GitHubApi implements GitHubClient {
private readonly octokit: InstanceType<typeof ActionOctokit>;
private readonly trace: TraceRedaction;
private readonly baseUrl: string;
private readonly apiVersion: string;
constructor(options: GitHubApiOptions) {
this.baseUrl = options.baseUrl ?? process.env.GITHUB_API_URL ?? "https://api.github.com";
this.apiVersion = options.apiVersion ?? DEFAULT_API_VERSION;
this.trace = new TraceRedaction(options.io ?? SILENT_TRACE);
const envKnob = envRetryBaseMs();
const retryBaseMs = options.retryBaseMs ?? envKnob ?? 1000;
Expand Down Expand Up @@ -219,6 +217,13 @@ export class GitHubApi implements GitHubClient {
onSecondaryRateLimit: throttleCallback("secondary rate limit", this.trace),
},
});
// A per-request accept (the raw media-type read) overrides the default; the hooks the plugins wrapped stay.
this.octokit.request = this.octokit.request.defaults({
headers: {
accept: "application/vnd.github+json",
"x-github-api-version": options.apiVersion ?? DEFAULT_API_VERSION,
},
});
}

async tryRequest(
Expand Down Expand Up @@ -295,10 +300,6 @@ export class GitHubApi implements GitHubClient {
url: path,
per_page: options?.perPage ?? PAGE_SIZE,
page: 1,
headers: {
accept: "application/vnd.github+json",
"x-github-api-version": this.apiVersion,
},
} as unknown as Parameters<RequestInterface>[0];
try {
for await (const _page of this.octokit.paginate.iterator(request, firstPage)) {
Expand Down Expand Up @@ -357,10 +358,7 @@ export class GitHubApi implements GitHubClient {
const response = await this.octokit.request({
method,
url: path,
headers: {
accept: options?.accept ?? "application/vnd.github+json",
"x-github-api-version": this.apiVersion,
},
...(options?.accept === undefined ? {} : { headers: { accept: options.accept } }),
// The body is the tree the scan inspected, so octokit never reshapes the payload and the wire carries exactly what was scanned.
...(payload === undefined ? {} : { data: secretScan.value.payload }),
} as unknown as Parameters<InstanceType<typeof ActionOctokit>["request"]>[0]);
Expand Down Expand Up @@ -437,10 +435,6 @@ export class GitHubApi implements GitHubClient {
response = (await this.octokit.request({
method: "POST",
url: "/graphql",
headers: {
accept: "application/vnd.github+json",
"x-github-api-version": this.apiVersion,
},
// operationName makes the request self-describing on the wire (the mock dispatches on it).
data: { query: op.query, operationName: op.name, variables: scan.value.payload },
} as unknown as Parameters<InstanceType<typeof ActionOctokit>["request"]>[0])) as {
Expand Down
Loading