Skip to content

Commit 64ace7f

Browse files
committed
feat: review: send messages to channel output
1 parent ed8e779 commit 64ace7f

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function registerOpenViewsCommands(
7171

7272
export function activate(context: ExtensionContext) {
7373
const outputChannel = window.createOutputChannel("GitGuardian");
74-
let configuration = getConfiguration(context);
74+
let configuration = getConfiguration(context, outputChannel);
7575

7676
const ggshieldResolver = new GGShieldResolver(
7777
outputChannel,

src/lib/ggshield-configuration-utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExtensionContext, workspace } from "vscode";
1+
import { ExtensionContext, OutputChannel, workspace } from "vscode";
22
import * as os from "os";
33
import { GGShieldConfiguration } from "./ggshield-configuration";
44
import { getGGShieldAbsolutePath } from "./ggshield-resolver-utils";
@@ -8,7 +8,8 @@ import { getGGShieldAbsolutePath } from "./ggshield-resolver-utils";
88
* @returns {GGShieldConfiguration} from the extension settings
99
*/
1010
export function getConfiguration(
11-
context: ExtensionContext
11+
context: ExtensionContext,
12+
outputChannel: OutputChannel
1213
): GGShieldConfiguration {
1314
const config = workspace.getConfiguration("gitguardian");
1415

@@ -19,7 +20,8 @@ export function getConfiguration(
1920
const ggshieldAbsolutePath: string = getGGShieldAbsolutePath(
2021
os.platform(),
2122
os.arch(),
22-
context
23+
context,
24+
outputChannel
2325
);
2426

2527
return new GGShieldConfiguration(

src/lib/ggshield-resolver-utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from "path";
2-
import { ExtensionContext } from "vscode";
2+
import { ExtensionContext, OutputChannel } from "vscode";
33
import * as fs from "fs";
44
import * as tar from "tar";
55
const AdmZip = require("adm-zip");
@@ -14,7 +14,8 @@ const AdmZip = require("adm-zip");
1414
export function getGGShieldAbsolutePath(
1515
platform: NodeJS.Platform,
1616
arch: string,
17-
context: ExtensionContext
17+
context: ExtensionContext,
18+
outputChannel: OutputChannel
1819
): string {
1920
const version = getGGShieldLatestVersion();
2021
console.log(`Latest GGShield version: ${version}`);
@@ -31,6 +32,9 @@ export function getGGShieldAbsolutePath(
3132

3233
// if exists, return the path
3334
if (fs.existsSync(ggshieldBinaryPath)) {
35+
outputChannel.appendLine(
36+
`Using GGShield v${version}. Checkout https://github.com/GitGuardian/ggshield for more info.`
37+
);
3438
console.log(`GGShield already exists at ${ggshieldBinaryPath}`);
3539
return ggshieldBinaryPath;
3640
}
@@ -41,6 +45,9 @@ export function getGGShieldAbsolutePath(
4145
fs.mkdirSync(ggshieldFolder);
4246
// install GGShield
4347
installGGShield(platform, arch, ggshieldFolder, version);
48+
outputChannel.appendLine(
49+
`Updated to GGShield v${version}. Checkout https://github.com/GitGuardian/ggshield for more info.`
50+
);
4451
console.log(`GGShield binary installed at ${ggshieldBinaryPath}`);
4552
return ggshieldBinaryPath;
4653
}

src/lib/ggshield-resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class GGShieldResolver {
3131
try {
3232
this.testConfiguration(this.configuration);
3333
this.channel.appendLine(
34-
`Using ggshield at: ${this.configuration.ggshieldPath}, to change this go to settings.`
34+
`Using ggshield at: ${this.configuration.ggshieldPath}.`
3535
);
3636
return;
3737
} catch (error) {

src/test/suite/lib/ggshield-configuration-utils.test.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import * as simple from "simple-mock";
22
import assert = require("assert");
3-
import { ExtensionContext, workspace } from "vscode";
3+
import { ExtensionContext, workspace, window } from "vscode";
44
import { getConfiguration } from "../../../lib/ggshield-configuration-utils";
55
import * as ggshieldResolverUtils from "../../../lib/ggshield-resolver-utils";
66

77
suite("getConfiguration", () => {
88
let getConfigurationMock: simple.Stub<Function>;
9-
let getGGShieldAbsolutePathMock: simple.Stub<(platform: NodeJS.Platform, arch: string, context: ExtensionContext) => string>;
9+
let getGGShieldAbsolutePathMock: simple.Stub<
10+
(
11+
platform: NodeJS.Platform,
12+
arch: string,
13+
context: ExtensionContext
14+
) => string
15+
>;
1016

1117
setup(() => {
1218
// Mock workspace.getConfiguration
1319
getConfigurationMock = simple.mock(workspace, "getConfiguration");
1420
// Mock getGGShieldAbsolutePath
15-
getGGShieldAbsolutePathMock = simple.mock(ggshieldResolverUtils, "getGGShieldAbsolutePath").returnWith(
16-
() => "/mock/path/to/ggshield"
17-
);
21+
getGGShieldAbsolutePathMock = simple
22+
.mock(ggshieldResolverUtils, "getGGShieldAbsolutePath")
23+
.returnWith(() => "/mock/path/to/ggshield");
1824
});
1925

2026
teardown(() => {
@@ -23,6 +29,7 @@ suite("getConfiguration", () => {
2329

2430
test("Vscode settings are correctly read", () => {
2531
const context = {} as ExtensionContext;
32+
const outputChannel = window.createOutputChannel("GitGuardian");
2633
simple.mock(context, "asAbsolutePath").returnWith("");
2734

2835
getConfigurationMock.returnWith({
@@ -35,10 +42,13 @@ suite("getConfiguration", () => {
3542
}
3643
},
3744
});
38-
const configuration = getConfiguration(context);
45+
const configuration = getConfiguration(context, outputChannel);
3946

4047
// Assert both workspace.getConfiguration and GGShieldConfiguration constructor were called
41-
assert(getConfigurationMock.called, "getConfiguration should be called once");
48+
assert(
49+
getConfigurationMock.called,
50+
"getConfiguration should be called once"
51+
);
4252

4353
// Assert that the configuration has the expected values
4454
assert.strictEqual(configuration.apiUrl, "https://custom-url.com");

0 commit comments

Comments
 (0)