-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:BharatKammakatla/Developer-Portfolio
- Loading branch information
Showing
14 changed files
with
307 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
#user generated content | ||
public/profile.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var fs = require("fs"); | ||
const https = require("https"); | ||
var process = require("process"); | ||
require("dotenv").config(); | ||
|
||
const GITHUB_TOKEN = process.env.REACT_APP_GITHUB_TOKEN; | ||
const GITHUB_USERNAME = process.env.GITHUB_USERNAME; | ||
|
||
if (GITHUB_USERNAME === undefined) { | ||
throw "Github Username was found to be undefined. Please set an Environment variable."; | ||
} | ||
|
||
console.log(`fetching profile for ${GITHUB_USERNAME}`); | ||
var data = JSON.stringify({ | ||
query: ` | ||
{ | ||
user(login:"${GITHUB_USERNAME}") { | ||
name | ||
bio | ||
isHireable | ||
avatarUrl | ||
location | ||
pinnedItems(first: 6, types: [REPOSITORY]) { | ||
totalCount | ||
edges { | ||
node { | ||
... on Repository { | ||
name | ||
description | ||
forkCount | ||
stargazers { | ||
totalCount | ||
} | ||
url | ||
id | ||
diskUsage | ||
primaryLanguage { | ||
name | ||
color | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
}); | ||
const default_options = { | ||
hostname: "api.github.com", | ||
path: "/graphql", | ||
port: 443, | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${GITHUB_TOKEN}`, | ||
"User-Agent": "Node", | ||
}, | ||
}; | ||
|
||
const req = https.request(default_options, (res) => { | ||
let data = ""; | ||
console.log(`statusCode: ${res.statusCode}`); | ||
if (res.statusCode != 200) { | ||
throw "The request to Github didn't suceed. Maybe check Github Token?"; | ||
} | ||
|
||
res.on("data", (d) => { | ||
data += d; | ||
}); | ||
res.on("end", () => { | ||
fs.writeFile("./public/profile.json", data, function (err) { | ||
if (err) return console.log(err); | ||
console.log("saved file to public/profile.json"); | ||
}); | ||
}); | ||
}); | ||
|
||
req.on("error", (error) => { | ||
throw error; | ||
}); | ||
|
||
req.write(data); | ||
req.end(); |
Oops, something went wrong.