From e9e885c96eef48658c8459579b383778d4f751b0 Mon Sep 17 00:00:00 2001 From: Raoul Schaffranek Date: Mon, 9 Dec 2024 16:06:33 +0100 Subject: [PATCH] WIP: GitHub Authentication --- package.json | 13 +++++++++++++ src/startDebugging.ts | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fa1b6ea..7e2a8f5 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,13 @@ "main": "./build/extension.js", "browser": "./build/extension.web.js", "contributes": { + "menus": { + "editor/title": [ + { + "command": "simbolik.debug" + } + ] + }, "languages": [ { "id": "solidity", @@ -204,6 +211,12 @@ } } } + ], + "commands": [ + { + "command": "simbolik.debug", + "title": "Debug" + } ] }, "scripts": { diff --git a/src/startDebugging.ts b/src/startDebugging.ts index 1ffd093..09f9800 100644 --- a/src/startDebugging.ts +++ b/src/startDebugging.ts @@ -16,6 +16,37 @@ export async function startDebugging( location: vscode.ProgressLocation.Notification, title: "Simbolik" }, async (progress) => { + + let email; + try { + const session = await vscode.authentication.getSession('github', ['user:email']) + if (!session) { throw new Error('Failed to login'); } + + const response = await fetch('https://api.github.com/user/emails', { + headers: { + 'Accept': 'application/vnd.github+json', + 'Authorization': `Bearer ${session.accessToken}`, + 'X-GitHub-Api-Version': '2022-11-28' + } + }); + + if (!response.ok) { + throw new Error('Failed to fetch public emails'); + } + + const emails = await response.json(); + if (!Array.isArray(emails)) { + throw new Error('Unexpected response from GitHub'); + } + + email = emails.filter(entry => entry.primary)[0].email; + // + // + } catch (e) { + vscode.window.showErrorMessage('Please sign in to GitHub'); + return; + } + const activeTextEditor = vscode.window.activeTextEditor; if (!activeTextEditor) { throw new Error('No active text editor.'); @@ -87,7 +118,7 @@ export async function startDebugging( ); console.log(myDebugConfig); progress.report({message: "Launching testnet"}); - const session = await vscode.debug.startDebugging( + const debugSession = await vscode.debug.startDebugging( workspaceFolder, myDebugConfig );