mirror of
https://github.com/zhigang1992/probot.github.io.git
synced 2026-01-12 22:49:53 +08:00
30 lines
899 B
Ruby
Executable File
30 lines
899 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# Sync star counts from GitHub
|
|
|
|
require 'open-uri'
|
|
|
|
require "octokit"
|
|
client = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
|
|
|
|
require "jekyll"
|
|
config = Jekyll.configuration("source" => File.expand_path('../', File.dirname(__FILE__)))
|
|
site = Jekyll::Site.new(config)
|
|
site.read
|
|
|
|
site.collections["apps"].docs.each do |app|
|
|
puts "Syncing #{app['repository']}"
|
|
repo = client.repository(app['repository'])
|
|
|
|
content = File.read(app.path)
|
|
content.sub!(/^stars: \d+$/, "stars: #{repo[:stargazers_count]}")
|
|
|
|
if app['host']
|
|
stats = JSON.parse(URI(app['host'] + '/stats').open.read)
|
|
content.sub!(/^installations: \d+$/, "installations: #{stats['installations']}")
|
|
yaml = YAML.dump(stats['popular'].map { |org| org['login'] }).sub('---', '')
|
|
content.sub!(/^organizations:\n(- .*\n)*/, "organizations:#{yaml}")
|
|
end
|
|
|
|
File.write(app.path, content)
|
|
end
|