From e38b6bc9527cdc05b63c777436d7f95be183c0cb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 Sep 2021 20:37:40 +0200 Subject: [PATCH] Governance: Signing Accounts implementation --- Platform/Client/githubServer.js | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Platform/Client/githubServer.js b/Platform/Client/githubServer.js index 4c0521a8b..47823b677 100644 --- a/Platform/Client/githubServer.js +++ b/Platform/Client/githubServer.js @@ -304,6 +304,7 @@ exports.newGithubServer = function newGithubServer() { if (await validateUserProfileNodeNameEqualsGithubUsername() === false) { continue } if (await validateUserProfileIdDoesNotBelongtoAnotherUserProfile() === false) { continue } if (await validateUserProfileBlockchainAccountDoesNotBelongtoAnotherUserProfile() === false) { continue } + if (await validateUserProfileSigningAccountsDoesNotBelongtoAnotherUserProfile() === false) { continue } if (await mergePullRequest() === false) { console.log('[WARN] Github Server -> mergeGithubPullRequests -> Merge Failed -> Pull Request "' + pullRequest.title + '" not merged because Github could not merge it. -> mergeResponse.message = ' + mergeResponse.data.message) @@ -578,6 +579,47 @@ exports.newGithubServer = function newGithubServer() { } } + async function validateUserProfileSigningAccountsDoesNotBelongtoAnotherUserProfile() { + try { + /* + Validation #8 Signing accounts of the User Profile + must have a signature of the same Github username of the User Profile. + */ + + if (userProfile.signingAccounts === undefined) { return true } + + for (let i = 0; i < userProfile.signingAccounts.length; i++) { + let signingAccount = userProfile.signingAccounts[i] + let config = JSON.parse(signingAccount.config) + + if (config.signature.message !== githubUsername) { + console.log('[INFO] Github Server -> mergeGithubPullRequests -> Validation #8 Failed -> Pull Request "' + pullRequest.title + '" not merged because the Signing Account ' + signingAccount.name + ' has not signed the current Github User Account, but something else. -> config.signature.message = ' + config.signature.message + '-> githubUsername = ' + githubUsername) + + await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME) + await octokit.rest.issues.createComment({ + owner: owner, + repo: repo, + issue_number: pullRequest.number, + body: 'This Pull Request could not be automatically merged and was closed by the Superalgos Governance System because the Signing Account ' + signingAccount.name + ' has not signed the current Github User Account, but something else. \n\nconfig.signature.message = ' + config.signature.message + '" \n\n githubUsername = ' + githubUsername + '"' + }); + + await PL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME) + await octokit.rest.pulls.update({ + owner: owner, + repo: repo, + pull_number: pullRequest.number, + state: 'closed' + }); + return false + } + } + + return true + } catch (err) { + console.log(err.stack) + } + } + async function mergePullRequest() { /* All validations passed, we will proceed an merge this Pull Request.