Skip to content

Instantly share code, notes, and snippets.

@egoens
Created April 5, 2018 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egoens/2f3dc48c480050538da3ebdc6663ca66 to your computer and use it in GitHub Desktop.
Save egoens/2f3dc48c480050538da3ebdc6663ca66 to your computer and use it in GitHub Desktop.
Github issue opener. Opens issues from a csv file format.
require 'optparse'
require 'csv'
# requires `ghi` gem is installed on your machine https://github.com/stephencelis/ghi
# As a protection mechanism, the actual generation of issues is commented out.
# when you've tested the output, the uncomment the `ghi` line in the try/accept
# block towards the bottom of this file
# ghi [command] -- [repo]
# example ghi list -- unizin/engage
options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: github-issue-creator-csv.rb [options]'
opts.on('-f', '--filename FILE_NAME', 'File name') { |v| options[:file_name] = v }
opts.on('-r', '--reponame REPO_NAME', 'Repo name') { |v| options[:repo_name] = v }
opts.on('-l', '--label LABEL_NAME', 'Label name (optional)') { |v| options[:label_name] = v }
end.parse!
puts "REPONAME: #{options[:repo_name]}"
# make sure file name is past in as a cli arg
if options[:file_name].nil?
puts("
You must pass in a file path using the '-f' argument.
Example: 'ruby github-issue-creator-csv.rb -f ~/username/filename.csv'
Run 'ruby github-issue-creator-csv.rb -h' for help
")
elsif options[:repo_name] == '' || options[:repo_name].nil?
puts("
You must specify a repo using the '-r' argument.
Example: 'ruby github-issue-creator-csv.rb -r unizin/engage'
Run 'ruby github-issue-creator-csv.rb -h' for help
")
else
# parse content if file exists, otherwise raise error
begin
CSV.foreach(options[:file_name], quote_char: '"', col_sep: ',', row_sep: :auto, headers: true) do |row|
message = "#{row['View']}: #{row['Issue']}
# Problem
#{row['Problem']}
# Solution
#{row['Solution']}
"
puts "ghi open -m '#{message}' -L '#{options[:label_name]}' -- #{options[:repo_name]}"
# `ghi open -m "#{message}" -L "#{options[:label_name]}" -- #{options[:repo_name]}`
end
rescue Exception => msg
puts msg
end
end
View Issue Problem Solution
Application view What should the GH issue title be What problem is to be solved How will we solve the problem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment