-
Notifications
You must be signed in to change notification settings - Fork 8
/
submit.ts
49 lines (43 loc) · 1.23 KB
/
submit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import ora from 'ora'
import { DIFF_MSG } from '../messages'
import { displayBoxUI } from '../util/boxen'
import { askForChallenges, askForConfirmation } from '../util/prompt'
import { DEBUG_TOKEN } from '../constants'
import { getDiffAgainstMaster } from '../util/git'
import { getCredentials } from '../util/credentials'
import { getLessons, sendSubmission } from '../util/request'
import * as Sentry from '@sentry/node'
const spinner = ora()
const submit = async ({
url,
debug,
}: {
url: string
debug: boolean
}): Promise<void> => {
try {
const cliToken = debug ? DEBUG_TOKEN : await getCredentials(url)
const lessons = await getLessons(url)
const {
lessonId,
challengeId,
lessonOrder,
challengeOrder,
} = await askForChallenges(lessons)
const diff = await getDiffAgainstMaster(lessonOrder, challengeOrder)
displayBoxUI(DIFF_MSG + diff.display)
const confirm = await askForConfirmation('The changes are correct?')
if (confirm.question) {
await sendSubmission(url, {
lessonId,
challengeId,
cliToken,
diff: diff.db,
})
}
} catch (error) {
Sentry.captureException(error)
spinner.fail(error.message)
}
}
export default submit