Skip to content

Commit 21dda65

Browse files
Add progress messages to LGTM download option. (#960)
* Add progress messages to LGTM download option. * Add additional argument to get test passing again. * Make edits requested by @aeisenerg * Fix assertion in test case * Update extensions/ql-vscode/CHANGELOG.md
1 parent 39fdd0c commit 21dda65

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
## [UNRELEASED]
44

5-
6-
- 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)
7-
5+
- 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)
6+
- 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)
87
- Fixed a bug where copying the version information fails when a CodeQL CLI cannot be found. [#958](https://github.com/github/vscode-codeql/pull/958)
98

109
## 1.5.5 - 08 September 2021

extensions/ql-vscode/src/databaseFetcher.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export async function promptImportLgtmDatabase(
7272
progress: ProgressCallback,
7373
token: CancellationToken
7474
): Promise<DatabaseItem | undefined> {
75+
progress({
76+
message: 'Choose project',
77+
step: 1,
78+
maxStep: 2
79+
});
7580
const lgtmUrl = await window.showInputBox({
7681
prompt:
7782
'Enter the project slug or URL on LGTM (e.g., g/github/codeql or https://lgtm.com/projects/g/github/codeql)',
@@ -81,7 +86,7 @@ export async function promptImportLgtmDatabase(
8186
}
8287

8388
if (looksLikeLgtmUrl(lgtmUrl)) {
84-
const databaseUrl = await convertToDatabaseUrl(lgtmUrl);
89+
const databaseUrl = await convertToDatabaseUrl(lgtmUrl, progress);
8590
if (databaseUrl) {
8691
const item = await databaseArchiveFetcher(
8792
databaseUrl,
@@ -405,7 +410,9 @@ function convertRawLgtmSlug(maybeSlug: string): string | undefined {
405410
}
406411

407412
// exported for testing
408-
export async function convertToDatabaseUrl(lgtmUrl: string) {
413+
export async function convertToDatabaseUrl(
414+
lgtmUrl: string,
415+
progress: ProgressCallback) {
409416
try {
410417
lgtmUrl = convertRawLgtmSlug(lgtmUrl) || lgtmUrl;
411418

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

424-
const language = await promptForLanguage(projectJson);
431+
const language = await promptForLanguage(projectJson, progress);
425432
if (!language) {
426433
return;
427434
}
@@ -439,8 +446,14 @@ export async function convertToDatabaseUrl(lgtmUrl: string) {
439446
}
440447

441448
async function promptForLanguage(
442-
projectJson: any
449+
projectJson: any,
450+
progress: ProgressCallback
443451
): Promise<string | undefined> {
452+
progress({
453+
message: 'Choose language',
454+
step: 2,
455+
maxStep: 2
456+
});
444457
if (!projectJson?.languages?.length) {
445458
return;
446459
}

extensions/ql-vscode/src/vscode-tests/no-workspace/databaseFetcher.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ import {
1313
looksLikeLgtmUrl,
1414
findDirWithFile,
1515
} from '../../databaseFetcher';
16+
import { ProgressCallback } from '../../commandRunner';
1617
chai.use(chaiAsPromised);
1718
const expect = chai.expect;
1819

19-
describe('databaseFetcher', function() {
20+
describe('databaseFetcher', function () {
2021
// These tests make API calls and may need extra time to complete.
2122
this.timeout(10000);
2223

2324
describe('convertToDatabaseUrl', () => {
2425
let sandbox: sinon.SinonSandbox;
2526
let quickPickSpy: sinon.SinonStub;
27+
let progressSpy: ProgressCallback;
28+
2629
beforeEach(() => {
2730
sandbox = sinon.createSandbox();
2831
quickPickSpy = sandbox.stub(window, 'showQuickPick');
32+
progressSpy = sandbox.spy();
2933
});
3034

3135
afterEach(() => {
@@ -35,7 +39,7 @@ describe('databaseFetcher', function() {
3539
it('should convert a project url to a database url', async () => {
3640
quickPickSpy.resolves('javascript');
3741
const lgtmUrl = 'https://lgtm.com/projects/g/github/codeql';
38-
const dbUrl = await convertToDatabaseUrl(lgtmUrl);
42+
const dbUrl = await convertToDatabaseUrl(lgtmUrl, progressSpy);
3943

4044
expect(dbUrl).to.equal(
4145
'https://lgtm.com/api/v1.0/snapshots/1506465042581/javascript'
@@ -48,28 +52,31 @@ describe('databaseFetcher', function() {
4852
quickPickSpy.resolves('python');
4953
const lgtmUrl =
5054
'https://lgtm.com/projects/g/github/codeql/subpage/subpage2?query=xxx';
51-
const dbUrl = await convertToDatabaseUrl(lgtmUrl);
55+
const dbUrl = await convertToDatabaseUrl(lgtmUrl, progressSpy);
5256

5357
expect(dbUrl).to.equal(
5458
'https://lgtm.com/api/v1.0/snapshots/1506465042581/python'
5559
);
60+
expect(progressSpy).to.have.been.calledOnce;
5661
});
5762

5863
it('should convert a raw slug to a database url with extra path segments', async () => {
5964
quickPickSpy.resolves('python');
6065
const lgtmUrl =
6166
'g/github/codeql';
62-
const dbUrl = await convertToDatabaseUrl(lgtmUrl);
67+
const dbUrl = await convertToDatabaseUrl(lgtmUrl, progressSpy);
6368

6469
expect(dbUrl).to.equal(
6570
'https://lgtm.com/api/v1.0/snapshots/1506465042581/python'
6671
);
72+
expect(progressSpy).to.have.been.calledOnce;
6773
});
6874

6975
it('should fail on a nonexistent project', async () => {
7076
quickPickSpy.resolves('javascript');
7177
const lgtmUrl = 'https://lgtm.com/projects/g/github/hucairz';
72-
await expect(convertToDatabaseUrl(lgtmUrl)).to.rejectedWith(/Invalid LGTM URL/);
78+
await expect(convertToDatabaseUrl(lgtmUrl, progressSpy)).to.rejectedWith(/Invalid LGTM URL/);
79+
expect(progressSpy).to.have.callCount(0);
7380
});
7481
});
7582

0 commit comments

Comments
 (0)