From 8b247f7af9c48b8f15e573216df49a696bf351b0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 13 Jan 2021 12:55:04 +0100 Subject: [PATCH] Final implementations of Git Branches --- Client/httpInterface.js | 59 ++++++++++++++++--- ...ng-branches-active-branch-not-changed.json | 14 +++++ .../UI/Spaces/Docs-Space/CommandInterface.js | 13 +++- .../UI/Spaces/Docs-Space/DocsSpace.js | 13 +++- 4 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-004-switching-branches-active-branch-not-changed.json diff --git a/Client/httpInterface.js b/Client/httpInterface.js index e5858d785..20ab62b55 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -533,6 +533,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE const commitMessage = unescape(requestParameters[3]) const username = unescape(requestParameters[4]) const token = unescape(requestParameters[5]) + const activeBranch = unescape(requestParameters[6]) + const contributionsBranch = unescape(requestParameters[7]) contribute() @@ -553,7 +555,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE await git.add('./*') await git.commit(commitMessage) - await git.push('origin', 'in-app-documentation') + await git.push('origin', branch) } async function doGithub() { @@ -567,8 +569,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE const repo = 'Superalgos' const owner = 'Superalgos' - const head = username + ':in-app-documentation' - const base = 'in-app-documentation' + const head = username + ':' + contributionsBranch + const base = activeBranch const title = 'Contribution: ' + commitMessage try { @@ -604,10 +606,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } case 'Update': { try { - const message = unescape(requestParameters[3]) - const username = unescape(requestParameters[4]) - const token = unescape(requestParameters[5]) - + const activeBranch = unescape(requestParameters[3]) update() async function update() { @@ -629,7 +628,51 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } const git = simpleGit(options) - return await git.pull('upstream', 'in-app-documentation') + return await git.pull('upstream', activeBranch) + } + + } catch (err) { + console.log('[ERROR] httpInterface -> App -> Update -> Method call produced an error.') + console.log('[ERROR] httpInterface -> App -> Update -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> App -> Update -> commitMessage = ' + commitMessage) + console.log('[ERROR] httpInterface -> App -> Update -> username = ' + username) + console.log('[ERROR] httpInterface -> App -> Update -> token = ' + token) + + let error = { + result: 'Fail Because', + message: err.message, + stack: err.stack + } + respondWithContent(JSON.stringify(error), httpResponse) + } + break + } + + case 'Checkout': { + try { + const activeBranch = unescape(requestParameters[3]) + checkout() + + async function checkout() { + let message = await doGit() + + let customResponse = { + result: global.CUSTOM_OK_RESPONSE.result, + message: message + } + respondWithContent(JSON.stringify(customResponse), httpResponse) + } + + async function doGit() { + const simpleGit = require('simple-git'); + const options = { + baseDir: process.cwd(), + binary: 'git', + maxConcurrentProcesses: 6, + } + const git = simpleGit(options) + + return await git.checkoutBranch(activeBranch) } } catch (err) { diff --git a/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-004-switching-branches-active-branch-not-changed.json b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-004-switching-branches-active-branch-not-changed.json new file mode 100644 index 000000000..aee7e57d3 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-004-switching-branches-active-branch-not-changed.json @@ -0,0 +1,14 @@ +{ + "topic": "Branches Management Messages", + "pageNumber": "4", + "type": "Switching Branches - Active Branch Not Changed", + "definition": { + "text": "Write here a summary for this topic page." + }, + "paragraphs": [ + { + "style": "Text", + "text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js index f0c57fa66..cb51ff863 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js @@ -62,7 +62,16 @@ function newSuperalgosDocsCommmandInterface() { return } - httpRequest(undefined, 'App/Contribute/' + message + '/' + config.username + '/' + config.token, onResponse) + httpRequest( + undefined, + 'App/Contribute/' + + message + '/' + + config.username + '/' + + config.token + '/' + + UI.projects.superalgos.spaces.docsSpace.activeBranch + '/' + + UI.projects.superalgos.spaces.docsSpace.contributionBranch + , onResponse) + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message - Creating Pull Request') return @@ -112,7 +121,7 @@ function newSuperalgosDocsCommmandInterface() { return } - httpRequest(undefined, 'App/Update/' + message + '/' + config.username + '/' + config.token, onResponse) + httpRequest(undefined, 'App/Update/' + UI.projects.superalgos.spaces.docsSpace.activeBranch, onResponse) UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message - Updating Your Local App') return diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 2fbc302a4..28ba785f7 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -185,9 +185,20 @@ function newSuperalgosDocSpace() { } function changeActiveBranch(branch) { - UI.projects.superalgos.spaces.docsSpace.activeBranch = branch window.localStorage.setItem('Active Branch', UI.projects.superalgos.spaces.docsSpace.activeBranch) + httpRequest(undefined, 'App/Checkout/' + UI.projects.superalgos.spaces.docsSpace.activeBranch, onResponse) UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Changing Active Branch') + + function onResponse(err, data) { + /* Lets check the result of the call through the http interface */ + data = JSON.parse(data) + if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.CUSTOM_OK_RESPONSE.result) { + UI.projects.superalgos.spaces.docsSpace.activeBranch = branch + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Active Branch Changed') + } else { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Active Branch Not Changed') + } + } } function changeContributionsBranch(branch) {