diff --git a/package.json b/package.json
index 73f888a..d16f258 100644
--- a/package.json
+++ b/package.json
@@ -147,6 +147,7 @@
"@octokit/rest": "^18.5.2",
"@radix-ui/react-dropdown-menu": "^0.0.17",
"@types/isomorphic-fetch": "^0.0.35",
+ "@vscode/webview-ui-toolkit": "^0.9.0",
"classcat": "^5.0.3",
"cronstrue": "^1.110.0",
"downshift": "^6.1.2",
diff --git a/src/extension.ts b/src/extension.ts
index 08935d8..d845931 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -9,22 +9,24 @@ export async function activate(context: vscode.ExtensionContext) {
const editor = FlatConfigEditor.register(context)
context.subscriptions.push(editor)
- const showEditor = ({ isPreview = false, onSide = false }) => () => {
- const workspaceRootUri = vscode.workspace.workspaceFolders?.[0].uri
- if (!workspaceRootUri) return
- const flatFileUri = vscode.Uri.joinPath(
- workspaceRootUri,
- '.github/workflows',
- 'flat.yml'
- )
+ const showEditor =
+ ({ isPreview = false, onSide = false }) =>
+ () => {
+ const workspaceRootUri = vscode.workspace.workspaceFolders?.[0].uri
+ if (!workspaceRootUri) return
+ const flatFileUri = vscode.Uri.joinPath(
+ workspaceRootUri,
+ '.github/workflows',
+ 'flat.yml'
+ )
- vscode.commands.executeCommand(
- 'vscode.openWith',
- flatFileUri,
- isPreview ? 'flat.config' : 'default',
- onSide ? { viewColumn: vscode.ViewColumn.Beside, preview: false } : {}
- )
- }
+ vscode.commands.executeCommand(
+ 'vscode.openWith',
+ flatFileUri,
+ isPreview ? 'flat.config' : 'default',
+ onSide ? { viewColumn: vscode.ViewColumn.Beside, preview: false } : {}
+ )
+ }
context.subscriptions.push(
vscode.commands.registerCommand(
@@ -65,9 +67,6 @@ export async function activate(context: vscode.ExtensionContext) {
const flatYmlPath = path.join(workflowsDir, 'flat.yml')
if (fs.existsSync(flatYmlPath)) {
- vscode.window.showInformationMessage(
- 'flat.yml already exists! Opening it for you...'
- )
showEditor({ isPreview: true })()
return
}
diff --git a/src/flatConfigEditor.ts b/src/flatConfigEditor.ts
index 036294c..a85d5bd 100644
--- a/src/flatConfigEditor.ts
+++ b/src/flatConfigEditor.ts
@@ -74,9 +74,20 @@ export class FlatConfigEditor implements vscode.CustomTextEditorProvider {
enableScripts: true,
}
- webviewPanel.webview.html = await this.getHtmlForWebview(
- webviewPanel.webview
- )
+ try {
+ webviewPanel.webview.html = await this.getHtmlForWebview(
+ webviewPanel.webview
+ )
+ } catch (e) {
+ await vscode.window.showErrorMessage(
+ "Please make sure you're in a repository with a valid upstream GitHub remote"
+ )
+ await vscode.commands.executeCommand(
+ 'workbench.action.revertAndCloseActiveEditor'
+ )
+ // For whatever reason, this doesn't close the webview.
+ await webviewPanel.dispose()
+ }
// Receive message from the webview.
webviewPanel.webview.onDidReceiveMessage(async e => {
@@ -101,6 +112,11 @@ export class FlatConfigEditor implements vscode.CustomTextEditorProvider {
case 'getUrlContents':
this.loadUrlContents(webviewPanel, e.data)
break
+ case 'refreshGitDetails':
+ webviewPanel.webview.html = await this.getHtmlForWebview(
+ webviewPanel.webview
+ )
+ break
case 'previewFile':
const workspaceRootUri = vscode.workspace.workspaceFolders?.[0].uri
if (!workspaceRootUri) {
@@ -168,7 +184,27 @@ export class FlatConfigEditor implements vscode.CustomTextEditorProvider {
workspaceRootUri.path.lastIndexOf('/') + 1
)
- const { owner, name } = await this.getRepoDetails()
+ let name,
+ owner = ''
+
+ try {
+ const details = await vscode.window.withProgress(
+ {
+ location: vscode.ProgressLocation.Notification,
+ },
+ async progress => {
+ progress.report({
+ message: `Checking for GitHub repository in directory: ${dirName}`,
+ })
+
+ return await this.getRepoDetails()
+ }
+ )
+ owner = details.owner || ''
+ name = details.name
+ } catch (e) {
+ console.error('Error getting GitHub repository details', e)
+ }
const gitRepo = owner && name ? `${owner}/${name}` : ''
@@ -399,14 +435,14 @@ export class FlatConfigEditor implements vscode.CustomTextEditorProvider {
try {
const gitClient = new VSCodeGit()
await gitClient.activateExtension()
- await gitClient.waitForRepo(5)
+ await gitClient.waitForRepo(3)
// Next, let's grab the repo name.
const { name, owner } = gitClient.repoDetails
resolve({ name, owner })
} catch (e) {
- resolve({})
+ reject('Couldnt activate git')
}
})
}
diff --git a/src/git.ts b/src/git.ts
index 9553fdd..c59c88c 100644
--- a/src/git.ts
+++ b/src/git.ts
@@ -31,10 +31,9 @@ export class VSCodeGit {
waitForRepo(times: number): Promise<{ name: string; owner: string }> {
let count = 0
- const timeToStop = count === times
return new Promise((resolve, reject) => {
- const checkRepoExists = setInterval(() => {
+ let interval = setInterval(() => {
try {
const remotes = this.repository._repository.remotes
if (remotes.length > 0) {
@@ -42,15 +41,14 @@ export class VSCodeGit {
const parsed = GitUrlParse(remote.pushUrl)
resolve({ name: parsed.name, owner: parsed.owner })
} else {
- if (timeToStop) {
+ if (count === times) {
+ clearInterval(interval)
reject(new Error("Couldn't get repo details"))
}
count++
}
} catch (e) {
reject(new Error("Couldn't get repo details"))
- } finally {
- clearInterval(checkRepoExists)
}
}, 1000)
})
diff --git a/src/webviews/src/App.tsx b/src/webviews/src/App.tsx
index 9922919..7969e72 100644
--- a/src/webviews/src/App.tsx
+++ b/src/webviews/src/App.tsx
@@ -7,12 +7,17 @@ import Triggers from './Triggers'
import { flatStateValidationSchema } from './validation'
import { VSCodeAPI } from './VSCodeAPI'
import { FlatStep, PullSqlConfig } from '../../types'
+import { ErrorState } from './error-state'
interface AppProps {}
function App({}: AppProps) {
const { state, setErrors, isStubData, gitRepo } = useFlatConfigStore()
+ if (!gitRepo) {
+ return
+ Please ensure you're working out of a Git repository with a valid + upstream remote set. +
+