diff options
Diffstat (limited to 'api/services/github/files.js')
-rw-r--r-- | api/services/github/files.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/api/services/github/files.js b/api/services/github/files.js index 65c4c83..9c2b6f9 100644 --- a/api/services/github/files.js +++ b/api/services/github/files.js @@ -16,11 +16,30 @@ class MissingRepoFile extends Error { async function fetchKeyboardFiles (installationId, repository, branch) { const { data: { token: installationToken } } = await auth.createInstallationToken(installationId) const { data: info } = await fetchFile(installationToken, repository, 'config/info.json', { raw: true, branch }) - const { data: keymap } = await fetchFile(installationToken, repository, 'config/keymap.json', { raw: true, branch }) + const keymap = await fetchKeymap(installationToken, repository, branch) const originalCodeKeymap = await findCodeKeymap(installationToken, repository, branch) return { info, keymap, originalCodeKeymap } } +async function fetchKeymap (installationToken, repository, branch) { + try { + const { data : keymap } = await fetchFile(installationToken, repository, 'config/keymap.json', { raw: true, branch }) + return keymap + } catch (err) { + if (err instanceof MissingRepoFile) { + return { + keyboard: 'unknown', + keymap: 'unknown', + layout: 'unknown', + layer_names: ['default'], + layers: [[]] + } + } else { + throw err + } + } +} + async function fetchFile (installationToken, repository, path, options = {}) { const { raw = false, branch = null } = options const url = `/repos/${repository}/contents/${path}` |