From a54de8bc939c6daae589c4399b1318b73a2e71fa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 27 Jul 2021 09:16:20 +0200 Subject: [PATCH 1/7] testPR --- .../Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index 563510637..b7c47e1df 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -239,7 +239,7 @@ "floatingObject": { "isPinned": false, "isFrozen": false, - "isCollapsed": false, + "isCollapsed": true, "angleToParent": 3, "distanceToParent": 3, "arrangementStyle": 0 From 6c9c4511acf8d8edd8156fe7e1592e32afafa5f7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 27 Jul 2021 14:18:54 +0200 Subject: [PATCH 2/7] Github Program impleme --- Client/httpInterface.js | 154 +- .../Icons/Programs/github-program.png | Bin 0 -> 17538 bytes .../Governance/Plugins/Pools/Superalgos.json | 165 +- .../User-Profiles/Luis-Fernando-Molina.json | 1694 ++++++++++++++--- .../Schemas/App-Schema/github-program.json | 51 + .../App-Schema/token-power-switch.json | 15 + .../Schemas/App-Schema/tokens-awarded.json | 2 +- .../Function-Libraries/DistributionProcess.js | 11 +- .../UI/Function-Libraries/GithubProgram.js | 191 ++ .../UI/Function-Libraries/TokenMining.js | 10 + .../UI/Function-Libraries/TokenPower.js | 6 +- .../Spaces/User-Profile-Space/UserProfile.js | 54 + Projects/ProjectsSchema.json | 5 + 13 files changed, 2007 insertions(+), 351 deletions(-) create mode 100644 Projects/Governance/Icons/Programs/github-program.png create mode 100644 Projects/Governance/Schemas/App-Schema/github-program.json create mode 100644 Projects/Governance/UI/Function-Libraries/GithubProgram.js diff --git a/Client/httpInterface.js b/Client/httpInterface.js index bcd81c02d..d4615cb18 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -773,7 +773,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE console.log('[ERROR] httpInterface -> App -> Contribute -> err.stack = ' + err.stack) 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 -> token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> App -> Contribute -> token ends with = ' + '...' + token.substring(token.length - 10)) console.log('[ERROR] httpInterface -> App -> Contribute -> currentBranch = ' + currentBranch) console.log('[ERROR] httpInterface -> App -> Contribute -> contributionsBranch = ' + contributionsBranch) @@ -1018,6 +1019,151 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } break + case 'Gov': { + switch (requestParameters[2]) { // switch by command + case 'getRepoInfo': { + try { + const GITHUB_API_WAITING_TIME = 1000 + const repository = unescape(requestParameters[3]) + const username = unescape(requestParameters[4]) + const token = unescape(requestParameters[5]) + let error + let starsListArray = [] + + + getRepoInfo() + + async function getRepoInfo() { + + await doGithub() + if (error !== undefined) { + + let docs = { + project: 'Governance', + category: 'Topic', + type: 'Gov Error - Get Repository Information', + anchor: undefined, + placeholder: {} + } + + respondWithDocsObject(docs, error) + return + } + respondWithContent(JSON.stringify(starsListArray), httpResponse) + } + + async function doGithub() { + + const { Octokit } = require("@octokit/rest") + + const octokit = new Octokit({ + auth: token, + userAgent: 'Superalgos Beta 10' + }) + + const repo = repository + const owner = 'Superalgos' + const per_page = 100 // Max + let page = 0 + let lastPage = false + + while (lastPage === false) { + try { + page++ + await sleep(GITHUB_API_WAITING_TIME) + let starsListResponse = await octokit.activity.listStargazersForRepo({ + owner, + repo, + per_page, + page + }); + + if (starsListResponse.data.length < 100) { + lastPage = true + } + + for (let i = 0; i < starsListResponse.data.length; i++) { + let star = starsListResponse.data[i] + starsListArray.push(star.login) + } + + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> Stars Page = ' + page) + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> Stars Received = ' + starsListResponse.data.length) + + } catch (err) { + console.log(err) + + if (err.stack.indexOf('last page') >= 0) { + return + } else { + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> Method call produced an error.') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> commitMessage = ' + repository) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> username = ' + username) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> token ends with = ' + '...' + token.substring(token.length - 10)) + error = err + } + } + } + } + + } catch (err) { + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> Method call produced an error.') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> repository = ' + repository) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> username = ' + username) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token ends with = ' + '...' + token.substring(token.length - 10)) + + let error = { + result: 'Fail Because', + message: err.message, + stack: err.stack + } + respondWithContent(JSON.stringify(error), httpResponse) + } + break + } + } + + function respondWithDocsObject(docs, error) { + + if (error.message !== undefined) { + docs.placeholder.errorMessage = { + style: 'Error', + text: error.message + } + } + if (error.stack !== undefined) { + docs.placeholder.errorStack = { + style: 'Javascript', + text: error.stack + } + } + if (error.code !== undefined) { + docs.placeholder.errorCode = { + style: 'Json', + text: error.code + } + } + + docs.placeholder.errorDetails = { + style: 'Json', + text: JSON.stringify(error, undefined, 4) + } + + let customResponse = { + result: global.CUSTOM_FAIL_RESPONSE.result, + docs: docs + } + + respondWithContent(JSON.stringify(customResponse), httpResponse) + + } + } + break + case 'LegacyPlotter.js': { respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/LegacyPlotter.js', httpResponse) @@ -1962,4 +2108,10 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE return files.reduce((a, f) => a.concat(f), []); } } + + function sleep(ms) { + return new Promise((resolve) => { + setTimeout(resolve, ms) + }) + } } diff --git a/Projects/Governance/Icons/Programs/github-program.png b/Projects/Governance/Icons/Programs/github-program.png new file mode 100644 index 0000000000000000000000000000000000000000..ef69b801e39ddc506bbda6ef930d53d5b8f706d8 GIT binary patch literal 17538 zcmb5Vc|4Tg8$Wzz!8C*^vNNcNWT%ap?4qn?OD0PwA|+eQh>%?iDrHS%Pgz1U$Wke5 zvSbS(*>^MMer})d@At>^dj5L;;>>-{b*^)rYdhC@p9iMr_4i^0u>gR*h6Xz303hLi zkpROA|5^3#*@piJ+}5?eZQ*tGw%-*W7jVYe%h3gI=y}D}#oXnJbHL5dE~f#|IcTVJ z#?pV_--~uHr+(k55@*Tp5_=2ALc=c>(CKM6_2WO-(=DLSUcah`TZT~OUH zjdXePjAv_exO!ojt|>+_t+v-q+Nh&{-(b{U=X~f=TUS0tez!)xvpSWsQ}BxXkqMQ2 zF%5ab447~r{2*}ULQr#dq*E~~(fZ|Z&Hg4P)K;lUf~39(8YPBjdd=o0r)F{9mw$f}pVLv3JgI8t^JfWg2tHUD`?7_W_| zz}l5XQAe;(W&0l#y-sihh{SuHDT~9wYIQS>qiHG#oolQ85MrI+jzklU^&Hd!t<*ze zc=t3Ih@zQ4oLCV(9`JY7dGb|w?!QV55op|Vh+!(G0R^VqKw>;L`yt#M`NJM=kjX*y z*p%!Ed3?G40Uu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8c2*_h3=S-9o3yT>VCzri+nYLZUxek}3B~*k*r&ihS*r2bHz4t;pQ9@F-RlJd*O0>pxz>Wx}pQ#0w@~M}rcvUGLKg zYD0G6u0$35PYmVVs)*wzY_On=J=7_M##66@2Hgz6foB0E8XTw{ODlw3v5(ibD;55u zZXU;~6VyP;!GZJhD40s3uF9x!HUf3gNgTEIe>iv>&HC>{fkeG@76PXWKFy}|e$@2a zvnwj$Y=q;enuuK3&!qQ#pZ*hy8!WeRa@w|4O(y)njt;-;0C5M9u!09$Y1?KTM&QSo zx8BeZfA90adUff#fQJ_5(nran;N7K;>cL}?=l5~&Blu7J+1QmarMi<6s)stSv~4RD zzqRw9W1n#&8f7D1=tu&XMg2?X02%-uKBUqq;s+Mn2N37G$E^Odh%&6PT_Qp+&@x|)v_K&m}f%*1;A4f?H>s=;MkoJ)8%s?T9 z4FVdaml8M`4|LWtbUO1gI2?N6*<7^ELI1(}srR>beq;xR7ek>7^AjJ&mHaOxTp8Hj zX`Q!E*$N7Nf%yUvyK)OW84ZenZULDlsaWtvOvY%714BUuzr!(LcAcPEbz;I5_BE4M z&%YuDtPDCB7#wb0Y?wCNFs#CjCEToken Power Switch->" + }, + "addLeftIcons": true, + "level": 1, + "propertyNameAtParent": "githubProgram", + "childrenNodesProperties": [ + { + "name": "tokensAwarded", + "type": "node", + "childType": "Tokens Awarded", + "autoAdd": true + } + ] +} \ No newline at end of file diff --git a/Projects/Governance/Schemas/App-Schema/token-power-switch.json b/Projects/Governance/Schemas/App-Schema/token-power-switch.json index 966f72788..f45aa674e 100644 --- a/Projects/Governance/Schemas/App-Schema/token-power-switch.json +++ b/Projects/Governance/Schemas/App-Schema/token-power-switch.json @@ -78,6 +78,15 @@ "label": "Add Delegation Program", "relatedUiObject": "Delegation Program" }, + { + "action": "Add UI Object", + "actionProject": "Foundations", + "actionFunction": "payload.executeAction", + "disableIfPropertyIsDefined": true, + "propertyToCheckFor": "githubProgram", + "label": "Add Github Program", + "relatedUiObject": "Github Program" + }, { "action": "Delete UI Object", "actionProject": "Foundations", @@ -149,6 +158,12 @@ "type": "node", "childType": "Delegation Program", "autoAdd": false + }, + { + "name": "githubProgram", + "type": "node", + "childType": "Github Program", + "autoAdd": false } ] } \ No newline at end of file diff --git a/Projects/Governance/Schemas/App-Schema/tokens-awarded.json b/Projects/Governance/Schemas/App-Schema/tokens-awarded.json index 997aa3a30..f5dfc3bb4 100644 --- a/Projects/Governance/Schemas/App-Schema/tokens-awarded.json +++ b/Projects/Governance/Schemas/App-Schema/tokens-awarded.json @@ -15,7 +15,7 @@ "addLeftIcons": true, "level": 2, "attachingRules": { - "compatibleTypes": "->Referral Program->Mentorship Program->Support Program->Claims Program->Staking Program->" + "compatibleTypes": "->Referral Program->Mentorship Program->Support Program->Claims Program->Staking Program->Github Program->" }, "propertyNameAtParent": "tokensAwarded" } \ No newline at end of file diff --git a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js index a48a320bc..ddb06403d 100644 --- a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js +++ b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js @@ -98,11 +98,18 @@ function newGovernanceFunctionLibraryDistributionProcess() { userProfiles ) /* + Run the Github Program + */ + UI.projects.governance.functionLibraries.githubProgram.calculate( + pools, + userProfiles + ) + /* After all the programs were ran, we can calculate the tokens mining calculation each profile. */ UI.projects.governance.functionLibraries.tokenMining.calculate( - userProfiles - ) + userProfiles + ) } } \ No newline at end of file diff --git a/Projects/Governance/UI/Function-Libraries/GithubProgram.js b/Projects/Governance/UI/Function-Libraries/GithubProgram.js new file mode 100644 index 000000000..69aec925d --- /dev/null +++ b/Projects/Governance/UI/Function-Libraries/GithubProgram.js @@ -0,0 +1,191 @@ +function newGovernanceFunctionLibraryGithubProgram() { + let thisObject = { + calculate: calculate + } + + return thisObject + + function calculate( + pools, + userProfiles + ) { + let programPoolTokenReward + /* + In order to be able to calculate the share of the Program Pool for each User Profile, + we need to accumulate all the Github Power that each User Profile at their Program + node has, because with that Power is that each Program node gets a share of the pool. + */ + let accumulatedProgramPower = 0 + + /* Scan Pools Until finding the Mentoship-Program Pool */ + for (let i = 0; i < pools.length; i++) { + let poolsNode = pools[i] + programPoolTokenReward = UI.projects.governance.utilities.pools.findPool(poolsNode, "Github-Rewards") + } + if (programPoolTokenReward === undefined || programPoolTokenReward === 0) { return } + + for (let i = 0; i < userProfiles.length; i++) { + let userProfile = userProfiles[i] + + if (userProfile.tokenPowerSwitch === undefined) { continue } + let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program") + if (program === undefined) { continue } + if (program.payload === undefined) { continue } + + resetProgram(program) + } + for (let i = 0; i < userProfiles.length; i++) { + let userProfile = userProfiles[i] + + if (userProfile.tokenPowerSwitch === undefined) { continue } + let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program") + if (program === undefined) { continue } + if (program.payload === undefined) { continue } + + validateProgram(program, userProfile) + } + for (let i = 0; i < userProfiles.length; i++) { + let userProfile = userProfiles[i] + + if (userProfile.tokenPowerSwitch === undefined) { continue } + let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program") + if (program === undefined) { continue } + if (program.payload === undefined) { continue } + if (program.payload.githubProgram.isActive === false) { continue } + + distributeProgram(program) + } + for (let i = 0; i < userProfiles.length; i++) { + let userProfile = userProfiles[i] + + if (userProfile.tokenPowerSwitch === undefined) { continue } + let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program") + if (program === undefined) { continue } + if (program.payload === undefined) { continue } + if (program.payload.githubProgram.isActive === false) { continue } + + calculateProgram(program) + } + + function resetProgram(node) { + if (node === undefined) { return } + if (node.payload === undefined) { return } + if (node.payload.githubProgram === undefined) { + node.payload.githubProgram = { + count: 0, + percentage: 0, + outgoingPower: 0, + ownPower: 0, + incomingPower: 0, + awarded: { + tokens: 0, + percentage: 0 + } + } + } else { + node.payload.githubProgram.count = 0 + node.payload.githubProgram.percentage = 0 + node.payload.githubProgram.outgoingPower = 0 + node.payload.githubProgram.ownPower = 0 + node.payload.githubProgram.incomingPower = 0 + node.payload.githubProgram.awarded = { + tokens: 0, + percentage: 0 + } + } + } + + function validateProgram(node, userProfile) { + /* + This program is not going to run unless the Profile has Tokens, and for + that users needs to execute the setup procedure of signing their Github + username with their private key. + */ + if ( + userProfile.payload.blockchainTokens === undefined + ) { + node.payload.githubProgram.isActive = false + userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, to access the Token Power of your account at the Blockchain.") + return + } + /* + Next thing to do is to validate if the github user profile has a star at the Superalgos repository. + */ + let profileSignature = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'signature') + if ( + profileSignature === undefined + ) { + node.payload.githubProgram.isActive = false + userProfile.payload.uiObject.setErrorMessage("You need to setup this profile with the Profile Constructor, and produce a signature of your Github Username.") + return + } + let githubUsername = profileSignature.message + node.payload.githubProgram.hasStar = UI.projects.governance.spaces.userProfileSpace.githubStars.get(githubUsername) + + if (node.payload.githubProgram.hasStar === true) { + node.payload.githubProgram.isActive = true + } else { + node.payload.githubProgram.isActive = false + } + } + + function distributeProgram(programNode) { + if (programNode === undefined || programNode.payload === undefined) { return } + /* + Here we will convert Token Power into Github Power. + As per system rules Github Powar = tokensPower + */ + let programPower = programNode.payload.tokenPower + programNode.payload.githubProgram.ownPower = programPower + + accumulatedProgramPower = accumulatedProgramPower + programPower + } + + function calculateProgram(programNode) { + /* + Here we will calculate which share of the Program Pool this user will get in tokens. + To do that, we use the ownPower, to see which proportion of the accumulatedProgramPower + represents. + */ + if (programNode.payload === undefined) { return } + /* + If the accumulatedProgramPower is not grater the amount of tokens at the Program Pool, then + this user will get the exact amount of tokens from the pool as incomingPower he has. + + If the accumulatedProgramPower is grater the amount of tokens at the Program Pool, then + the amount ot tokens to be received is a proportional to the share of incomingPower in accumulatedProgramPower. + */ + let totalPowerRewardRatio = accumulatedProgramPower / programPoolTokenReward + if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 } + + if (programNode.tokensAwarded === undefined || programNode.tokensAwarded.payload === undefined) { + programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.") + return + } + programNode.payload.githubProgram.awarded.tokens = programNode.payload.githubProgram.ownPower / totalPowerRewardRatio + + drawProgram(programNode) + } + + function drawProgram(node) { + if (node.payload !== undefined) { + + const ownPowerText = parseFloat(node.payload.githubProgram.ownPower.toFixed(0)).toLocaleString('en') + + node.payload.uiObject.statusAngleOffset = 0 + node.payload.uiObject.statusAtAngle = false + + node.payload.uiObject.setStatus(ownPowerText + ' Github Power') + } + if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) { + + const tokensAwardedText = parseFloat(node.payload.githubProgram.awarded.tokens.toFixed(0)).toLocaleString('en') + + node.tokensAwarded.payload.uiObject.valueAngleOffset = 0 + node.tokensAwarded.payload.uiObject.valueAtAngle = false + + node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens') + } + } + } +} \ No newline at end of file diff --git a/Projects/Governance/UI/Function-Libraries/TokenMining.js b/Projects/Governance/UI/Function-Libraries/TokenMining.js index 7c980d3d7..3c767f30e 100644 --- a/Projects/Governance/UI/Function-Libraries/TokenMining.js +++ b/Projects/Governance/UI/Function-Libraries/TokenMining.js @@ -83,6 +83,16 @@ function newGovernanceFunctionLibraryTokenMining() { calculateProgram(userProfile, program, "delegationProgram") } + for (let i = 0; i < userProfiles.length; i++) { + let userProfile = userProfiles[i] + + if (userProfile.tokenPowerSwitch === undefined) { continue } + let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Github Program") + if (program === undefined) { continue } + if (program.payload === undefined) { continue } + + calculateProgram(userProfile, program, "githubProgram") + } for (let i = 0; i < userProfiles.length; i++) { let userProfile = userProfiles[i] diff --git a/Projects/Governance/UI/Function-Libraries/TokenPower.js b/Projects/Governance/UI/Function-Libraries/TokenPower.js index 05c6da779..4299a19a0 100644 --- a/Projects/Governance/UI/Function-Libraries/TokenPower.js +++ b/Projects/Governance/UI/Function-Libraries/TokenPower.js @@ -49,7 +49,8 @@ function newGovernanceFunctionLibraryTokenPower() { node.type === 'Voting Program' || node.type === 'Claims Program' || node.type === 'Staking Program' || - node.type === 'Delegation Program' + node.type === 'Delegation Program' || + node.type === 'Github Program' ) { return } /* We will reset token power of children. @@ -149,7 +150,8 @@ function newGovernanceFunctionLibraryTokenPower() { node.type === 'Voting Program' || node.type === 'Claims Program' || node.type === 'Staking Program' || - node.type === 'Delegation Program' + node.type === 'Delegation Program' || + node.type === 'Github Program' ) { return } /* We will redistribute token power among children. diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index f146f594a..9a34c3cb7 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -2,6 +2,7 @@ function newGovernanceUserProfileSpace() { const MODULE_NAME = 'User Profile Space' let thisObject = { + githubStars: undefined, container: undefined, physics: physics, draw: draw, @@ -17,13 +18,66 @@ function newGovernanceUserProfileSpace() { let waitingForResponses = 0 let timer = 0 + thisObject.githubStars = new Map() + return thisObject function initialize() { + /* + Here we will get a list of all github usernames who have a star or fork and are watching the + Superalgos Repository. This will later be used to know which user profiles are participating + at the Github Program. + */ + /* Find the Username and Password */ + let apisNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('APIs') + if (apisNode === undefined) { + UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + UI.projects.education.spaces.docsSpace.sidePanelTab.open() + return + } + if (apisNode.githubAPI === undefined) { + UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + UI.projects.education.spaces.docsSpace.sidePanelTab.open() + return + } + + let config = JSON.parse(apisNode.githubAPI.config) + if (config.username === undefined || config.username === "") { + UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + UI.projects.education.spaces.docsSpace.sidePanelTab.open() + return + } + if (config.token === undefined || config.token === "") { + UI.projects.education.spaces.docsSpace.navigateTo('Foundations', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing') + UI.projects.education.spaces.docsSpace.sidePanelTab.open() + return + } + + httpRequest( + undefined, + 'Gov/getRepoInfo/' + + 'Superalgos' + '/' + + config.username + '/' + + config.token + , onGithubStarsResponse) + + return + + function onGithubStarsResponse(err, githubStarsArray) { + /* Lets check the result of the call through the http interface */ + githubStarsArray = JSON.parse(githubStarsArray) + + for (let i = 0; i < githubStarsArray.length; i++) { + githubUsername = githubStarsArray[i] + thisObject.githubStars.set(githubUsername, true) + } + } } function finalize() { + thisObject.githubStars = undefined + thisObject.container.finalize() thisObject.container = undefined } diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 18b8a465a..c774e951c 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1051,6 +1051,11 @@ "name": "Profile Constructor", "propertyName": "profileConstructor", "functionName": "newGovernanceFunctionLibraryProfileConstructor" + }, + { + "name": "Github Program", + "propertyName": "githubProgram", + "functionName": "newGovernanceFunctionLibraryGithubProgram" } ], "utilities": [ From dae1164d3c65531e90d7ff414b8ba952b86d0f7f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 27 Jul 2021 14:33:56 +0200 Subject: [PATCH 3/7] github stars implemented --- .../UI/Function-Libraries/GithubProgram.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Projects/Governance/UI/Function-Libraries/GithubProgram.js b/Projects/Governance/UI/Function-Libraries/GithubProgram.js index 69aec925d..6f24a6fab 100644 --- a/Projects/Governance/UI/Function-Libraries/GithubProgram.js +++ b/Projects/Governance/UI/Function-Libraries/GithubProgram.js @@ -126,7 +126,7 @@ function newGovernanceFunctionLibraryGithubProgram() { node.payload.githubProgram.isActive = true } else { node.payload.githubProgram.isActive = false - } + } } function distributeProgram(programNode) { @@ -185,6 +185,16 @@ function newGovernanceFunctionLibraryGithubProgram() { node.tokensAwarded.payload.uiObject.valueAtAngle = false node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens') + + node.tokensAwarded.payload.uiObject.statusAngleOffset = 0 + node.tokensAwarded.payload.uiObject.statusAtAngle = false + + let extraText = '' + if (node.payload.githubProgram.hasStar === true) { + extraText = ' 1 Star' + } + + node.tokensAwarded.payload.uiObject.setStatus('From' + extraText) } } } From 030c21d3723c079889a8a382aad4b3d0414f3997 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 27 Jul 2021 16:12:43 +0200 Subject: [PATCH 4/7] Github Watchers Implemented at Github Program --- Client/httpInterface.js | 132 +++++++++++++----- .../UI/Function-Libraries/GithubProgram.js | 16 ++- .../Spaces/User-Profile-Space/UserProfile.js | 15 +- 3 files changed, 120 insertions(+), 43 deletions(-) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index d4615cb18..e667bf113 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -1029,7 +1029,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE const token = unescape(requestParameters[5]) let error let starsListArray = [] - + let watchersListArray = [] getRepoInfo() @@ -1049,7 +1049,12 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE respondWithDocsObject(docs, error) return } - respondWithContent(JSON.stringify(starsListArray), httpResponse) + + let responseObject = { + starsListArray: starsListArray, + watchersListArray: watchersListArray + } + respondWithContent(JSON.stringify(responseObject), httpResponse) } async function doGithub() { @@ -1061,48 +1066,101 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE userAgent: 'Superalgos Beta 10' }) - const repo = repository - const owner = 'Superalgos' - const per_page = 100 // Max - let page = 0 - let lastPage = false + await getStars() + await getWatchers() - while (lastPage === false) { - try { - page++ - await sleep(GITHUB_API_WAITING_TIME) - let starsListResponse = await octokit.activity.listStargazersForRepo({ - owner, - repo, - per_page, - page - }); + async function getStars() { + const repo = repository + const owner = 'Superalgos' + const per_page = 100 // Max + let page = 0 + let lastPage = false - if (starsListResponse.data.length < 100) { - lastPage = true + while (lastPage === false) { + try { + page++ + await sleep(GITHUB_API_WAITING_TIME) + let starsListResponse = await octokit.activity.listStargazersForRepo({ + owner, + repo, + per_page, + page + }); + + if (starsListResponse.data.length < 100) { + lastPage = true + } + + for (let i = 0; i < starsListResponse.data.length; i++) { + let star = starsListResponse.data[i] + starsListArray.push(star.login) + } + + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars -> Stars Page = ' + page) + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars -> Stars Received = ' + starsListResponse.data.length) + + } catch (err) { + console.log(err) + + if (err.stack.indexOf('last page') >= 0) { + return + } else { + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->Method call produced an error.') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->commitMessage = ' + repository) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->username = ' + username) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->token ends with = ' + '...' + token.substring(token.length - 10)) + error = err + } } + } + } - for (let i = 0; i < starsListResponse.data.length; i++) { - let star = starsListResponse.data[i] - starsListArray.push(star.login) - } + async function getWatchers() { + const repo = repository + const owner = 'Superalgos' + const per_page = 100 // Max + let page = 0 + let lastPage = false - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> Stars Page = ' + page) - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> Stars Received = ' + starsListResponse.data.length) + while (lastPage === false) { + try { + page++ + await sleep(GITHUB_API_WAITING_TIME) + let watchersListResponse = await octokit.activity.listWatchersForRepo({ + owner, + repo, + per_page, + page + }); - } catch (err) { - console.log(err) + if (watchersListResponse.data.length < 100) { + lastPage = true + } - if (err.stack.indexOf('last page') >= 0) { - return - } else { - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> Method call produced an error.') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> err.stack = ' + err.stack) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> commitMessage = ' + repository) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> username = ' + username) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> token starts with = ' + token.substring(0, 10) + '...') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> token ends with = ' + '...' + token.substring(token.length - 10)) - error = err + for (let i = 0; i < watchersListResponse.data.length; i++) { + let watch = watchersListResponse.data[i] + watchersListArray.push(watch.login) + } + + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers -> Watchers Page = ' + page) + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers -> Watchers Received = ' + watchersListResponse.data.length) + + } catch (err) { + console.log(err) + + if (err.stack.indexOf('last page') >= 0) { + return + } else { + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->Method call produced an error.') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->commitMessage = ' + repository) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->username = ' + username) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->token ends with = ' + '...' + token.substring(token.length - 10)) + error = err + } } } } diff --git a/Projects/Governance/UI/Function-Libraries/GithubProgram.js b/Projects/Governance/UI/Function-Libraries/GithubProgram.js index 6f24a6fab..7342847f4 100644 --- a/Projects/Governance/UI/Function-Libraries/GithubProgram.js +++ b/Projects/Governance/UI/Function-Libraries/GithubProgram.js @@ -121,8 +121,14 @@ function newGovernanceFunctionLibraryGithubProgram() { } let githubUsername = profileSignature.message node.payload.githubProgram.hasStar = UI.projects.governance.spaces.userProfileSpace.githubStars.get(githubUsername) + node.payload.githubProgram.hasWatch = UI.projects.governance.spaces.userProfileSpace.githubWatchers.get(githubUsername) + node.payload.githubProgram.engagement = 0 - if (node.payload.githubProgram.hasStar === true) { + if (node.payload.githubProgram.hasStar === true) { node.payload.githubProgram.engagement++ } + if (node.payload.githubProgram.hasWatch === true) { node.payload.githubProgram.engagement++ } + + if ( + node.payload.githubProgram.engagement > 0) { node.payload.githubProgram.isActive = true } else { node.payload.githubProgram.isActive = false @@ -162,7 +168,8 @@ function newGovernanceFunctionLibraryGithubProgram() { programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.") return } - programNode.payload.githubProgram.awarded.tokens = programNode.payload.githubProgram.ownPower / totalPowerRewardRatio + const MAX_ENGAGEMENT = 2 + programNode.payload.githubProgram.awarded.tokens = programNode.payload.githubProgram.ownPower / totalPowerRewardRatio * programNode.payload.githubProgram.engagement / MAX_ENGAGEMENT drawProgram(programNode) } @@ -191,7 +198,10 @@ function newGovernanceFunctionLibraryGithubProgram() { let extraText = '' if (node.payload.githubProgram.hasStar === true) { - extraText = ' 1 Star' + extraText = extraText + ' 1 Star' + } + if (node.payload.githubProgram.hasWatch === true) { + extraText = extraText + ' 1 Watch' } node.tokensAwarded.payload.uiObject.setStatus('From' + extraText) diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 9a34c3cb7..6fd9ec107 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -3,6 +3,7 @@ function newGovernanceUserProfileSpace() { let thisObject = { githubStars: undefined, + githubWatchers: undefined, container: undefined, physics: physics, draw: draw, @@ -19,6 +20,7 @@ function newGovernanceUserProfileSpace() { let timer = 0 thisObject.githubStars = new Map() + thisObject.githubWatchers = new Map() return thisObject @@ -64,14 +66,21 @@ function newGovernanceUserProfileSpace() { return - function onGithubStarsResponse(err, githubStarsArray) { + function onGithubStarsResponse(err, githubData) { /* Lets check the result of the call through the http interface */ - githubStarsArray = JSON.parse(githubStarsArray) + let githubGithubDataObject = JSON.parse(githubData) + let githubStarsArray = githubGithubDataObject.starsListArray + let githubWatchersArray = githubGithubDataObject.watchersListArray for (let i = 0; i < githubStarsArray.length; i++) { - githubUsername = githubStarsArray[i] + let githubUsername = githubStarsArray[i] thisObject.githubStars.set(githubUsername, true) } + + for (let i = 0; i < githubWatchersArray.length; i++) { + let githubUsername = githubWatchersArray[i] + thisObject.githubWatchers.set(githubUsername, true) + } } } From 1c00fd43510420b88dfbe32cf0dfe0fac6215b67 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 27 Jul 2021 20:46:46 +0200 Subject: [PATCH 5/7] getForks --- Client/httpInterface.js | 69 +++++++++++++++++-- .../UI/Function-Libraries/GithubProgram.js | 7 +- .../Spaces/User-Profile-Space/UserProfile.js | 13 +++- 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index e667bf113..f438a0bfa 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -1021,20 +1021,22 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'Gov': { switch (requestParameters[2]) { // switch by command - case 'getRepoInfo': { + case 'getGithubStars': { try { - const GITHUB_API_WAITING_TIME = 1000 + console.log('getRepoInfo') + const GITHUB_API_WAITING_TIME = 250 const repository = unescape(requestParameters[3]) const username = unescape(requestParameters[4]) const token = unescape(requestParameters[5]) let error let starsListArray = [] let watchersListArray = [] + let forksListArray = [] getRepoInfo() async function getRepoInfo() { - + console.log('doGithub') await doGithub() if (error !== undefined) { @@ -1051,9 +1053,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } let responseObject = { - starsListArray: starsListArray, - watchersListArray: watchersListArray + starsListArray: starsListArray, + watchersListArray: watchersListArray, + forksListArray: forksListArray } + console.log('responseObject', starsListArray.length, watchersListArray.length, forksListArray.length) respondWithContent(JSON.stringify(responseObject), httpResponse) } @@ -1065,9 +1069,12 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE auth: token, userAgent: 'Superalgos Beta 10' }) - + console.log('getStars') await getStars() - await getWatchers() + console.log('getWatchers') + await getWatchers() + console.log('getForks') + await getForks() async function getStars() { const repo = repository @@ -1164,6 +1171,54 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } } } + + async function getForks() { + const repo = repository + const owner = 'Superalgos' + const per_page = 100 // Max + let page = 0 + let lastPage = false + + while (lastPage === false) { + try { + page++ + await sleep(GITHUB_API_WAITING_TIME) + let forksListResponse = await octokit.repos.listForks({ + owner, + repo, + per_page, + page + }); + + if (forksListResponse.data.length < 100) { + lastPage = true + } + + for (let i = 0; i < forksListResponse.data.length; i++) { + let fork = forksListResponse.data[i] + forksListArray.push(fork.login) + } + + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks -> Forks Page = ' + page) + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks -> Forks Received = ' + forksListResponse.data.length) + + } catch (err) { + console.log(err) + + if (err.stack.indexOf('last page') >= 0) { + return + } else { + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->Method call produced an error.') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->commitMessage = ' + repository) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->username = ' + username) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->token ends with = ' + '...' + token.substring(token.length - 10)) + error = err + } + } + } + } } } catch (err) { diff --git a/Projects/Governance/UI/Function-Libraries/GithubProgram.js b/Projects/Governance/UI/Function-Libraries/GithubProgram.js index 7342847f4..65338d0c1 100644 --- a/Projects/Governance/UI/Function-Libraries/GithubProgram.js +++ b/Projects/Governance/UI/Function-Libraries/GithubProgram.js @@ -122,10 +122,12 @@ function newGovernanceFunctionLibraryGithubProgram() { let githubUsername = profileSignature.message node.payload.githubProgram.hasStar = UI.projects.governance.spaces.userProfileSpace.githubStars.get(githubUsername) node.payload.githubProgram.hasWatch = UI.projects.governance.spaces.userProfileSpace.githubWatchers.get(githubUsername) + node.payload.githubProgram.hasFork = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername) node.payload.githubProgram.engagement = 0 if (node.payload.githubProgram.hasStar === true) { node.payload.githubProgram.engagement++ } if (node.payload.githubProgram.hasWatch === true) { node.payload.githubProgram.engagement++ } + if (node.payload.githubProgram.hasFork === true) { node.payload.githubProgram.engagement++ } if ( node.payload.githubProgram.engagement > 0) { @@ -168,7 +170,7 @@ function newGovernanceFunctionLibraryGithubProgram() { programNode.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.") return } - const MAX_ENGAGEMENT = 2 + const MAX_ENGAGEMENT = 3 programNode.payload.githubProgram.awarded.tokens = programNode.payload.githubProgram.ownPower / totalPowerRewardRatio * programNode.payload.githubProgram.engagement / MAX_ENGAGEMENT drawProgram(programNode) @@ -203,6 +205,9 @@ function newGovernanceFunctionLibraryGithubProgram() { if (node.payload.githubProgram.hasWatch === true) { extraText = extraText + ' 1 Watch' } + if (node.payload.githubProgram.hasWatch === true) { + extraText = extraText + ' 1 Fork' + } node.tokensAwarded.payload.uiObject.setStatus('From' + extraText) } diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 6fd9ec107..426e6ed8f 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -4,6 +4,7 @@ function newGovernanceUserProfileSpace() { let thisObject = { githubStars: undefined, githubWatchers: undefined, + githubForks: undefined, container: undefined, physics: physics, draw: draw, @@ -21,6 +22,7 @@ function newGovernanceUserProfileSpace() { thisObject.githubStars = new Map() thisObject.githubWatchers = new Map() + thisObject.githubForks = new Map() return thisObject @@ -55,7 +57,7 @@ function newGovernanceUserProfileSpace() { UI.projects.education.spaces.docsSpace.sidePanelTab.open() return } - + console.log('httpRequest') httpRequest( undefined, 'Gov/getRepoInfo/' + @@ -67,10 +69,12 @@ function newGovernanceUserProfileSpace() { return function onGithubStarsResponse(err, githubData) { - /* Lets check the result of the call through the http interface */ + console.log(githubData) + /* Lets check the result of the call through the http interface */ let githubGithubDataObject = JSON.parse(githubData) let githubStarsArray = githubGithubDataObject.starsListArray let githubWatchersArray = githubGithubDataObject.watchersListArray + let githubForksArray = githubGithubDataObject.forksListArray for (let i = 0; i < githubStarsArray.length; i++) { let githubUsername = githubStarsArray[i] @@ -81,6 +85,11 @@ function newGovernanceUserProfileSpace() { let githubUsername = githubWatchersArray[i] thisObject.githubWatchers.set(githubUsername, true) } + + for (let i = 0; i < githubForksArray.length; i++) { + let githubUsername = githubForksArray[i] + thisObject.githubForks.set(githubUsername, true) + } } } From 34670b98a6e3fc37338203a26c20cf62b6353f06 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 27 Jul 2021 21:31:41 +0200 Subject: [PATCH 6/7] Forks Info Implementation working --- Client/httpInterface.js | 340 +++++++----------- .../UI/Function-Libraries/GithubProgram.js | 8 +- .../Spaces/User-Profile-Space/UserProfile.js | 63 +++- 3 files changed, 179 insertions(+), 232 deletions(-) diff --git a/Client/httpInterface.js b/Client/httpInterface.js index f438a0bfa..97d17c6e4 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -1022,224 +1022,136 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'Gov': { switch (requestParameters[2]) { // switch by command case 'getGithubStars': { - try { - console.log('getRepoInfo') - const GITHUB_API_WAITING_TIME = 250 - const repository = unescape(requestParameters[3]) - const username = unescape(requestParameters[4]) - const token = unescape(requestParameters[5]) - let error - let starsListArray = [] - let watchersListArray = [] - let forksListArray = [] - - getRepoInfo() - - async function getRepoInfo() { - console.log('doGithub') - await doGithub() - if (error !== undefined) { - - let docs = { - project: 'Governance', - category: 'Topic', - type: 'Gov Error - Get Repository Information', - anchor: undefined, - placeholder: {} - } - - respondWithDocsObject(docs, error) - return - } - - let responseObject = { - starsListArray: starsListArray, - watchersListArray: watchersListArray, - forksListArray: forksListArray - } - console.log('responseObject', starsListArray.length, watchersListArray.length, forksListArray.length) - respondWithContent(JSON.stringify(responseObject), httpResponse) - } - - async function doGithub() { - - const { Octokit } = require("@octokit/rest") - - const octokit = new Octokit({ - auth: token, - userAgent: 'Superalgos Beta 10' - }) - console.log('getStars') - await getStars() - console.log('getWatchers') - await getWatchers() - console.log('getForks') - await getForks() - - async function getStars() { - const repo = repository - const owner = 'Superalgos' - const per_page = 100 // Max - let page = 0 - let lastPage = false - - while (lastPage === false) { - try { - page++ - await sleep(GITHUB_API_WAITING_TIME) - let starsListResponse = await octokit.activity.listStargazersForRepo({ - owner, - repo, - per_page, - page - }); - - if (starsListResponse.data.length < 100) { - lastPage = true - } - - for (let i = 0; i < starsListResponse.data.length; i++) { - let star = starsListResponse.data[i] - starsListArray.push(star.login) - } - - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars -> Stars Page = ' + page) - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars -> Stars Received = ' + starsListResponse.data.length) - - } catch (err) { - console.log(err) - - if (err.stack.indexOf('last page') >= 0) { - return - } else { - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->Method call produced an error.') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->err.stack = ' + err.stack) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->commitMessage = ' + repository) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->username = ' + username) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->token starts with = ' + token.substring(0, 10) + '...') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getStars ->token ends with = ' + '...' + token.substring(token.length - 10)) - error = err - } - } - } - } - - async function getWatchers() { - const repo = repository - const owner = 'Superalgos' - const per_page = 100 // Max - let page = 0 - let lastPage = false - - while (lastPage === false) { - try { - page++ - await sleep(GITHUB_API_WAITING_TIME) - let watchersListResponse = await octokit.activity.listWatchersForRepo({ - owner, - repo, - per_page, - page - }); - - if (watchersListResponse.data.length < 100) { - lastPage = true - } - - for (let i = 0; i < watchersListResponse.data.length; i++) { - let watch = watchersListResponse.data[i] - watchersListArray.push(watch.login) - } - - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers -> Watchers Page = ' + page) - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers -> Watchers Received = ' + watchersListResponse.data.length) - - } catch (err) { - console.log(err) - - if (err.stack.indexOf('last page') >= 0) { - return - } else { - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->Method call produced an error.') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->err.stack = ' + err.stack) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->commitMessage = ' + repository) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->username = ' + username) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->token starts with = ' + token.substring(0, 10) + '...') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getWatchers ->token ends with = ' + '...' + token.substring(token.length - 10)) - error = err - } - } - } - } - - async function getForks() { - const repo = repository - const owner = 'Superalgos' - const per_page = 100 // Max - let page = 0 - let lastPage = false - - while (lastPage === false) { - try { - page++ - await sleep(GITHUB_API_WAITING_TIME) - let forksListResponse = await octokit.repos.listForks({ - owner, - repo, - per_page, - page - }); - - if (forksListResponse.data.length < 100) { - lastPage = true - } - - for (let i = 0; i < forksListResponse.data.length; i++) { - let fork = forksListResponse.data[i] - forksListArray.push(fork.login) - } - - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks -> Forks Page = ' + page) - console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks -> Forks Received = ' + forksListResponse.data.length) - - } catch (err) { - console.log(err) - - if (err.stack.indexOf('last page') >= 0) { - return - } else { - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->Method call produced an error.') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->err.stack = ' + err.stack) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->commitMessage = ' + repository) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->username = ' + username) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->token starts with = ' + token.substring(0, 10) + '...') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getForks ->token ends with = ' + '...' + token.substring(token.length - 10)) - error = err - } - } - } - } - } - - } catch (err) { - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> Method call produced an error.') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> err.stack = ' + err.stack) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> repository = ' + repository) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> username = ' + username) - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token starts with = ' + token.substring(0, 10) + '...') - console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token ends with = ' + '...' + token.substring(token.length - 10)) - - let error = { - result: 'Fail Because', - message: err.message, - stack: err.stack - } - respondWithContent(JSON.stringify(error), httpResponse) - } + getProfiles('activity', 'listStargazersForRepo') + break + } + case 'getGithubWatchers': { + getProfiles('activity', 'listWatchersForRepo') + break + } + case 'getGithubForks': { + getProfiles('repos', 'listForks') break } } + function getProfiles(endpoint, method) { + try { + const GITHUB_API_WAITING_TIME = 250 + const repository = unescape(requestParameters[3]) + const username = unescape(requestParameters[4]) + const token = unescape(requestParameters[5]) + let error + let githubListArray = [] + + getRepoInfo() + + async function getRepoInfo() { + await doGithub() + if (error !== undefined) { + + let docs = { + project: 'Governance', + category: 'Topic', + type: 'Gov Error - Get Repository Information', + anchor: undefined, + placeholder: {} + } + + respondWithDocsObject(docs, error) + return + } + + respondWithContent(JSON.stringify(githubListArray), httpResponse) + } + + async function doGithub() { + + const { Octokit } = require("@octokit/rest") + + const octokit = new Octokit({ + auth: token, + userAgent: 'Superalgos Beta 10' + }) + await getList() + + async function getList() { + const repo = repository + const owner = 'Superalgos' + const per_page = 100 // Max + let page = 0 + let lastPage = false + + while (lastPage === false) { + try { + page++ + await sleep(GITHUB_API_WAITING_TIME) + let listResponse = await octokit[endpoint][method]({ + owner, + repo, + per_page, + page + }); + + if (listResponse.data.length < 100) { + lastPage = true + } + + for (let i = 0; i < listResponse.data.length; i++) { + let listItem = listResponse.data[i] + let githubUsername + switch(endpoint) { + case 'activity' : { + githubUsername = listItem.login + break + } + case 'repos' : { + githubUsername = listItem.owner.login + break + } + } + //console.log(listItem) + + githubListArray.push(githubUsername) + } + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList -> ' + method + ' Page = ' + page) + console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList -> ' + method + ' Received = ' + listResponse.data.length) + + } catch (err) { + console.log(err) + + if (err.stack.indexOf('last page') >= 0) { + return + } else { + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->Method call produced an error.') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->repository = ' + repository) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->username = ' + username) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->token ends with = ' + '...' + token.substring(token.length - 10)) + error = err + } + } + } + } + } + + } catch (err) { + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> Method call produced an error.') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> repository = ' + repository) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> username = ' + username) + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token ends with = ' + '...' + token.substring(token.length - 10)) + + let error = { + result: 'Fail Because', + message: err.message, + stack: err.stack + } + respondWithContent(JSON.stringify(error), httpResponse) + } + } function respondWithDocsObject(docs, error) { if (error.message !== undefined) { diff --git a/Projects/Governance/UI/Function-Libraries/GithubProgram.js b/Projects/Governance/UI/Function-Libraries/GithubProgram.js index 65338d0c1..3fe817e10 100644 --- a/Projects/Governance/UI/Function-Libraries/GithubProgram.js +++ b/Projects/Governance/UI/Function-Libraries/GithubProgram.js @@ -200,13 +200,13 @@ function newGovernanceFunctionLibraryGithubProgram() { let extraText = '' if (node.payload.githubProgram.hasStar === true) { - extraText = extraText + ' 1 Star' + extraText = extraText + ' + 1 Star' } if (node.payload.githubProgram.hasWatch === true) { - extraText = extraText + ' 1 Watch' + extraText = extraText + ' + 1 Watch' } - if (node.payload.githubProgram.hasWatch === true) { - extraText = extraText + ' 1 Fork' + if (node.payload.githubProgram.hasFork === true) { + extraText = extraText + ' + 1 Fork' } node.tokensAwarded.payload.uiObject.setStatus('From' + extraText) diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 426e6ed8f..8fa131e74 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -57,35 +57,70 @@ function newGovernanceUserProfileSpace() { UI.projects.education.spaces.docsSpace.sidePanelTab.open() return } - console.log('httpRequest') - httpRequest( - undefined, - 'Gov/getRepoInfo/' + - 'Superalgos' + '/' + - config.username + '/' + - config.token - , onGithubStarsResponse) - return + requestStars() + + function requestStars() { + httpRequest( + undefined, + 'Gov/getGithubStars/' + + 'Superalgos' + '/' + + config.username + '/' + + config.token + , onGithubStarsResponse) + } + + function requestWatchers() { + httpRequest( + undefined, + 'Gov/getGithubWatchers/' + + 'Superalgos' + '/' + + config.username + '/' + + config.token + , onGithubWatchersResponse) + } + + function requestForks() { + httpRequest( + undefined, + 'Gov/getGithubForks/' + + 'Superalgos' + '/' + + config.username + '/' + + config.token + , onGithubForksResponse) + } function onGithubStarsResponse(err, githubData) { - console.log(githubData) + //console.log(githubData) /* Lets check the result of the call through the http interface */ - let githubGithubDataObject = JSON.parse(githubData) - let githubStarsArray = githubGithubDataObject.starsListArray - let githubWatchersArray = githubGithubDataObject.watchersListArray - let githubForksArray = githubGithubDataObject.forksListArray + let githubStarsArray = JSON.parse(githubData) for (let i = 0; i < githubStarsArray.length; i++) { let githubUsername = githubStarsArray[i] thisObject.githubStars.set(githubUsername, true) } + requestWatchers() + } + + function onGithubWatchersResponse(err, githubData) { + //console.log(githubData) + /* Lets check the result of the call through the http interface */ + let githubWatchersArray = JSON.parse(githubData) + for (let i = 0; i < githubWatchersArray.length; i++) { let githubUsername = githubWatchersArray[i] thisObject.githubWatchers.set(githubUsername, true) } + requestForks() + } + + function onGithubForksResponse(err, githubData) { + //console.log(githubData) + /* Lets check the result of the call through the http interface */ + let githubForksArray = JSON.parse(githubData) + for (let i = 0; i < githubForksArray.length; i++) { let githubUsername = githubForksArray[i] thisObject.githubForks.set(githubUsername, true) From b8e031856ce45af65f570481859f7c1af21dadee Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 27 Jul 2021 21:52:53 +0200 Subject: [PATCH 7/7] Github Program implemented. Reports still missing. --- .../UI/Spaces/Reports-Space/ReportsSpace.js | 3 +++ .../UI/Spaces/User-Profile-Space/UserProfile.js | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js b/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js index 29a701975..dc95dcf31 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js @@ -104,6 +104,9 @@ function newGobernanceReportsSpace() { } function initialize() { + /* + If the workspace is not related to governance, then we exit the Intialize Function + */ let resultsArary = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile') if (resultsArary.length === 0) { return } diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 8fa131e74..250d5b8e1 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -33,6 +33,12 @@ function newGovernanceUserProfileSpace() { at the Github Program. */ + /* + If the workspace is not related to governance, then we exit the Intialize Function + */ + let resultsArary = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile') + if (resultsArary.length === 0) { return } + /* Find the Username and Password */ let apisNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('APIs') if (apisNode === undefined) { @@ -58,7 +64,7 @@ function newGovernanceUserProfileSpace() { return } - requestStars() + requestStars() function requestStars() { httpRequest( @@ -102,7 +108,7 @@ function newGovernanceUserProfileSpace() { requestWatchers() } - + function onGithubWatchersResponse(err, githubData) { //console.log(githubData) /* Lets check the result of the call through the http interface */ @@ -115,7 +121,7 @@ function newGovernanceUserProfileSpace() { requestForks() } - + function onGithubForksResponse(err, githubData) { //console.log(githubData) /* Lets check the result of the call through the http interface */