Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 6ac19e6

Browse files
authored
fix: remove fetch override for octokit and versions (#4042)
## Problem Updating octkit auth app to 6.1.1. fails runtime. Not in our tests due to most of the SDK layer is mocked. Only information we catch is a generic Error. ``` HttpError: response.json(...).catch is not a function ``` Via [issue](octokit/auth-app.js#634) @wolfy1339 provides feedback that the cause could be related to overriding the fetch in octokit. In PR #3554 where tracing was introduced also the fetch command was overriden, this due the fact the node fetch was not working properly for tracing HTTP calls, which are in our case the cals to GitHub. This problem seems now to be fixed in the [AWS xray sdk](https://github.com/aws/aws-xray-sdk-node/blob/master/CHANGELOG.md#370). ## Solution The solution is quite simple. Just remove axios as fetch implementation (override) and use the default provide by octokit. ## Testing The problem was not detected in the unit tests. Reason is that the unit test mocking the octokit SDK. In case of an ovrride we have doen. We hsould have added a test using nock to mock the HTTP calls and not the full SDK to catch problems like this in the unit test. By removing the override, we can relay again on the test efforts done by octokit. ## References - fix #3966
1 parent c15c99d commit 6ac19e6

File tree

10 files changed

+96
-480
lines changed

10 files changed

+96
-480
lines changed

Diff for: .github/dependabot.yml

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ updates:
3636
update-types: ["version-update:semver-major"]
3737
- dependency-name: "@octokit/*"
3838
update-types: ["version-update:semver-major"]
39-
- dependency-name: "@octokit/rest"
40-
- dependency-name: "@octokit/auth-app"
4139
- dependency-name: "eslint"
4240
update-types: ["version-update:semver-major"]
4341
commit-message:

Diff for: lambdas/functions/control-plane/jest.config.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const config: Config = {
66
...defaultConfig,
77
coverageThreshold: {
88
global: {
9-
statements: 98.01,
10-
branches: 97.28,
11-
functions: 95.6,
12-
lines: 97.94,
9+
statements: 97.99,
10+
branches: 97.26,
11+
functions: 95.45,
12+
lines: 97.92,
1313
},
1414
},
1515
};

Diff for: lambdas/functions/control-plane/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@
4141
"@aws-sdk/client-ec2": "^3.624.0",
4242
"@aws-sdk/types": "^3.609.0",
4343
"@middy/core": "^4.7.0",
44-
"@octokit/auth-app": "6.0.3",
44+
"@octokit/auth-app": "6.1.1",
4545
"@octokit/core": "5.2.0",
4646
"@octokit/plugin-throttling": "8.2.0",
47-
"@octokit/rest": "20.0.2",
47+
"@octokit/rest": "20.1.1",
4848
"@octokit/types": "^13.5.0",
4949
"@terraform-aws-github-runner/aws-powertools-util": "*",
5050
"@terraform-aws-github-runner/aws-ssm-util": "*",
51-
"axios": "^1.7.2",
5251
"cron-parser": "^4.9.0",
5352
"typescript": "^5.5.4"
5453
},

Diff for: lambdas/functions/control-plane/src/axios/fetch-override.test.ts

-31
This file was deleted.

Diff for: lambdas/functions/control-plane/src/axios/fetch-override.ts

-19
This file was deleted.

Diff for: lambdas/functions/control-plane/src/gh-auth/gh-auth.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ${decryptedValue}`,
9595

9696
// Assert
9797
expect(mockedCreatAppAuth).toBeCalledTimes(1);
98-
expect(mockedCreatAppAuth).toBeCalledWith({ ...authOptions, request: expect.anything() });
98+
expect(mockedCreatAppAuth).toBeCalledWith({ ...authOptions });
9999
});
100100

101101
test('Creates auth object for public GitHub', async () => {
@@ -121,7 +121,7 @@ ${decryptedValue}`,
121121
expect(getParameter).toBeCalledWith(PARAMETER_GITHUB_APP_KEY_BASE64_NAME);
122122

123123
expect(mockedCreatAppAuth).toBeCalledTimes(1);
124-
expect(mockedCreatAppAuth).toBeCalledWith({ ...authOptions, request: expect.anything() });
124+
expect(mockedCreatAppAuth).toBeCalledWith({ ...authOptions });
125125
expect(mockedAuth).toBeCalledWith({ type: authType });
126126
expect(result.token).toBe(token);
127127
});

Diff for: lambdas/functions/control-plane/src/gh-auth/gh-auth.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ import { Octokit } from '@octokit/rest';
1313
import { throttling } from '@octokit/plugin-throttling';
1414
import { createChildLogger } from '@terraform-aws-github-runner/aws-powertools-util';
1515
import { getParameter } from '@terraform-aws-github-runner/aws-ssm-util';
16-
17-
import { axiosFetch } from '../axios/fetch-override';
16+
import { EndpointDefaults } from '@octokit/types';
1817

1918
const logger = createChildLogger('gh-auth');
2019

2120
export async function createOctoClient(token: string, ghesApiUrl = ''): Promise<Octokit> {
2221
const CustomOctokit = Octokit.plugin(throttling);
2322
const ocktokitOptions: OctokitOptions = {
2423
auth: token,
25-
request: { fetch: axiosFetch },
2624
};
2725
if (ghesApiUrl) {
2826
ocktokitOptions.baseUrl = ghesApiUrl;
@@ -32,12 +30,12 @@ export async function createOctoClient(token: string, ghesApiUrl = ''): Promise<
3230
return new CustomOctokit({
3331
...ocktokitOptions,
3432
throttle: {
35-
onRateLimit: (options: { method: string; url: string }) => {
33+
onRateLimit: (retryAfter: number, options: Required<EndpointDefaults>) => {
3634
logger.warn(
3735
`GitHub rate limit: Request quota exhausted for request ${options.method} ${options.url}. Requested `,
3836
);
3937
},
40-
onSecondaryRateLimit: (options: { method: string; url: string }) => {
38+
onSecondaryRateLimit: (retryAfter: number, options: Required<EndpointDefaults>) => {
4139
logger.warn(`GitHub rate limit: SecondaryRateLimit detected for request ${options.method} ${options.url}`);
4240
},
4341
},
@@ -82,12 +80,7 @@ async function createAuth(installationId: number | undefined, ghesApiUrl: string
8280
if (ghesApiUrl) {
8381
authOptions.request = request.defaults({
8482
baseUrl: ghesApiUrl,
85-
request: {
86-
fetch: axiosFetch,
87-
},
8883
});
89-
} else {
90-
authOptions.request = request.defaults({ request: { fetch: axiosFetch } });
9184
}
9285
return createAppAuth(authOptions);
9386
}

Diff for: lambdas/functions/gh-agent-syncer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@aws-sdk/lib-storage": "^3.623.0",
4141
"@aws-sdk/types": "^3.609.0",
4242
"@middy/core": "^4.7.0",
43-
"@octokit/rest": "20.0.2",
43+
"@octokit/rest": "20.1.1",
4444
"@terraform-aws-github-runner/aws-powertools-util": "*",
4545
"axios": "^1.7.2"
4646
},

Diff for: lambdas/functions/webhook/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dependencies": {
4040
"@aws-sdk/client-sqs": "^3.623.0",
4141
"@middy/core": "^4.7.0",
42-
"@octokit/rest": "20.0.2",
42+
"@octokit/rest": "20.1.1",
4343
"@octokit/types": "^13.5.0",
4444
"@octokit/webhooks": "^12.2.0",
4545
"@terraform-aws-github-runner/aws-powertools-util": "*",

0 commit comments

Comments
 (0)