Skip to content

Commit cf98e9b

Browse files
Copilotsetchy
andauthored
refactor(api): migrate from custom axios rest/graphql client to official octokit sdk (#2153)
* Initial plan * Changes before error encountered Co-authored-by: setchy <386277+setchy@users.noreply.github.com> * Changes before error encountered Co-authored-by: setchy <386277+setchy@users.noreply.github.com> * wip Signed-off-by: Adam Setch <adam.setch@outlook.com> * Revert previous changes to start fresh migration to Octokit Co-authored-by: setchy <386277+setchy@users.noreply.github.com> * Migrate from axios to @octokit for GitHub API requests - Install @octokit/core, @octokit/plugin-paginate-rest, @octokit/plugin-rest-endpoint-methods - Create Octokit client utility with GitHub.com and Enterprise Server support - Migrate REST requests to use Octokit instead of axios - Migrate GraphQL requests to use Octokit's graphql method - Update Jest configuration for Octokit ES modules - Update request.test.ts and client.test.ts to work with Octokit - Remove axios dependency from test-utils - Fix all linting issues - Most tests passing (98 suites), nock-based tests need mocking adjustments * Address code review feedback - Remove redundant header generation (Octokit handles auth) - Fix GraphQL response headers not being overwritten - Use property shorthand in octokit.ts - Update test expectations for removed headers parameter * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: use octokit client Signed-off-by: Adam Setch <adam.setch@outlook.com> * remove axios test helper Signed-off-by: Adam Setch <adam.setch@outlook.com> * remove axios references Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor esm packages Signed-off-by: Adam Setch <adam.setch@outlook.com> * introduce client builder and caches for rest and graphql Signed-off-by: Adam Setch <adam.setch@outlook.com> * restore header for ghes version Signed-off-by: Adam Setch <adam.setch@outlook.com> * introduce client builder and caches for rest and graphql Signed-off-by: Adam Setch <adam.setch@outlook.com> * improve graphql error handling Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor graphql response shapes Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix tests Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix test Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix test Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix test Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix test Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix test Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix tests and remove nock Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix authentication - skip client cache Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix authentication - skip client cache Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix authentication - skip client cache Signed-off-by: Adam Setch <adam.setch@outlook.com> * update gen Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix lint Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix lint Signed-off-by: Adam Setch <adam.setch@outlook.com> * add retry plugin Signed-off-by: Adam Setch <adam.setch@outlook.com> * add never return type Signed-off-by: Adam Setch <adam.setch@outlook.com> * update error handler Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix lockfile Signed-off-by: Adam Setch <adam.setch@outlook.com> * improve coverage Signed-off-by: Adam Setch <adam.setch@outlook.com> * improve coverage Signed-off-by: Adam Setch <adam.setch@outlook.com> --------- Signed-off-by: Adam Setch <adam.setch@outlook.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: setchy <386277+setchy@users.noreply.github.com> Co-authored-by: Adam Setch <adam.setch@outlook.com>
1 parent a57941f commit cf98e9b

46 files changed

Lines changed: 1601 additions & 1592 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ This project focuses on GitHub notification monitoring, not being a full GitHub
153153
## Technology Stack Reference
154154

155155
**Core Technologies:**
156-
- **Electron 37+**: Desktop app framework
156+
- **Electron 40+**: Desktop app framework
157157
- **React 19+**: UI library
158158
- **TypeScript 5+**: Language
159159
- **pnpm 10+**: Package manager
@@ -166,7 +166,8 @@ This project focuses on GitHub notification monitoring, not being a full GitHub
166166
- **menubar**: System tray integration
167167
- **electron-updater**: Auto-update functionality
168168
- **@primer/react**: GitHub's React component library
169+
- **octokit**: HTTP client for GitHub API
170+
- **@primer/octicons-react**: GitHub icon library
169171
- **date-fns**: Date utilities
170-
- **axios**: HTTP client for GitHub API
171172

172173
ALWAYS reference this information first before exploring the codebase or running commands to save time and avoid common pitfalls.

biome.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
":BLANK_LINE:",
1919
"@primer/**",
2020
":BLANK_LINE:",
21+
"@octokit/**",
22+
":BLANK_LINE:",
2123
":PACKAGE:",
2224
":BLANK_LINE:",
2325
["**/__mocks__/**", "**/__helpers__/**"],

jest.config.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
import type { Config } from 'jest';
22

3+
const esmPackages = [
4+
'@github/relative-time-element',
5+
'@github/tab-container-element',
6+
'@lit-labs/react',
7+
'@octokit/app',
8+
'@octokit/core',
9+
'@octokit/endpoint',
10+
'@octokit/oauth-authorization-url',
11+
'@octokit/oauth-methods',
12+
'@octokit/graphql',
13+
'@octokit/plugin-paginate-graphql',
14+
'@octokit/plugin-paginate-rest',
15+
'@octokit/plugin-retry',
16+
'@octokit/plugin-rest-endpoint-methods',
17+
'@octokit/plugin-throttling',
18+
'@octokit/request',
19+
'@octokit/request-error',
20+
'@primer/octicons-react',
21+
'@primer/primitives',
22+
'@primer/react',
23+
'lit',
24+
'universal-user-agent',
25+
];
26+
27+
const escapeForRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
28+
29+
const transformIgnorePattern = `node_modules/(?!(?:${esmPackages.map(escapeForRegExp).join('|')})/)`;
30+
331
const config: Config = {
432
preset: 'ts-jest',
533
globalSetup: '<rootDir>/src/renderer/__helpers__/jest.setup.env.ts',
@@ -13,17 +41,9 @@ const config: Config = {
1341
'^.+\\.(js|mjs)$': 'babel-jest',
1442
},
1543
// Allow transforming specific ESM packages in node_modules that ship untranspiled ESM.
16-
// @primer/* libraries rely on lit and @lit-labs/react internally for some components.
17-
// @octokit/* libraries rely on universal-user-agent internally.
18-
// We also include GitHub web components that ship ESM-only builds.
19-
transformIgnorePatterns: [
20-
'node_modules/(?!(?:@primer/react|@primer/primitives|@primer/octicons-react|@lit-labs/react|lit|@github/relative-time-element|@github/tab-container-element|@octokit/oauth-methods|@octokit/oauth-authorization-url|@octokit/request|@octokit/request-error|@octokit/endpoint|universal-user-agent)/)',
21-
],
44+
// Packages are listed above in `esmPackages` for easier maintenance.
45+
transformIgnorePatterns: [transformIgnorePattern],
2246
moduleNameMapper: {
23-
// Force CommonJS build for http adapter to be available.
24-
// via https://github.com/axios/axios/issues/5101#issuecomment-1276572468
25-
'^axios$': require.resolve('axios'),
26-
2747
// GitHub Primer Design System - CSS in JS
2848
'\\.css$': 'identity-obj-proxy',
2949
},

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@
8787
"@electron/notarize": "3.1.1",
8888
"@graphql-codegen/cli": "6.1.1",
8989
"@graphql-codegen/schema-ast": "5.0.0",
90+
"@octokit/core": "7.0.6",
91+
"@octokit/graphql": "9.0.3",
9092
"@octokit/oauth-methods": "6.0.2",
91-
"@octokit/openapi-types": "27.0.0",
92-
"@octokit/request": "10.0.7",
93+
"@octokit/plugin-paginate-rest": "14.0.0",
94+
"@octokit/plugin-rest-endpoint-methods": "17.0.0",
95+
"@octokit/plugin-retry": "8.0.3",
96+
"@octokit/request-error": "^7.1.0",
9397
"@octokit/types": "16.0.0",
9498
"@parcel/watcher": "2.5.4",
9599
"@primer/css": "22.1.0",
96100
"@primer/octicons-react": "19.21.2",
97-
"@primer/primitives": "11.3.2",
98101
"@primer/react": "38.7.1",
99102
"@tailwindcss/postcss": "4.1.18",
100103
"@testing-library/jest-dom": "6.9.1",
@@ -106,7 +109,6 @@
106109
"@types/react-dom": "19.2.3",
107110
"@types/react-router-dom": "5.3.3",
108111
"@types/semver": "7.7.1",
109-
"axios": "1.13.2",
110112
"babel-jest": "30.2.0",
111113
"clsx": "2.1.1",
112114
"concurrently": "9.2.1",
@@ -125,7 +127,6 @@
125127
"jest": "30.2.0",
126128
"jest-environment-jsdom": "30.2.0",
127129
"mini-css-extract-plugin": "2.10.0",
128-
"nock": "13.5.6",
129130
"postcss": "8.5.6",
130131
"postcss-loader": "8.2.0",
131132
"rimraf": "6.1.2",

0 commit comments

Comments
 (0)