Commit Graph

4072 Commits

Author SHA1 Message Date
Elena Tanasoiu
3e3eb0da0a Re-use existing database if one for the same language is already downloaded
We'd like to select an existing database for our query, if on is
already downloaded and matches the query language.

Previously we were re-using the database if the language and name
matched (e.g. the name would be `github/codeql`).
2023-04-11 16:53:00 +00:00
Elena Tanasoiu
460da1ea08 Add language to list of params 2023-04-11 15:00:00 +00:00
Elena Tanasoiu
f4a8de0f6b Don't count files that are not example<number>.ql
When we try to determine the next file name for our example query,
we only look at `example<n>.ql` files.

e.g. if the files in the folder are:
- `example.ql`
- `example2.ql`
- `MyQuery.ql`

we will create an `example3.ql` file.

Previously we were counting all existing `.ql` files.
2023-04-11 15:00:00 +00:00
Elena Tanasoiu
c7d9407a4c Rename workoutNextFileName -> determineNextFileName 2023-04-11 15:00:00 +00:00
Elena Tanasoiu
913942625c Increase timeout for skeleton wizard tests
We've now added more tests and pushed the total duration over 5 seconds
for all the tests in this file.

This limitation seems to be a recent development where files with tests
that last longer than 5 seconds start failing in jest.

We're bumping the timeout limit to 40 seconds for now.
2023-04-11 14:59:59 +00:00
Elena Tanasoiu
62bebc02bd Set storage path after the user selects language
And add tests for getFirstStoragePath method
2023-04-11 14:59:59 +00:00
Elena Tanasoiu
16a828938f Shorten logic for deciding when to ask for language
Let's only ask for the language when the language is not provided OR it's invalid.

Let's also add tests for these cases.
2023-04-11 14:59:59 +00:00
Elena Tanasoiu
59909e20b0 Convert folderName property into getter method 2023-04-11 14:59:59 +00:00
Elena Tanasoiu
b794427778 Remove unnecessary casting to DatabaseItem 2023-04-11 14:59:59 +00:00
Elena Tanasoiu
97fb4ea2ed Use Record 2023-04-11 14:59:59 +00:00
Elena Tanasoiu
911c3af225 Use a regular const instead of storing this on the class 2023-04-11 14:59:59 +00:00
Elena Tanasoiu
f949eda5ff Fix error message 2023-04-11 14:59:59 +00:00
Elena Tanasoiu
9c0deaec96 Make it clear we're checking the filename
Replaces `file[0]` with a more meaningful `filename`.
2023-04-11 14:59:58 +00:00
Elena Tanasoiu
fe3e9a713b Get rid of unnecessary ternary 2023-04-11 14:59:58 +00:00
Elena Tanasoiu
30011aaf65 Fail gracefully if we can't open the new query file 2023-04-11 14:59:58 +00:00
Elena Tanasoiu
061f347ea0 Don't obfuscate assignment when we choose language
Instead of assigning this property in a method, let's make the method
return a value and assign it more visibly.
2023-04-11 14:59:58 +00:00
Elena Tanasoiu
95ed076047 Shorten beforeEach to decrease chances of timeout 2023-04-11 14:59:58 +00:00
Elena Tanasoiu
c23b0bf6c8 Replace github/codeql with top databases for querying
We initially defined the default database to download as one from the
`github/codeql` repo as it was convenient.

However, this repo doesn't have a lot of vulnerabilities to discover.

Let's use repos that are in our MRVA top 10 list to allow users to
write more interesting queries.
2023-04-11 14:59:58 +00:00
Elena Tanasoiu
121ebc24a6 skeleton-query.ts -> skeleton-query-wizard.ts 2023-04-11 14:59:58 +00:00
Elena Tanasoiu
f212804634 Make "Create Query" command work with vscode-codeql-starter
We set up the "Create Query" command with the assumption that
the first folder in the workspace is the parent folder.

This is true for the `codespaces-codeql` repo where we expect
to use this command.

However, for the `vscode-codeql-starter` repo, the top level
folders are QL packs:
- codeql-custom-queries-cpp
- codeql-custom-queries-ruby
... etc.

In order to make the command work for people using the starter
repo, we'll need to introduce a check for these QL packs when
we decide the storage path.

The end goal is to replace the starter workspace completely
with the codespaces-codeql repo, so this code can be removed
in the future when we retire the repo.

Until then, the command will need this to be able to work in
both starter workspaces.
2023-04-11 14:59:57 +00:00
Elena Tanasoiu
b9decd8f80 Create QL pack in workspace instead of global storage
We were initially using the storage path of the extension.

We'd like to create these QL packs in the workspace instead.
2023-04-11 14:59:57 +00:00
Elena Tanasoiu
22d9487ab8 Be able to specify language when downloading github database
We offer `github/codeql` as a repo to use for downloading databases
for our skeleton pack.

Once the repo is specified, the user is prompted to choose a language.

At this point, we already know what language the user wants, so let's
change the `downloadGitHubDatabase` and `convertGithubNwoToDatabaseUrl`
methods to accept a language parameter.

We check if the language is in the list of languages received in the
response. If it isn't, we still prompt the user.
2023-04-11 14:59:57 +00:00
Elena Tanasoiu
91c4c9189f Introduce "Create Query" command 2023-04-11 14:59:57 +00:00
Elena Tanasoiu
ddd00d16b0 Introduce SkeletonWizard class
This will be triggered by a "Create Query" command.

It will:
- prompt the user for a language
- create a skeleton pack based on the language chosen
- download a database for the QL pack
- open the new query file

If the skeleton pack already exists, we just create a new query file
in the existing folder.

If the database is already downloaded, we just re-use it.
2023-04-11 14:59:57 +00:00
Elena Tanasoiu
e63f0fc0af Be able to specify the name of the skeleton query file
We introduced this QlPackGenerator a while ago. It always creates an `example.ql` query file as part of the skeleton pack.

We'd like to set the name of the query file, since we'll allow the user to create queries multiple times in the same skeleton pack folder.

The folder will be named `codeql-custom-queries-${language}` and will first receive an `example.ql` file.

If the user then tries to create a new query for the same language, we'll just create an `example2.ql`, `example3.ql` etc. file in the existing folder.
2023-04-11 14:59:57 +00:00
Elena Tanasoiu
2995b0120d Provide a way to search for database items by name and language
We'll use this to check whether a database for our ql pack already exists.

While there are other methods that search for a database item by URI, we
only have a language chosen by the user and an nwo ("github/codeql").

So let's introduce a way to search for the db based on the information we
have.
2023-04-11 14:59:57 +00:00
Elena Tanasoiu
053a1800a9 Export existing language prompt
We plan to ask the user to choose a language, before attempting
to download a corresponding database for them.

The functionality already exists, so let's re-use it.
2023-04-11 14:59:56 +00:00
Elena Tanasoiu
1a2e5d90df Extract functionality to download GitHub database
This was nested in a method that included prompting the user for a
github repo.

We'd like to re-use this to download a database of our choice from
GitHub, based on which language a user chooses.
2023-04-11 14:59:56 +00:00
Koen Vlaswinkel
957f71c9d4 Merge pull request #2293 from github/koesie10/use-data-extensions-in-editor
Use data extensions for finding external API calls
2023-04-11 16:01:26 +02:00
Koen Vlaswinkel
ae08a1b598 Use data extensions for finding external API calls
The data extension editor was only using the default data extensions
found in the `ql` submodule to find external API calls. This will add
support for using data extensions found in the workspace.

Rather than using the `codeQL.runningQueries.useExtensionPacks` setting,
this will always include data extensions since the editor doesn't make
sense to use without data extensions. We will also forbid the user from
opening this view unless they are using a CLI which supports data
extension packs.
2023-04-11 13:31:51 +02:00
Charis Kyriakou
deb2b83642 Update selected code flow when data flow paths change (#2288) 2023-04-11 11:02:03 +01:00
Koen Vlaswinkel
0115259778 Merge pull request #2271 from github/koesie10/data-extension-editor-cli-tests
Split and add tests for external API usages query
2023-04-11 11:46:29 +02:00
Koen Vlaswinkel
ccf9466fd9 Merge pull request #2260 from github/koesie10/data-extension-editor-stories
Add stories for data extension editor
2023-04-11 11:19:04 +02:00
Koen Vlaswinkel
6dfa726110 Merge remote-tracking branch 'origin/main' into koesie10/data-extension-editor-cli-tests 2023-04-11 11:13:07 +02:00
Koen Vlaswinkel
9f3baadee9 Rename getResults to readQueryResults 2023-04-11 11:10:45 +02:00
Koen Vlaswinkel
ad3a728012 Merge pull request #2267 from github/koesie10/data-extension-editor-generate-flow-model
Add generating of flow model to data extension editor
2023-04-11 11:07:30 +02:00
Koen Vlaswinkel
102976e167 Use functions instead of class for generating flow model
We were using a single-use class for generating the flow model, while we
are actually able to do it using two functions. This is more in line
with our existing codebase.
2023-04-11 10:27:46 +02:00
Koen Vlaswinkel
4e8df309fb Add comments for adding flow database 2023-04-11 10:22:10 +02:00
Nora
36f7555fdd Merge pull request #2281 from github/nora/refactor-repo-task
Repo task:  new data model and mapping
2023-04-06 18:12:19 +02:00
Nora
2cb5928cd8 Remove unnecessary directory creation that is handled by outputJson 2023-04-06 14:58:29 +00:00
Nora
2963d7eb5f Remove unnecessary return statements in repo task and repo states 2023-04-06 14:58:29 +00:00
Nora
1beddf7640 Map data types 2023-04-06 14:58:29 +00:00
Nora
f21117e5dd Extract read and write to store 2023-04-06 14:58:29 +00:00
Koen Vlaswinkel
dbc7f90c20 Throw error instead of returning undefined 2023-04-06 16:54:20 +02:00
Koen Vlaswinkel
af8e0bb454 Rename getAddsTo 2023-04-06 16:49:20 +02:00
Koen Vlaswinkel
18db74ed2d Add type check for query results 2023-04-06 16:35:04 +02:00
Koen Vlaswinkel
d5403ad926 Introduce type for modeled method with signature 2023-04-06 16:33:43 +02:00
Koen Vlaswinkel
fcc937657d Merge pull request #2280 from github/koesie10/fix-webview-disposed
Fix error when closing MRVA webview during extension activation
2023-04-06 16:33:26 +02:00
Koen Vlaswinkel
0d00e5c5b7 Remove undefined from readModeledMethod return type 2023-04-06 16:27:34 +02:00
Koen Vlaswinkel
3214a376ad Clarify definitions to be extensible predicate definitions 2023-04-06 16:24:25 +02:00