Governance: Signing Accounts implementation

This commit is contained in:
Luis Fernando Molina committed 2021-09-21 20:37:40 +02:00
1 parent e3f8d25328
commit e38b6bc952
1 file changed
+42
+42
View File
@@ -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.