Created
February 14, 2018 21:01
-
-
Save korneliakobiela/cdba65f0d45a1f8dfd979c81c8dbb558 to your computer and use it in GitHub Desktop.
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
const fetch = require('node-fetch'); | |
const http = require('http'); | |
const fs = require('fs') | |
var url = require('url'); | |
const reducer = (accumulator, currentValue) => accumulator + currentValue.contributions; | |
fetch('https://api.github.com/repos/sindresorhus/caprine') | |
.then(res => res.json()) | |
.then((json) => { | |
var out = {} | |
out.forks = json.forks; | |
out.open_issues = json.open_issues; | |
out.watchers = json.watchers; | |
out.stargazers = json.stargazers_count; | |
out.subscribers = json.subscribers_count; | |
fetch('https://api.github.com/repos/sindresorhus/caprine/contributors') | |
.then(res => res.json()) | |
.then((json) => { | |
out.contributors_count = json.length; | |
out.commits = json.reduce(reducer, 0); | |
out.total_lines = 1372; | |
out.code_lines = 1216; | |
console.log(JSON.stringify(out)); | |
fs.writeFile("out.json", JSON.stringify(out), function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("The file was saved!"); | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment