Skip to content

Instantly share code, notes, and snippets.

@brianmichel
Last active September 6, 2017 21:30
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 brianmichel/b6cd316f4ffed77219a32f0ca7d3c24b to your computer and use it in GitHub Desktop.
Save brianmichel/b6cd316f4ffed77219a32f0ca7d3c24b to your computer and use it in GitHub Desktop.
Scrape Clubhouse.io tickets from git logs.
#!/usr/bin/env ruby
require 'optparse'
options = {
repo: File.expand_path(`pwd`),
verbose: false
}
parser = OptionParser.new do |opts|
opts.banner = 'Usage: pennant.rb -p TAG_PATTERN'
opts.on('-p', '--pattern TAG_PATTERN', 'Pattern to look up tags with') do |p|
options[:pattern] = p
end
opts.on('-r', '--repo-path [PATH]', 'Path to Git repo to search through (current path will be used if not supplied)') do |r|
options[:repo] = File.expand_path(r)
end
opts.on('-v', '--verbose', 'Print debug logging') do |d|
options[:verbose] = d
end
end
begin
parser.parse!
unless options[:repo] && options[:pattern]
puts "Missing options!"
puts parser.help
exit 2
end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => error
puts error
puts parser
exit 2
end
full_repo = "#{options[:repo]}/.git"
previous_commit_command = "git --git-dir #{full_repo} tag -l #{options[:pattern]} --sort=-refname | head -n1"
previous_commitish = `#{previous_commit_command}`.chomp!
current_commitish = 'HEAD'
commits_command = "git --git-dir #{full_repo} log #{previous_commitish}...#{current_commitish}"
formatted_commits_command = "#{commits_command} --format=oneline"
if options[:verbose]
puts "Running '#{previous_commit_command}' to determine previous Git marker..."
puts "Found #{previous_commitish} as previous Git marker..."
puts "Using #{current_commitish} as current Git marker..."
puts "Running '#{commits_command}' to locate commits between commitish markers..."
puts "----"
end
commits = `#{commits_command}`
formatted_commits = `#{formatted_commits_command}`
matches = commits.scan(/(ch[0-9]+)/).flatten.uniq
completed_stories = ""
for match in matches do
story_url = "https://app.clubhouse.io/ando/story/#{match[2..-1]}"
completed_stories += "* [#{story_url}](#{story_url})\n"
end
changelog = <<EOF
# Changelog from `#{previous_commitish}` to `#{current_commitish}`
\n## Clubhouse Tickets\n
#{completed_stories}
\n## All Commits\n
```
#{formatted_commits}
```
EOF
puts changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment