Merge pull request #1299 from ssplatt/handle-git-error

Avoid crashing when attempting to use git command but it isn't available
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-07-15 10:58:37 -04:00
commit ca964b0eb8
4 files changed
+3729 -73

No files matched your search

+94 -70
View File
@@ -666,37 +666,43 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
contribute()
async function contribute() {
await doGit()
if (error !== undefined) {
const { lookpath } = require('lookpath');
const gitpath = await lookpath('git');
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
} else {
await doGit()
if (error !== undefined) {
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Contribution Not Sent',
anchor: undefined,
placeholder: {}
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Contribution Not Sent',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, error)
return
}
respondWithDocsObject(docs, error)
return
}
await doGithub()
if (error !== undefined) {
await doGithub()
if (error !== undefined) {
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Contribution Not Sent',
anchor: undefined,
placeholder: {}
}
console.log('respond with docs ')
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Contribution Not Sent',
anchor: undefined,
placeholder: {}
respondWithDocsObject(docs, error)
return
}
console.log('respond with docs ')
respondWithDocsObject(docs, error)
return
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
}
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
}
async function doGit() {
@@ -787,26 +793,32 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
update()
async function update() {
let result = await doGit()
if (result.error === undefined) {
let customResponse = {
result: global.CUSTOM_OK_RESPONSE.result,
message: result.message
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
const { lookpath } = require('lookpath');
const gitpath = await lookpath('git');
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
} else {
let result = await doGit()
if (result.error === undefined) {
let customResponse = {
result: global.CUSTOM_OK_RESPONSE.result,
message: result.message
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
} else {
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Update Failed',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, result.error)
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Update Failed',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, result.error)
}
}
@@ -852,20 +864,26 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
checkout()
async function checkout() {
await doGit()
if (error === undefined) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
const { lookpath } = require('lookpath');
const gitpath = await lookpath('git');
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
} else {
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'Switching Branches - Current Branch Not Changed',
anchor: undefined,
placeholder: {}
}
await doGit()
respondWithDocsObject(docs, error)
if (error === undefined) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
} else {
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'Switching Branches - Current Branch Not Changed',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, error)
}
}
}
@@ -905,24 +923,30 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
branch()
async function branch() {
let result = await doGit()
if (result.error === undefined) {
let customResponse = {
result: global.CUSTOM_OK_RESPONSE.result,
message: result
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
const { lookpath } = require('lookpath');
const gitpath = await lookpath('git');
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
} else {
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Could Not Get Current Branch',
anchor: undefined,
placeholder: {}
}
let result = await doGit()
respondWithDocsObject(docs, error)
if (result.error === undefined) {
let customResponse = {
result: global.CUSTOM_OK_RESPONSE.result,
message: result
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
} else {
let docs = {
project: 'Foundations',
category: 'Topic',
type: 'App Error - Could Not Get Current Branch',
anchor: undefined,
placeholder: {}
}
respondWithDocsObject(docs, error)
}
}
}
@@ -1938,4 +1962,4 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
return files.reduce((a, f) => a.concat(f), []);
}
}
}
}
+3632 -1
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -10,6 +10,7 @@
"@octokit/rest": "^18.0.12",
"ccxt": "^1.51.98",
"child_process": "^1.0.2",
"lookpath": "^1.2.1",
"open": "^6.4.0",
"rimraf": "^3.0.2",
"simple-git": "^2.31.0",
+2 -2
View File
@@ -14,6 +14,6 @@ services:
- ../Log-Files:/app/Log-Files
- ../My-Workspaces:/app/My-Workspaces
environment:
- PUID: '1000'
- GUID: '1000'
PUID: '1000'
PGID: '1000'
restart: on-failure