Better handling of user fork
This commit is contained in:
1 parent
480d4121da
commit
f318bcdf15
3 files changed
+14
-63
No files matched your search
@@ -163,17 +163,14 @@ exports.newGithubServer = function newGithubServer() {
|
||||
}
|
||||
}
|
||||
|
||||
async function createGithubFork(repository, username, token) {
|
||||
async function createGithubFork(token) {
|
||||
try {
|
||||
username = unescape(username)
|
||||
token = unescape(token)
|
||||
|
||||
await doGithub()
|
||||
|
||||
async function doGithub() {
|
||||
try {
|
||||
//const repo = 'Superalgos'
|
||||
//const owner = username
|
||||
const { Octokit } = SA.nodeModules.octokit
|
||||
const octokit = new Octokit({
|
||||
auth: token,
|
||||
|
||||
@@ -1315,8 +1315,6 @@ exports.newHttpInterface = function newHttpInterface() {
|
||||
case 'createGithubFork': {
|
||||
|
||||
let serverResponse = await PL.servers.GITHUB_SERVER.createGithubFork(
|
||||
params.repository,
|
||||
params.username,
|
||||
params.token
|
||||
)
|
||||
|
||||
@@ -1355,8 +1353,21 @@ exports.newHttpInterface = function newHttpInterface() {
|
||||
|
||||
let error
|
||||
|
||||
await checkFork()
|
||||
await updateUser()
|
||||
|
||||
async function checkFork() {
|
||||
let serverResponse = await PL.servers.GITHUB_SERVER.createGithubFork(
|
||||
params.token
|
||||
)
|
||||
|
||||
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(serverResponse), httpResponse)
|
||||
|
||||
if(error != undefined) {
|
||||
console.log('[ERROR] httpInterface -> Gov -> createFork -> You already have a fork. Good for you!')
|
||||
}
|
||||
}
|
||||
|
||||
async function updateUser() {
|
||||
|
||||
await doGithubUser()
|
||||
|
||||
@@ -145,63 +145,6 @@ function newGovernanceFunctionLibraryProfileConstructor() {
|
||||
liquidProg.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
|
||||
liquidProg.payload.uiObject.menu.internalClick('Add Tokens Awarded')
|
||||
/*
|
||||
Check if the user already has the SA fork. If not, do it for them.
|
||||
*/
|
||||
|
||||
/*
|
||||
const hasFork = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername)
|
||||
if (hasFork === undefined) {
|
||||
// New user! Probably doesn't have a fork, so let's create it.
|
||||
let apisNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('APIs')
|
||||
if (apisNode === undefined) {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
return
|
||||
}
|
||||
if (apisNode.githubAPI === undefined) {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
return
|
||||
}
|
||||
|
||||
let config = JSON.parse(apisNode.githubAPI.config)
|
||||
if (config.username === undefined || config.username === "") {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
return
|
||||
}
|
||||
if (config.token === undefined || config.token === "") {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
|
||||
return
|
||||
}
|
||||
|
||||
let params = {
|
||||
method: 'createGithubFork',
|
||||
username: config.username,
|
||||
token: config.token,
|
||||
}
|
||||
|
||||
let url = 'GOV' // We will access the default Client GOV endpoint.
|
||||
|
||||
httpRequest(JSON.stringify(params), url, onResponse)
|
||||
|
||||
function onResponse(err, data) {
|
||||
|
||||
data = JSON.parse(data)
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
UI.projects.education.spaces.docsSpace.navigateTo('Governance', 'Topic', 'Gov Message - Automated User Profile Contribute Done')
|
||||
} else {
|
||||
if (data.docs === undefined) { return }
|
||||
UI.projects.education.spaces.docsSpace.navigateTo(
|
||||
data.docs.project,
|
||||
data.docs.category,
|
||||
data.docs.type,
|
||||
data.docs.anchor,
|
||||
undefined,
|
||||
data.docs.placeholder
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
We store at the User Profile the Signed githubUsername
|
||||
*/
|
||||
UI.projects.visualScripting.utilities.nodeConfig.saveConfigProperty(userProfile.payload, 'signature', response.signature)
|
||||
|
||||
Reference in new issue
Block a user