Skip to content

Instantly share code, notes, and snippets.

@matiasgarciaisaia
Created December 13, 2016 00:43
Show Gist options
  • Save matiasgarciaisaia/d76c2d45a55c4174e491b889bdc6006f to your computer and use it in GitHub Desktop.
Save matiasgarciaisaia/d76c2d45a55c4174e491b889bdc6006f to your computer and use it in GitHub Desktop.
Dumping a repo's stargazers' information to a JSON
source 'https://rubygems.org'
gem "octokit", "~> 4.0"
gem "highline", "~> 1.7"
#!/usr/bin/env ruby
require 'octokit'
require 'highline/import'
username = ENV['GITHUB_USER'] || ask("GitHub user:")
password = ENV['GITHUB_PASSWORD'] || ask("Password:") {|q| q.echo = false}
repo = ENV['STARGAZERS_REPO'] || ask("Repo (org/repo):")
client = Octokit::Client.new login: username, password: password, auto_paginate: true
stargazers = client.stargazers(repo)
users = stargazers.map { |stargazer|
client.user(stargazer.login).to_hash
}
File.open("#{repo.sub '/', '_-_'}_stargazers.json", 'w') { |f|
f.puts users.to_json
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment