Case insensitive fallback check for github repositories#961
Case insensitive fallback check for github repositories#961mgsium wants to merge 19 commits intogithub:mainfrom
Conversation
aeisenberg
left a comment
There was a problem hiding this comment.
Nice work. Some comments inline.
|
|
||
| export async function retrieveCanonicalRepoName(lgtmUrl: string) { | ||
| const givenRepoName = parseLgtmUrl(lgtmUrl); | ||
| const repo = await fetch(`https://un5my6tpgjf94hmrq01g.julianrbryant.com/repos/${givenRepoName}`).then(res => res.json()); |
There was a problem hiding this comment.
What happens if there is an error here and something besides 200 is returned? Can you take a look at checkForFailingResponse in this file? It would be best to to generalize this function to handle this case as well. You could add a new parameter that would replace the error message Error downloading database..
| } | ||
|
|
||
| function parseLgtmUrl(lgtmUrl: string): string | undefined { | ||
| const re = new RegExp('https://un5nu71xrxc0.julianrbryant.com/projects/(g|gl|b|git)/(.*)'); |
There was a problem hiding this comment.
Only project slugs that begin with a g are from github (they are the vast majority of projects on lgtm. It may not be safe to match on other slugs. Eg- if two people put up the different projects with the same project name with different capitalization on github and bitbucket, you would get a mismatch. It's a rare case, but it's probably safer to protect against it.
There was a problem hiding this comment.
Also, please add a comment that this only supports github slugs.
| throw new Error(); | ||
| } | ||
| canonicalName = convertRawLgtmSlug(`g/${canonicalName}`); | ||
| projectJson = await pullLgtmProject(canonicalName); |
There was a problem hiding this comment.
You should check again if projectJson.code === 404.
| return; | ||
| } | ||
|
|
||
| function parseLgtmUrl(lgtmUrl: string): string | undefined { |
There was a problem hiding this comment.
This name is misleading. This function does not parse a url. It really just extracts the project slug. Could you rename it to something like: extractProjectSlug
| // fallback check for github repos with same name but different case | ||
| let canonicalName = await retrieveCanonicalRepoName(lgtmUrl); | ||
| if (!canonicalName) { | ||
| throw new Error(); |
There was a problem hiding this comment.
Include an error message here.
| canonicalName = convertRawLgtmSlug(`g/${canonicalName}`); | ||
| projectJson = await downloadLgtmProjectMetadata(canonicalName); | ||
| if (projectJson.code === 404) { | ||
| throw new Error(); |
aeisenberg
left a comment
There was a problem hiding this comment.
Tried this out locally and found a handful of more issues.
|
|
||
| function parseLgtmUrl(lgtmUrl: string): string | undefined { | ||
| // Only matches the '/g/' provider (github) | ||
| const re = new RegExp('https://un5nu71xrxc0.julianrbryant.com/projects/g/(.*)'); |
There was a problem hiding this comment.
This also needs to handle the case when there is a trailing /. You can either change the regex so that it will ignore capturing the / or add a check after and remove it.
aeisenberg
left a comment
There was a problem hiding this comment.
Looks good. Just some smaller suggestions.
| let resolved; | ||
| try { | ||
| resolved = await cliServer.resolveQlref(selectedQuery.path.replace(/^\/([a-zA-Z]:)/, '$1')); | ||
| } catch { | ||
| throw new Error('Referenced .ql file could not be found.'); | ||
| } |
There was a problem hiding this comment.
Is this part of the same PR?
There was a problem hiding this comment.
No, this is related to #970, I must have mixed up the commits for these.
| ## 1.5.6 - 07 October 2021 | ||
|
|
||
| - Add progress messages to LGTM download option. This makes the two-step process (selecting a project, then selecting a language) more clear. [#960](https://github.com/github/vscode-codeql/pull/960) | ||
| - Remove line about selecting a language from the dropdown when downloading database from LGTM. This makes the download progress visible when the popup is not expanded. [#957](https://github.com/github/vscode-codeql/pull/957) |
There was a problem hiding this comment.
I don't think this should have been deleted.
| throw new Error('Referenced .ql file could not be found.'); | ||
| } | ||
| const uri = Uri.file(resolved.resolvedPath); | ||
| // Something wrong with the uri |
There was a problem hiding this comment.
I think this comment can be removed.
| const uri = Uri.parse(lgtmUrl, true); | ||
| const paths = ['api', 'v1.0'].concat( | ||
| uri.path.split('/').filter((segment) => segment) | ||
| ).slice(0, 6); |
There was a problem hiding this comment.
Why 0, 6? Could you add a comment to explain?
| // fallback check for github repos with same name but different case | ||
| let canonicalName = await retrieveCanonicalRepoName(lgtmUrl); | ||
| if (!canonicalName) { | ||
| throw new Error('Repository not found.'); |
There was a problem hiding this comment.
Include the lgtmUrl in the error message.
|
|
||
| if (projectJson.code === 404) { | ||
| throw new Error(); | ||
| // fallback check for github repos with same name but different case |
There was a problem hiding this comment.
Also mention that this will fail for all non-github providers.
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
|
Unrelated changes in the PR; reopening to clean up. |
Made suggested changes; comments can be found at github#961
Implements a case-insensitive fallback check for the
/g/provider where a repository is not found on LGTM using a case-sensitive search. Partially fixes #892Checklist