Skip to content

Commit 5b97f11

Browse files
use uri
1 parent 2e40465 commit 5b97f11

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

editor/src/ctx.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as net from 'net';
1616
import { Logger } from "./logger";
1717
import { existsSync, readdirSync, rmdirSync, rm } from "fs";
1818
import * as path from "path";
19-
import { FetchResult, PackageManager } from "@4dsas/package-manager";
19+
import { FetchOptions, FetchResult, PackageManager } from "@4dsas/package-manager";
2020

2121
export type CommandCallback = {
2222
call: (ctx: Ctx) => Commands.Cmd;
@@ -229,21 +229,41 @@ export class Ctx {
229229
clientOptions
230230
);
231231
this._client.onNotification(ext.notif_needFetchNotification, async (params) => {
232-
const packageManager = new PackageManager(params.uri);
233-
packageManager.initialize();
234-
packageManager.fetch().then(()=> {
232+
233+
const GITHUB_AUTH_PROVIDER_ID = 'github';
234+
// The GitHub Authentication Provider accepts the scopes described here:
235+
// https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
236+
//repo: Full control of private repositories
237+
//public_repo: Access public repositories
238+
const SCOPES = ['repo', 'public_repo'];
239+
240+
241+
const parsed = vscode.Uri.parse(params.uri).fsPath;
242+
const packageFolder = path.dirname(path.dirname(parsed));
243+
244+
const packageManager = new PackageManager(packageFolder);
245+
await packageManager.initialize();
246+
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: false });
247+
if(!session){
248+
//Error message user interface
249+
vscode.window.showErrorMessage("GitHub authentication is required to fetch 4D components. Please sign in to GitHub.");
250+
return;
251+
}
252+
let options: FetchOptions = {};
253+
options.githubToken = session.accessToken;
254+
packageManager.fetch(options).then(() => {
235255
this._client.sendNotification(ext.notif_installComponents, params);
236256
});
237-
return true;
257+
return true;
238258
});
239259

240260
this._client.onNotification(ext.notif_installComponents_before, async (params) => {
241261
this._client.sendNotification(ext.notif_installComponents, params);
242-
return true;
262+
return true;
243263
});
244264

245265
this._client.onNotification(ext.notif_installComponents_progress, async (params) => {
246-
return true;
266+
return true;
247267
});
248268
this._client.start();
249269
}

0 commit comments

Comments
 (0)