Skip to content

Instantly share code, notes, and snippets.

@runeleaf
Created May 20, 2014 09:36
Show Gist options
  • Save runeleaf/3f5737446403ac49489e to your computer and use it in GitHub Desktop.
Save runeleaf/3f5737446403ac49489e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# 1. PIVOTAL API TOKENの取得
#
# 2. スクリプトの置き場所
# ~/bin/git-start
#
# 3. プロジェクトの指定
# cd PROJECT_DIR
# echo PIVOTALプロジェクト番号 > .gitproject
#
# 4. コマンド
# git start チケット番号
#
require 'json'
require 'open3'
puts "git start command."
PIVOTAL_API_TOKEN="please your pivotal tracker api token."
PROJECT_FILE=".gitproject"
raise("no such file or directory - .gitproject") unless File.exist?(PROJECT_FILE)
PROJECT_ID=File.read(PROJECT_FILE).strip
STORY_ID=ARGV[0]
raise("no project id.") if PROJECT_ID.to_s.empty?
raise("no story id.") if STORY_ID.to_s.empty?
AUTHOR=`git log --pretty=format:"%an" -1`
REVISION=`git log --pretty=format:"%H" -1`
MESSAGE=`git log --pretty=format:"%s" -1`
URL=`git log --pretty=format:"https://git.raw-hide.jp/banana/commit/%H" -1`
COMMAND1=%Q(curl -X GET -H "X-TrackerToken: #{PIVOTAL_API_TOKEN}" "https://www.pivotaltracker.com/services/v5/me")
o, e, s = Open3.capture3(COMMAND1)
res = JSON.parse(o)
raise("blank owner. please get pivotal tracker api token.") if res["id"].to_s.empty?
owner_id = res["id"]
COMMAND2=%Q(curl -H "X-TrackerToken: #{PIVOTAL_API_TOKEN}" -X PUT -H "Content-Type: application/json" -d '{"current_state":"started","owner_ids":[#{owner_id}]' https://www.pivotaltracker.com/services/v5/projects/#{PROJECT_ID}/stories/#{STORY_ID})
# ticket start
o, e, s = Open3.capture3(COMMAND2)
res = JSON.parse(o)
raise("failed to start the ticket.") unless res["current_state"].eql?("started")
puts "pivotal status -> started."
# git checkout -b feature/$STORY_ID
`git checkout -b feature/#{STORY_ID}`
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment