Skip to content

Instantly share code, notes, and snippets.

@postmodern
Last active January 23, 2022 09:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save postmodern/d168aeaf426236d5c8cf2fe7fa9cff05 to your computer and use it in GitHub Desktop.
Save postmodern/d168aeaf426236d5c8cf2fe7fa9cff05 to your computer and use it in GitHub Desktop.
Quick and dirty ruby script to parse a copy/pasted list of GitHub Issues and output a nicely formatted markdown list that can be pasted into a blog post
#!/usr/bin/env ruby
require 'optparse'
USAGE = "usage: #{$0} [options] GITHUB_REPO_URL [FILE]"
optparser = OptionParser.new do |opts|
opts.banner = USAGE
opts.separator ''
opts.separator 'Options:'
opts.on('-h','--help','Print this cruft') do
puts opts
exit
end
opts.separator ''
opts.separator 'Arguments:'
opts.separator "\tGITHUB_REPO_URL\t\tThe URL to the github.com repo"
opts.separator "\tFILE\t\t\tOptional file to parse. Defaults to parsing STDIN"
opts.separator ''
opts.separator 'Parses a list of GitHub Issues and outputs a markdown list'
end
optparser.parse!(ARGV)
if ARGV.length == 0
$stderr.puts(USAGE)
exit -1
end
github_repo_url = ARGV[0].chomp('/') # delete any extra trailing /
github_repo_name = File.basename(github_repo_url)
input = if ARGV[1] then File.open(ARGV[1])
else $stdin
end
markdown_list = []
markdown_links = []
issue_title = nil
issue_number = nil
begin
input.each_line do |line|
line.chomp!
if line =~ /^[A-Z]/
issue_title = line.gsub('*',"\\*") # escape any astericks
elsif line =~ /^#\d+/
match = line.match(/^#(\d+)/)
issue_number = match[1].to_i
markdown_list << "[#{issue_title}][#{github_repo_name}##{issue_number}]"
markdown_links << "[#{github_repo_name}##{issue_number}]: #{github_repo_url}/issues/#{issue_number}"
issue_title = nil
issue_number = nil
end
end
rescue Interrupt
exit 130
end
puts
markdown_list.each do |entry|
puts "* #{entry}"
end
puts
markdown_links.each do |entry|
puts entry
end
@postmodern
Copy link
Author

Please @github, add some sort of "Export to CSV" or "Export to Markdown" option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment