Skip to content

Instantly share code, notes, and snippets.

@tlvince tlvince/.gitignore
Last active Dec 15, 2015

What would you like to do?
Convert GitHub repository information to a directory of YAML files. See
fs = require 'fs'
https = require 'https'
yaml = require 'js-yaml'
moment = require 'moment'
path = require 'path'
url = require 'url'
querystring = require 'querystring'
out = 'build'
username = 'tlvince'
api = "{username}/repos"
getPageLinks = (link) ->
link = or if typeof link is "object" and ( or
links = {}
return links unless typeof link is "string"
link.replace /<([^>]*)>;\s*rel="([\w]*)\"/g, (m, uri, type) ->
links[type] = uri
getRepos = (uri) ->
uri = url.parse uri
query = querystring.parse uri.query
page = if then else 1
options =
hostname: uri.hostname
path: uri.path
headers: 'User-Agent': 'github2yaml'
console.log "Getting repositories from page #{page}"
https.get options, (res) ->
body = ''
res.on 'data', (chunk) ->
body += chunk
res.on 'end', ->
data = JSON.parse(body)
genYAML data
link =
next = getPageLinks(link).next if link
getRepos next if next
genYAML = (repos) ->
for repo in repos
console.log "Parsing #{}"
filename = "#{path.basename repo.html_url}.yaml"
file = path.join out, filename
repo =
date: moment(repo.created_at).format('YYYY-MM-DD HH:mm:ss ZZ')
url: repo.html_url
description: repo.description
fork: repo.fork
repo.tags = repo.language if repo.language
contents = yaml.dump repo
fs.writeFile file, contents, (err) ->
throw err if err
fs.mkdir out
getRepos api
"name": "github-to-yaml",
"version": "0.1.0",
"description": "Convert GitHub repository information to a directory of YAML files",
"main": "",
"repository": "",
"keywords": [
"author": "Tom Vincent",
"license": "MIT",
"readmeFilename": "readme.mkd",
"dependencies": {
"coffee-script": "~1.6.1",
"js-yaml": "~2.0.3",
"moment": "~2.0.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.