Skip to content

Instantly share code, notes, and snippets.

@yjukaku
Created March 19, 2020 16:00
Show Gist options
  • Save yjukaku/bf313a325b454278b3a112716ba619c1 to your computer and use it in GitHub Desktop.
Save yjukaku/bf313a325b454278b3a112716ba619c1 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# This script will take the ticket number from your current git branch and prepend it to your
# commit so you don't have to type it yourself.
# Run it either like this `./jira_commit Your commit message here`
# or just as `./jira_commit ` and enter your commit message when prompted
current = `git branch`.split("\n").detect{|l| l.start_with?("*")}.gsub("* ", "").strip
ticket = current.match(/(qweb-\d+)/)[1].upcase
message =
if ARGV.any?
ARGV.join(" ")
else
STDOUT.write "Enter a commit message for #{ticket}: "
STDIN.gets.strip
end
puts "Needs a message" && exit(1) if message.nil? || message.empty?
puts "Ticket #{ticket}"
system("git commit -m \"#{ticket.upcase} #{message}\"") && exit(0)
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment