aboutsummaryrefslogtreecommitdiffhomepage
path: root/api/services
diff options
context:
space:
mode:
authorNick Coutsos <[email protected]>2021-11-03 13:08:41 -0400
committerNick Coutsos <[email protected]>2021-11-03 13:08:41 -0400
commit2de5888f5b0c0b22487f32e5adec5440a2e78c35 (patch)
tree2911de4f61c94f7dfd7e90cd41c2e21eee93fa60 /api/services
parent8fd26192689c06c75e4f6909fb2eb485fa377e56 (diff)
parent3d653a5e8b655678c8328c14282d0c7b4edf8a92 (diff)
downloadkeymap-editor-2de5888f5b0c0b22487f32e5adec5440a2e78c35.tar.gz
keymap-editor-2de5888f5b0c0b22487f32e5adec5440a2e78c35.zip
Merge branch 'master' into repo-picker
Diffstat (limited to 'api/services')
-rw-r--r--api/services/github/files.js17
-rw-r--r--api/services/github/index.js2
-rw-r--r--api/services/zmk/keymap.js2
3 files changed, 17 insertions, 4 deletions
diff --git a/api/services/github/files.js b/api/services/github/files.js
index 5f5837f..40bcb41 100644
--- a/api/services/github/files.js
+++ b/api/services/github/files.js
@@ -4,12 +4,22 @@ const zmk = require('../zmk')
const MODE_FILE = '100644'
+class InvalidRepoError extends Error {}
+
async function fetchKeyboardFiles (installationId, repository) {
const { data: { token: installationToken } } = await auth.createInstallationToken(installationId)
- const { data: info } = await fetchFile(installationToken, repository, 'config/info.json', true)
- const { data: keymap } = await fetchFile(installationToken, repository, 'config/keymap.json', true)
+ try {
+ const { data: info } = await fetchFile(installationToken, repository, 'config/info.json', true)
+ const { data: keymap } = await fetchFile(installationToken, repository, 'config/keymap.json', true)
+
+ return { info, keymap }
+ } catch (err) {
+ if (err.response && err.response.status === 404) {
+ throw new InvalidRepoError()
+ }
- return { info, keymap }
+ throw err
+ }
}
function fetchFile (installationToken, repository, path, raw = false) {
@@ -76,6 +86,7 @@ async function commitChanges (installationId, repository, layout, keymap) {
}
module.exports = {
+ InvalidRepoError,
fetchKeyboardFiles,
commitChanges
}
diff --git a/api/services/github/index.js b/api/services/github/index.js
index 34a0654..8443dd7 100644
--- a/api/services/github/index.js
+++ b/api/services/github/index.js
@@ -13,6 +13,7 @@ const {
} = require('./installations')
const {
+ InvalidRepoError,
fetchKeyboardFiles,
commitChanges
} = require('./files')
@@ -26,6 +27,7 @@ module.exports = {
verifyUserToken,
fetchInstallation,
fetchInstallationRepos,
+ InvalidRepoError,
fetchKeyboardFiles,
commitChanges
}
diff --git a/api/services/zmk/keymap.js b/api/services/zmk/keymap.js
index 011f486..a8837ea 100644
--- a/api/services/zmk/keymap.js
+++ b/api/services/zmk/keymap.js
@@ -108,7 +108,7 @@ function generateKeymapCode (layout, keymap, encoded) {
})
return `
- ${name} {
+ ${name.replace(/[^a-zA-Z0-9_]/g, '_')} {
bindings = <
${rendered}
>;