Github Watchers Implemented at Github Program
This commit is contained in:
1 parent
dae1164d3c
commit
030c21d372
3 files changed
+120
-43
No files matched your search
+95
-37
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user