aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/routes/github.js6
-rw-r--r--api/services/github/files.js7
-rw-r--r--application/components/app.vue41
-rw-r--r--application/components/github-picker.vue2
-rw-r--r--application/components/initialize.vue49
-rw-r--r--application/components/keyboard-picker.vue4
-rw-r--r--application/github.js6
7 files changed, 33 insertions, 82 deletions
diff --git a/api/routes/github.js b/api/routes/github.js
index 78459db..529af4a 100644
--- a/api/routes/github.js
+++ b/api/routes/github.js
@@ -116,11 +116,11 @@ const getKeyboardFiles = async (req, res, next) => {
}
const updateKeyboardFiles = async (req, res, next) => {
- const { installationId, repository } = req.params
+ const { installationId, repository, branch } = req.params
const { keymap, layout } = req.body
try {
- await commitChanges(installationId, repository, layout, keymap)
+ await commitChanges(installationId, repository, branch, layout, keymap)
} catch (err) {
return next(err)
}
@@ -136,7 +136,7 @@ router.get('/authorize', authorize)
router.get('/installation/:installationId/:repository/branches', authenticate, getBranches)
router.get('/installation', authenticate, getInstallation)
router.get('/keyboard-files/:installationId/:repository', authenticate, getKeyboardFiles)
-router.post('/keyboard-files/:installationId/:repository', authenticate, updateKeyboardFiles)
+router.post('/keyboard-files/:installationId/:repository/:branch', authenticate, updateKeyboardFiles)
router.post('/webhook', receiveWebhook)
router.use(handleError)
diff --git a/api/services/github/files.js b/api/services/github/files.js
index 5d4b454..ddfecf8 100644
--- a/api/services/github/files.js
+++ b/api/services/github/files.js
@@ -35,7 +35,7 @@ function fetchFile (installationToken, repository, path, options = {}) {
return api.request({ url, headers, params, token: installationToken })
}
-async function commitChanges (installationId, repository, layout, keymap) {
+async function commitChanges (installationId, repository, branch, layout, keymap) {
const { data: { token: installationToken } } = await auth.createInstallationToken(installationId)
const generatedKeymap = zmk.generateKeymap(layout, keymap)
@@ -45,8 +45,7 @@ async function commitChanges (installationId, repository, layout, keymap) {
const { data: directory } = await fetchFile(installationToken, repository, 'config/')
const originalCodeKeymap = directory.find(file => file.name.toLowerCase().endsWith('.keymap'))
- const { data: repo } = await api.request({ url: `/repos/${repository}`, token: installationToken })
- const { data: [{sha, commit}] } = await api.request({ url: `/repos/${repository}/commits?per_page=1`, token: installationToken })
+ const { data: {sha, commit} } = await api.request({ url: `/repos/${repository}/commits/${branch}`, token: installationToken })
const { data: { sha: newTreeSha } } = await api.request({
url: `/repos/${repository}/git/trees`,
@@ -83,7 +82,7 @@ async function commitChanges (installationId, repository, layout, keymap) {
})
await api.request({
- url: `/repos/${repository}/git/refs/heads/${repo.default_branch}`,
+ url: `/repos/${repository}/git/refs/heads/${branch}`,
method: 'PATCH',
token: installationToken,
data: {
diff --git a/application/components/app.vue b/application/components/app.vue
index 98b6437..e890835 100644
--- a/application/components/app.vue
+++ b/application/components/app.vue
@@ -2,8 +2,7 @@
import Initialize from './initialize.vue'
import Keymap from './keymap.vue'
-import TooManyRepos from './messages/too-many-repos.vue'
-import InvalidRepo from './messages/invalid-repo.vue'
+import KeyboardPicker from './keyboard-picker.vue'
import * as config from '../config'
import * as github from '../github'
@@ -11,13 +10,16 @@ import * as github from '../github'
export default {
components: {
keymap: Keymap,
- Initialize,
- TooManyRepos,
- InvalidRepo
+ KeyboardPicker,
+ Initialize
},
data() {
return {
config,
+ source: null,
+ sourceOther: null,
+ layout: [],
+ keymap: {},
editingKeymap: {},
terminalOpen: false,
socket: null
@@ -29,6 +31,12 @@ export default {
}
},
methods: {
+ handleKeyboardSelected({ source, layout, keymap, ...other }) {
+ this.source = source
+ this.sourceOther = other
+ this.layout.splice(0, this.layout.length, ...layout)
+ Object.assign(this.keymap, keymap)
+ },
handleUpdateKeymap(keymap) {
Object.assign(this.editingKeymap, keymap)
},
@@ -36,7 +44,8 @@ export default {
github.beginLoginFlow()
},
handleCommitChanges() {
- github.commitChanges(this.layout, this.editingKeymap)
+ const { repository, branch } = this.sourceOther.github
+ github.commitChanges(repository, branch, this.layout, this.editingKeymap)
},
handleCompile() {
fetch('/keymap', {
@@ -52,12 +61,10 @@ export default {
</script>
<template>
- <initialize v-slot="{ keymap, layout, tooManyRepos, loadKeyboardError }">
- <TooManyRepos v-if="tooManyRepos" />
-
- <InvalidRepo v-else-if="loadKeyboardError === 'InvalidRepoError'" />
+ <initialize>
+ <keyboard-picker @select="handleKeyboardSelected" />
- <template v-else>
+ <template v-if="keymap.keyboard">
<keymap
:layout="layout"
:keymap="editingKeymap.keyboard ? editingKeymap : keymap"
@@ -65,7 +72,7 @@ export default {
/>
<div id="actions">
<button
- v-if="config.enableLocal"
+ v-if="source === 'local'"
v-text="`Save Local`"
id="compile"
:disabled="!this.editingKeymap.keyboard"
@@ -73,15 +80,7 @@ export default {
/>
<button
- v-if="config.enableGitHub && !githubAuthorized"
- v-text="`Authorize GitHub`"
- @click="handleGithubAuthorize"
- title="Install as a GitHub app to edit a zmk-config repository."
-
- />
-
- <button
- v-if="config.enableGitHub && githubAuthorized"
+ v-if="source === 'github'"
v-text="`Commit Changes`"
@click="handleCommitChanges"
:disabled="!this.editingKeymap.keyboard"
diff --git a/application/components/github-picker.vue b/application/components/github-picker.vue
index 3a4384b..259b35e 100644
--- a/application/components/github-picker.vue
+++ b/application/components/github-picker.vue
@@ -132,7 +132,7 @@ export default {
return
}
- this.$emit('select', response)
+ this.$emit('select', { github: { repository, branch }, ...response })
},
clearSelection() {
this.branch = null
diff --git a/application/components/initialize.vue b/application/components/initialize.vue
index 1021c0f..7795fcd 100644
--- a/application/components/initialize.vue
+++ b/application/components/initialize.vue
@@ -1,12 +1,9 @@
<script>
import keyBy from 'lodash/keyBy'
-import * as config from '../config'
import * as github from '../github'
import { healthcheck, loadBehaviours } from '../api'
-import { loadLayout } from '../layout.js'
-import { loadKeymap } from '../keymap.js'
import { loadKeycodes } from '../keycodes'
import Loader from './loader.vue'
@@ -41,7 +38,6 @@ export default {
async doReadyCheck() {
await healthcheck()
await this.loadAppData()
- await this.loadKeyboardData()
},
async loadAppData () {
await github.init()
@@ -54,46 +50,6 @@ export default {
this.behaviours.splice(0, this.behaviours.length, ...behaviours)
Object.assign(this.indexedKeycodes, keyBy(this.keycodes, 'code'))
Object.assign(this.indexedBehaviours, keyBy(this.behaviours, 'code'))
- },
- async loadKeyboardData() {
- const loadKeyboardData = async () => {
- if (config.enableGitHub && github.isGitHubAuthorized()) {
- if (github.repositories.length > 1) {
- this.tooManyRepos = true
- console.log('too many')
- return { layout: [], keymap: { layers: [] } }
- }
-
- const response = await github.fetchLayoutAndKeymap()
- if (response.error) {
- this.loadKeyboardError = response.error
- console.log('repo error')
- return { layout: [], keymap: { layers: [] } }
- }
-
- return response
- } else if (config.enableLocal) {
- const [layout, keymap] = await Promise.all([
- loadLayout(),
- loadKeymap()
- ])
- return { layout, keymap }
- } else {
- return { layout: [], keymap: { layers: [] } }
- }
- }
-
- const { layout, keymap } = await loadKeyboardData()
-
- this.layout.splice(0, this.layout.length, ...layout.map(key => (
- { ...key, u: key.u || key.w || 1, h: key.h || 1 }
- )))
-
- const layerNames = keymap.layer_names || keymap.layers.map((_, i) => `Layer ${i}`)
- Object.assign(this.layers, keymap.layers)
- Object.assign(this.keymap, keymap, {
- layer_names: layerNames
- })
}
}
}
@@ -102,11 +58,8 @@ export default {
<template>
<loader :load="doReadyCheck">
<slot
- :keymap="keymap"
- :layers="layers"
- :layout="layout"
:tooManyRepos="tooManyRepos"
:loadKeyboardError="loadKeyboardError"
/>
</loader>
-</template> \ No newline at end of file
+</template>
diff --git a/application/components/keyboard-picker.vue b/application/components/keyboard-picker.vue
index 404240a..a6fd529 100644
--- a/application/components/keyboard-picker.vue
+++ b/application/components/keyboard-picker.vue
@@ -71,14 +71,14 @@ export default {
},
handleKeyboardSelected(event) {
const { source } = this
- const { layout, keymap } = event
+ const { layout, keymap, ...rest } = event
const layerNames = keymap.layer_names || keymap.layers.map((_, i) => `Layer ${i}`)
Object.assign(keymap, {
layer_names: layerNames
})
- this.$emit('select', { source, layout, keymap })
+ this.$emit('select', { source, layout, keymap, ...rest })
}
}
}
diff --git a/application/github.js b/application/github.js
index 314d263..0d0782c 100644
--- a/application/github.js
+++ b/application/github.js
@@ -83,10 +83,10 @@ export async function fetchLayoutAndKeymap(repo, branch) {
}
}
-export function commitChanges(layout, keymap) {
+export function commitChanges(repo, branch, layout, keymap) {
const installationId = encodeURIComponent(installation.id)
- const repository = encodeURIComponent(repositories[0].full_name)
- const url = `${config.apiBaseUrl}/github/keyboard-files/${installationId}/${repository}`
+ const repository = encodeURIComponent(repo)
+ const url = `${config.apiBaseUrl}/github/keyboard-files/${installationId}/${repository}/${encodeURIComponent(branch)}`
return request(url, {
method: 'POST',