Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [UNRELEASED]

- 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. [#894](https://github.com/github/vscode-codeql/issues/894)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this duplicated line.

- Add progress messages to LGTM download option. This makes the two-step process (selecting a project, then selecting a language) more clear.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there is an extra newline here.

- 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. [#894](https://github.com/github/vscode-codeql/issues/894)

Expand Down
21 changes: 17 additions & 4 deletions extensions/ql-vscode/src/databaseFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export async function promptImportLgtmDatabase(
progress: ProgressCallback,
token: CancellationToken
): Promise<DatabaseItem | undefined> {
progress({
message: 'Choose project',
step: 1,
maxStep: 2
});
const lgtmUrl = await window.showInputBox({
prompt:
'Enter the project slug or URL on LGTM (e.g., g/github/codeql or https://lgtm.com/projects/g/github/codeql)',
Expand All @@ -81,7 +86,7 @@ export async function promptImportLgtmDatabase(
}

if (looksLikeLgtmUrl(lgtmUrl)) {
const databaseUrl = await convertToDatabaseUrl(lgtmUrl);
const databaseUrl = await convertToDatabaseUrl(lgtmUrl, progress);
if (databaseUrl) {
const item = await databaseArchiveFetcher(
databaseUrl,
Expand Down Expand Up @@ -405,7 +410,9 @@ function convertRawLgtmSlug(maybeSlug: string): string | undefined {
}

// exported for testing
export async function convertToDatabaseUrl(lgtmUrl: string) {
export async function convertToDatabaseUrl(
lgtmUrl: string,
progress: ProgressCallback) {
try {
lgtmUrl = convertRawLgtmSlug(lgtmUrl) || lgtmUrl;

Expand All @@ -421,7 +428,7 @@ export async function convertToDatabaseUrl(lgtmUrl: string) {
throw new Error();
}

const language = await promptForLanguage(projectJson);
const language = await promptForLanguage(projectJson, progress);
if (!language) {
return;
}
Expand All @@ -439,8 +446,14 @@ export async function convertToDatabaseUrl(lgtmUrl: string) {
}

async function promptForLanguage(
projectJson: any
projectJson: any,
progress: ProgressCallback
): Promise<string | undefined> {
progress({
message: 'Choose language',
step: 2,
maxStep: 2
});
if (!projectJson?.languages?.length) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
looksLikeLgtmUrl,
findDirWithFile,
} from '../../databaseFetcher';
import { ProgressUpdate } from '../../commandRunner';
chai.use(chaiAsPromised);
const expect = chai.expect;

describe('databaseFetcher', function() {
describe('databaseFetcher', function () {
// These tests make API calls and may need extra time to complete.
const fakeProgress = (_: ProgressUpdate) => { /*do nothing*/ };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be converted into a test spy and you can later verify that this spy is invoked. This would ensure that the progress update is properly called.

eg-

let progressSpy: sinon.SinonStub<ProgressCallback>;

// and then in the before block:
progressSpy = sandbox.spy();

// and then in each test, after the call to convert databasea
expect(progressSpy).to.have.been.calledOnce;

this.timeout(10000);

describe('convertToDatabaseUrl', () => {
Expand All @@ -35,7 +37,7 @@ describe('databaseFetcher', function() {
it('should convert a project url to a database url', async () => {
quickPickSpy.resolves('javascript');
const lgtmUrl = 'https://lgtm.com/projects/g/github/codeql';
const dbUrl = await convertToDatabaseUrl(lgtmUrl);
const dbUrl = await convertToDatabaseUrl(lgtmUrl, fakeProgress);

expect(dbUrl).to.equal(
'https://lgtm.com/api/v1.0/snapshots/1506465042581/javascript'
Expand All @@ -48,7 +50,7 @@ describe('databaseFetcher', function() {
quickPickSpy.resolves('python');
const lgtmUrl =
'https://lgtm.com/projects/g/github/codeql/subpage/subpage2?query=xxx';
const dbUrl = await convertToDatabaseUrl(lgtmUrl);
const dbUrl = await convertToDatabaseUrl(lgtmUrl, fakeProgress);

expect(dbUrl).to.equal(
'https://lgtm.com/api/v1.0/snapshots/1506465042581/python'
Expand All @@ -59,7 +61,7 @@ describe('databaseFetcher', function() {
quickPickSpy.resolves('python');
const lgtmUrl =
'g/github/codeql';
const dbUrl = await convertToDatabaseUrl(lgtmUrl);
const dbUrl = await convertToDatabaseUrl(lgtmUrl, fakeProgress);

expect(dbUrl).to.equal(
'https://lgtm.com/api/v1.0/snapshots/1506465042581/python'
Expand All @@ -69,7 +71,7 @@ describe('databaseFetcher', function() {
it('should fail on a nonexistent project', async () => {
quickPickSpy.resolves('javascript');
const lgtmUrl = 'https://lgtm.com/projects/g/github/hucairz';
await expect(convertToDatabaseUrl(lgtmUrl)).to.rejectedWith(/Invalid LGTM URL/);
await expect(convertToDatabaseUrl(lgtmUrl, fakeProgress)).to.rejectedWith(/Invalid LGTM URL/);
});
});

Expand Down