Created
November 10, 2022 02:57
-
-
Save namnv609/0af7ee43e98d4a88633ff410b286fcd5 to your computer and use it in GitHub Desktop.
Generate PR desc for my project
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 | |
require "optparse" | |
require "fileutils" | |
options = {} | |
current_work_dir = ::File.expand_path(::File.dirname(__FILE__)) | |
current_date_time = Time.now.strftime("%Y%m%d-%H%M") | |
OptionParser.new do |opts| | |
opts.banner = "Usage: ./gen-pr-desc [options]" | |
opts.on("-tTICKET_ID", "--ticket-id TICKET_ID", "Ticket ID. Empty to default branch name") do |ticket_id| | |
options[:ticket_id] = ticket_id | |
end | |
opts.on("-mMILESTONE", "--milestone MILESTONE", "Milestone. Empty to current milestone") do |milestone| | |
options[:milestone] = milestone | |
end | |
end.parse! | |
unless options[:ticket_id] | |
current_branch = %x(git rev-parse --abbrev-ref HEAD).match(/(^MB\-[0-9]{1,})/) | |
options[:ticket_id] = current_branch[0] if current_branch | |
end | |
options[:milestone] = %x(git branch | cut -c 3- | grep -E "^milestone_").strip unless options[:milestone] | |
unless options[:milestone] && options[:ticket_id] | |
puts "Ticket ID and Milestone is required" | |
exit 1 | |
end | |
pr_descs_dir = ::File.join(current_work_dir, "my_scripts", "pr-descs") | |
target_pr_desc_dir = ::File.join(pr_descs_dir, options[:milestone]) | |
src_pr_desc_file = ::File.join(current_work_dir, "my_scripts", "merge_request_template.md") | |
dest_pr_desc_file = ::File.join(target_pr_desc_dir, "#{options[:ticket_id].downcase}-#{current_date_time}.md") | |
::FileUtils.mkdir_p(target_pr_desc_dir, verbose: true) | |
::FileUtils.cp(src_pr_desc_file, dest_pr_desc_file, verbose: true) | |
system("subl #{src_pr_desc_file}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment