Files
probot.github.io/script/sync-data
Brandon Keepers 885ece0ffc Update sync script
This fixes it to work whether or not the frontmatter contains existing keys or not
2017-09-30 00:09:12 -05:00

30 lines
792 B
Ruby
Executable File

#!/usr/bin/env ruby
# Sync data for apps from GitHub
require "bundler/setup"
require "open-uri"
require "octokit"
require "yaml"
client = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
files = ARGV[0] ? [ARGV[0]] : Dir.glob('_apps/*.md')
files.each do |path|
app = YAML.load_file(path)
puts "Syncing #{app['repository']}"
repo = client.repository(app['repository'])
app['stars'] = repo[:stargazers_count]
app['updated'] = repo[:pushed_at].to_s
if app['host']
stats = JSON.parse(URI(app['host'] + '/stats').open.read)
app['installations'] = stats['installations']
app['organizations'] = stats['popular'].map { |org| org['login'] }
end
content = File.read(path)
content.sub!(/---(.*?)---/m, "#{YAML.dump(app)}---")
File.write(path, content)
end