Created
March 5, 2014 08:27
-
-
Save malclocke/9363308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Usage: ./offline_pull_requests.rb user/repo | |
# | |
require 'octokit' | |
require 'erb' | |
require 'redcarpet' | |
def filename_for(pull) | |
'%d.html' % pull.number | |
end | |
pull_request_erb = <<-EOT | |
<h1><%= pull.title %></h1> | |
<%= markdown.render(pull.body) %> | |
<h2>Comments</h2> | |
<% comments.each do |comment| %> | |
<hr> | |
<%= markdown.render(comment.body) %> | |
<p>~ <%= comment.user.login %></p> | |
<% end %> | |
EOT | |
index_erb = <<-EOT | |
<h1>Pull requests for <%= repo %></h1> | |
<ul> | |
<% pulls.each do |pull| %> | |
<li> | |
<a href="<%= filename_for(pull) %>"><%= pull.number %> - <%= pull.title %></a> | |
</li> | |
<% end %> | |
EOT | |
repo = ARGV[0] | |
client = Octokit::Client.new :netrc => true | |
markdown = Redcarpet::Markdown.new( | |
Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true | |
) | |
pulls = Octokit.pull_requests(repo, :state => 'open') | |
pull_request_template = ERB.new(pull_request_erb) | |
pulls.each do |pull| | |
comments = Octokit.issue_comments(repo, pull.number) | |
f = File.open(filename_for(pull), 'w') | |
f.puts pull_request_template.result(binding) | |
f.close | |
end | |
index_template = ERB.new(index_erb) | |
f = File.open('index.html', 'w') | |
f.puts index_template.result(binding) | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment