Skip to content

Commit

Permalink
Merge branch 'master' of github.com:BharatKammakatla/Developer-Portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
BharatKammakatla committed Sep 16, 2023
2 parents 8e8ed9d + 21d0361 commit f194065
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 430 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: Build and Deploy
env:
CI: false
REACT_APP_GITHUB_TOKEN: ${{ secrets.OPEN_SOURCE_TOKEN }}
GITHUB_USERNAME: ${{ github.repository_owner }}
REACT_APP_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
branches:
- master
schedule:
- cron: "0 12 * * 1"
jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

#user generated content
public/profile.json
83 changes: 83 additions & 0 deletions fetch.js
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();
Loading

0 comments on commit f194065

Please sign in to comment.