Created
August 6, 2019 15:34
-
-
Save ryangreenberg/ca240600494f1d36df429eefc7da1e0e to your computer and use it in GitHub Desktop.
prn.rb - Pull request notes
This file contains hidden or 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 | |
# prn = pull request notes | |
# TODO: Better name | |
# PRN is an abbreviation for the Latin term, "pro re nata" which loosely translates to "as needed." | |
# | |
# This tool opens notes for the current pull request in a text file named for the current branch. | |
require 'fileutils' | |
DEFAULT_LOCATION = File.expand_path('~/Desktop') | |
# Use Desktop by default | |
notes_dir_path = if ENV['PR_NOTES_DIRECTORY'] | |
File.expand_path(ENV['PR_NOTES_DIRECTORY']) | |
else | |
warn "No value set for PR_NOTES_DIRECTORY, using default location #{DEFAULT_LOCATION}" | |
DEFAULT_LOCATION | |
end | |
current_branch = `git rev-parse --abbrev-ref HEAD`.strip | |
notes_path = File.join(notes_dir_path, "#{current_branch}.md") | |
unless File.exists?(notes_path) | |
# Create new file using a template | |
content = [ | |
"# #{current_branch}", | |
'', | |
] | |
# Extract the JIRA from the branch name and create a | |
# `Issue: []()` link in the body | |
jira = current_branch.match(/([A-Z]+-[0-9]+)_/) | |
if jira | |
issue = jira[1] | |
content << "Issue: [#{issue}](https://jira.example.com/browse/#{issue})" | |
end | |
File.open(notes_path, 'a') do |file| | |
file.puts content.join("\n") | |
end | |
end | |
warn "Opening #{notes_path}..." | |
system("open '#{notes_path}'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment