forked from pytorch-ignite/code-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnebari.js
50 lines (42 loc) · 1.37 KB
/
nebari.js
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
50
import {
pushToGitHub,
getZip_Uid,
getRootUrlWithoutTrailingSlash,
getNbCells
} from './utils'
const repoOwner = process.env.VUE_APP_GH_USER
const repo = process.env.VUE_APP_GH_REPO
// This function is the one Netlify function runs on
// https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format
exports.handler = async function (event, _) {
// event is a JSON object
const data = JSON.parse(event.body)
const template = `ignite-${data.template}`
const nebariInstanceLink = getRootUrlWithoutTrailingSlash(
data.nebariInstanceLink
)
const argparser = data.argparser
const userName = data.userName
const nbName = `${template}.ipynb`
const { zipRes, nbUid } = await getZip_Uid(data)
const title = template
.replace('ignite-', '')
.split('-')
.map((v) => v[0].toUpperCase() + v.slice(1))
.join(' ')
// get notebook cell structure
const nb = getNbCells(title, zipRes, argparser, template, (nebari = true))
// Updating UUID for nebari-test-fix
const nbUid_nebari = nbUid + '-nebari'
// Create the notebook on GitHub
await pushToGitHub(
Buffer.from(JSON.stringify(nb)).toString('base64'),
nbName,
nbUid_nebari
)
const nebariLink = `${nebariInstanceLink}/user/${userName}/lab/tree/GitHub%3A${repoOwner}/${repo}/nbs/${nbUid_nebari}/${nbName}`
return {
statusCode: 200,
body: nebariLink
}
}