This commit is contained in:
Luis Fernando Molina committed 2021-07-27 20:46:46 +02:00
1 parent 030c21d372
commit 1c00fd4351
3 files changed
+79 -10

No files matched your search

+62 -7
View File
@@ -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) {
@@ -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)
}
@@ -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)
}
}
}