Skip to content

Fix/check git remote #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add git remote check
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Apr 10, 2020
commit 98932e0b975848d4d74ab7f28793794365b46e36
19 changes: 19 additions & 0 deletions src/services/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as TT from 'typings/tutorial'
import node from '../node'
import logger from '../logger'
import onError from '../sentry/onError'
Expand Down Expand Up @@ -98,6 +99,24 @@ export async function initIfNotExists(): Promise<void> {
}
}

export async function checkRemoteConnects(repo: TT.TutorialRepo): Promise<boolean | Error> {
// check for git repo
const externalRepoExists = await node.exec(`git ls-remote --exit-code --heads ${repo.uri}`)
if (externalRepoExists.stderr) {
// no repo found or no internet connection
throw new Error(externalRepoExists.stderr)
}
// check for git repo branch
const { stderr, stdout } = await node.exec(`git ls-remote --exit-code --heads ${repo.uri} ${repo.branch}`)
if (stderr) {
throw new Error(stderr)
}
if (!stdout || !stdout.length) {
throw new Error('Tutorial branch does not exist')
}
return true
}

export async function addRemote(repo: string): Promise<void> {
const { stderr } = await node.exec(`git remote add ${gitOrigin} ${repo} && git fetch ${gitOrigin}`)
if (stderr) {
Expand Down
2 changes: 2 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ export interface MachineStateSchema {
ValidateSetup: {}
NonEmptyWorkspace: {}
GitNotInstalled: {}
GitRemoteFailed: {}
SelectTutorial: {}
SetupNewTutorial: {}
StartNewTutorial: {}
}
}
Tutorial: {
Expand Down
8 changes: 6 additions & 2 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import CompletedPage from './containers/Tutorial/CompletedPage'
import LevelSummaryPage from './containers/Tutorial/LevelPage'
import SelectEmptyWorkspace from './containers/Check/SelectWorkspace'
import GitInstalled from './containers/Check/GitInstalled'
import GitRemoteFailed from './containers/Check/GitRemoteFailed'

const Routes = () => {
const { context, send, Router, Route } = useRouter()
return (
<Workspace>
<Router>
{/* Setup */}
<Route path={['Setup.Startup', 'Setup.Authenticate', 'Setup.LoadStoredTutorial', 'Setup.CheckEmptyWorkspace']}>
<Route path={['Setup.Startup', 'Setup.LoadStoredTutorial', 'Setup.ValidateSetup']}>
<LoadingPage text="Launching..." context={context} />
</Route>
<Route path="Setup.Start">
Expand All @@ -36,9 +37,12 @@ const Routes = () => {
<Route path="Setup.SelectTutorial">
<SelectTutorialPage send={send} context={context} />
</Route>
<Route path="Setup.SetupNewTutorial">
<Route path={['Setup.SetupNewTutorial', 'Setup.StartNewTutorial']}>
<LoadingPage text="Configuring tutorial..." context={context} />
</Route>
<Route path="Setup.GitRemoteFailed">
<GitRemoteFailed send={send} error={context.error} />
</Route>
{/* Tutorial */}
<Route path={['Tutorial.LoadNext', 'Tutorial.Level.Load']}>
<LoadingPage text="Loading Level..." context={context} />
Expand Down
48 changes: 48 additions & 0 deletions web-app/src/containers/Check/GitRemoteFailed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react'
import * as T from 'typings'
import { css, jsx } from '@emotion/core'
import Button from '../../components/Button'

const styles = {
container: {
padding: '1rem',
},
}

type Props = {
error: T.ErrorMessage | null
send: (action: T.Action) => void
}

const GitRemoteFailed = (props: Props) => {
const onTryAgain = () => props.send({ type: 'TRY_AGAIN' })
return (
<div css={styles.container}>
<h3>Git Remote Failed</h3>
<p>Something went wrong when connecting to the Git repo.</p>
<p>
There may be a problem with: (1) your internet, (2) your access to a private repo, or (3) the tutorial may not
have the correct repo name or branch.
</p>

{props.error && (
<div>
<p>See the following error below for help:</p>
<pre>
<code>
{props.error.title}
{props.error.description}
</code>
</pre>
</div>
)}

<br />
<Button type="secondary" onClick={onTryAgain}>
Check Again
</Button>
</div>
)
}

export default GitRemoteFailed
16 changes: 14 additions & 2 deletions web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export const createMachine = (options: any) => {
TRY_AGAIN: 'ValidateSetup',
},
},
GitRemoteFailed: {
on: {
TRY_AGAIN: 'SetupNewTutorial',
},
},
SelectTutorial: {
onEntry: ['clearStorage'],
id: 'select-new-tutorial',
Expand All @@ -96,9 +101,16 @@ export const createMachine = (options: any) => {
},
},
SetupNewTutorial: {
onEntry: ['configureNewTutorial', 'startNewTutorial'],
onEntry: ['configureNewTutorial'],
on: {
TUTORIAL_CONFIGURED: '#tutorial',
GIT_REMOTE_FAILED: 'GitRemoteFailed',
TUTORIAL_CONFIGURED: 'StartNewTutorial',
},
},
StartNewTutorial: {
onEntry: ['startNewTutorial'],
after: {
0: '#tutorial',
},
},
},
Expand Down