mirror of
https://github.com/zhigang1992/probot.github.io.git
synced 2026-01-12 22:49:53 +08:00
30 lines
792 B
Ruby
Executable File
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
|