Skip to content

Commit

Permalink
✨ Add GitHub repos generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Sep 23, 2017
1 parent 5a9056a commit 5781826
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GITHUB_TOKEN=YOUR_GITHUB_TOKEN
GITHUB_USERNAME=YOUR_GITHUB_USERNAME
GITHUB_MAX_REPOS=4
47 changes: 47 additions & 0 deletions scripts/fetch-github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require('dotenv').config()
const fetch = require('node-fetch')

const { GITHUB_TOKEN, GITHUB_USERNAME, GITHUB_MAX_REPOS } = process.env
const GITHUB_ENDPOINT = 'https://api.github.com/graphql'

const query = `query ($login: String!, $first: Int!) {
repositoryOwner(login: $login) {
... on User {
pinnedRepositories(first: $first) {
edges {
node {
name
description
primaryLanguage {
name
color
}
stargazers {
totalCount
}
forks {
totalCount
}
}
}
}
}
}
}`

const variables = {
login: GITHUB_USERNAME,
first: GITHUB_MAX_REPOS
}

fetch(GITHUB_ENDPOINT, {
method: 'POST',
headers: {
'Authorization': `Bearer ${GITHUB_TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query, variables })
})
.then(res => res.json())
.then(data => JSON.stringify(data, null, 2))
.then(console.log)

0 comments on commit 5781826

Please sign in to comment.