From 4647ab2758a5c518f0db2bfc8b0dc9f5795a2eb4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 15 Jan 2021 13:37:45 +0100 Subject: [PATCH 1/5] This is my contribution to Superalgos --- Client/httpInterface.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index 868755e4d..c1d69da31 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -599,8 +599,12 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE contribute() async function contribute() { - await doGit() - await doGithub() + if (await doGit() === false) { + respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + } + if (await doGithub() === false) { + respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + } respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) } @@ -617,10 +621,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE await git.add('./*') await git.commit(commitMessage) await git.push('origin', currentBranch) + return true } catch (err) { - console.log('[ERROR] Error running Contribute.') - console.log(err.stack) - throw (err) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> Method call produced an error.') + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> commitMessage = ' + commitMessage) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> currentBranch = ' + currentBranch) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGit -> contributionsBranch = ' + contributionsBranch) + return false } } @@ -647,9 +655,19 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE head, base, }); + return true } catch (err) { - if (err.stack.indexOf('A pull request already exists') < 0) { - throw (err) + if (err.stack.indexOf('A pull request already exists') >= 0) { + return true + } else { + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> Method call produced an error.') + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> commitMessage = ' + commitMessage) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> username = ' + username) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token = ' + token) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> currentBranch = ' + currentBranch) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> contributionsBranch = ' + contributionsBranch) + return false } } } @@ -660,6 +678,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE console.log('[ERROR] httpInterface -> App -> Contribute -> commitMessage = ' + commitMessage) console.log('[ERROR] httpInterface -> App -> Contribute -> username = ' + username) console.log('[ERROR] httpInterface -> App -> Contribute -> token = ' + token) + console.log('[ERROR] httpInterface -> App -> Contribute -> currentBranch = ' + currentBranch) + console.log('[ERROR] httpInterface -> App -> Contribute -> contributionsBranch = ' + contributionsBranch) let error = { result: 'Fail Because', From 75254b774b5d331c985f6a7db34a297434473392 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 15 Jan 2021 13:39:11 +0100 Subject: [PATCH 2/5] This is my contribution to Superalgos --- Client/httpInterface.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index c1d69da31..a89a053fb 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -601,9 +601,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE async function contribute() { if (await doGit() === false) { respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + return } if (await doGithub() === false) { respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + return } respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) } From 26dcdeaaed1338282287c154dc865942e86d1328 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 15 Jan 2021 13:42:19 +0100 Subject: [PATCH 3/5] This is my contribution to Superalgos --- Client/httpInterface.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index a89a053fb..115272566 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -666,7 +666,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> err.stack = ' + err.stack) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> commitMessage = ' + commitMessage) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> username = ' + username) - console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token = ' + token) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(1, 5)) + '...' + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token ends with = ' + '...' + token.substring(token.length-5, 5)) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> currentBranch = ' + currentBranch) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> contributionsBranch = ' + contributionsBranch) return false From b59a8d0fa4280a10a1cb58d70d6c29716af8c53c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 15 Jan 2021 13:44:48 +0100 Subject: [PATCH 4/5] This is my contribution to Superalgos --- Client/httpInterface.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index 115272566..a517cf35a 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -539,7 +539,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE fs.mkdirSync(filePath) } catch (err) { if (err.message.indexOf('file already exists') < 0) { - throw(err) + throw (err) } } fs.writeFileSync(filePath + '/' + fileName, fileContent) @@ -666,8 +666,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> err.stack = ' + err.stack) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> commitMessage = ' + commitMessage) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> username = ' + username) - console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(1, 5)) + '...' - console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token ends with = ' + '...' + token.substring(token.length-5, 5)) + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(1, 10)) + '...' + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token ends with = ' + '...' + token.substring(token.length - 10)) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> currentBranch = ' + currentBranch) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> contributionsBranch = ' + contributionsBranch) return false From 5ba59db34201d456b89a1738c07a03e847f73325 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 15 Jan 2021 13:46:09 +0100 Subject: [PATCH 5/5] This is my contribution to Superalgos --- Client/httpInterface.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index a517cf35a..2a968bdd2 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -666,7 +666,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> err.stack = ' + err.stack) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> commitMessage = ' + commitMessage) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> username = ' + username) - console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(1, 10)) + '...' + console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token starts with = ' + token.substring(0, 10) + '...') console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> token ends with = ' + '...' + token.substring(token.length - 10)) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> currentBranch = ' + currentBranch) console.log('[ERROR] httpInterface -> App -> Contribute -> doGithub -> contributionsBranch = ' + contributionsBranch)