Forks Info Implementation working
This commit is contained in:
1 parent
1c00fd4351
commit
34670b98a6
3 files changed
+179
-232
No files matched your search
+126
-214
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user