Refactor database-fetcher.ts into a class and simplify#3458
Refactor database-fetcher.ts into a class and simplify#3458robertbrignull merged 10 commits intomainfrom
Conversation
| await fetch(databaseUrl, { | ||
| headers: requestHeaders, | ||
| signal, | ||
| }), |
Check failure
Code scanning / CodeQL
Untrusted data passed to external API with additional heuristic sources
There was a problem hiding this comment.
I've dismissed this alert as a false positive. There's nothing wrong that I can see with the checkForFailingResponse function or anything else we do with this response.
I'm not sure why it wasn't present on the main branch already as this is just code that's been moved around.
…can make more methods private
51751a6 to
55b9b2e
Compare
|
This had some fairly complex merge conflicts and I realised a bunch of the tests were broken. Since nobody has reviewed yet I've tried to rebase and keep all the commits clean. Hopefully I got everything right while rebasing 🤞🏼 |
...ions/ql-vscode/test/vscode-tests/cli-integration/local-queries/skeleton-query-wizard.test.ts
Outdated
Show resolved
Hide resolved
extensions/ql-vscode/test/vscode-tests/no-workspace/databases/github-databases/download.test.ts
Outdated
Show resolved
Hide resolved
extensions/ql-vscode/test/vscode-tests/no-workspace/databases/github-databases/updates.test.ts
Outdated
Show resolved
Hide resolved
|
Thanks. I'll address your comments but then wait for #3433 to be merged so I can fix up the conflicts manually. That's probably easier than fixing them on that PR. |
|
I've merged in latest
I fixed the conflicts largely by manually re-applying the changes from https://github.com/github/vscode-codeql/pull/3433/files and https://github.com/github/vscode-codeql/pull/3486/files. The only change that wasn't clear how to fix was around the It's quite hard to see everything that changed during the merge so this may need another full review if you want to be certain. To help with this you can compare to 66de756...ff889b7 which is the diff before the merge. |
koesie10
left a comment
There was a problem hiding this comment.
Thanks, LGTM. I found two minor unexpected changes, but once those are fixed I think this can be merged. I didn't test it locally, but since all tests pass this should be fine.
This PR tries to make the
database-fetcher.tsfile easier to work with, and also sets up for future refactoring in this area.I highly recommend ignoring whitespace when reviewing! It has also been split into commits if you find that makes it easier.
The main change is creating the
DatabaseFetcherclass, rather than having all functions be defined at the top level and exported. My reasoning for doing this is:app(orcommandManager),databaseManager,storagePath, andcli. These are values that don't change and are needed by every method, so it makes sense to pass them in once when constructing theDatabaseFetcherobject.mockedObjectand pass that in, rather than having to know exactly which methods the code calls and spying on them. It should be a lot less brittle to code changes now, and safer because it'll fail with an error message instead of calling unexpected code.I then do a little bit of refactoring around the skeleton query wizard because I spotted an opportunity to delete a method and reuse code.
This PR is also hopefully setting up for more work in this area. Right now I haven't changed much about what is done in
database-fetcher.ts, but my next plan is to maybe separate it into two areas. The idea would be to separate the fetching of databases from a known source (i.e. URL or github NWO) and prompting for which database to import, which is currently spread betweenDatabaseFetcherandDatabaseUIandsrc/databases/github-databases/download.ts.Checklist
ready-for-doc-reviewlabel there.