class Object
Public Instance Methods
confirm?()
click to toggle source
# File bin/git-jira, line 86 def confirm? $stdout.write 'Go? [y/N]: ' exit unless $stdin.gets.chomp =~ /y/i $stdout.puts end
current_branch()
click to toggle source
# File bin/git-jira, line 82 def current_branch `git rev-parse --abbrev-ref HEAD`.strip end
load_story(story)
click to toggle source
# File bin/git-jira, line 43 def load_story(story) body = `jira view #{story} 2>&1` if body =~ /404 Not Found/ raise StoryNotFound, "Story #{story} not found" end begin YAML.load(body) rescue Psych::SyntaxError # go-jira's YAML is not quite equal to ruby's YAML - if the body of the # description or comments fields has a " foo:" line, then ruby won't be # able to parse it # HACK: replace those fields with a double-quoted value. body = body.each_line.map do |line| # if the line contains colons or brackets or quotes, escape them match = line.match(/^([a-z]+): .*(: |[<>'"\[\]])/) if match "#{match[1]}: #{line[(match[1].length + 2)..-1].strip.inspect}" else line end end.join("\n") return YAML.load(body) end end
matches_story?(string)
click to toggle source
# File bin/git-jira, line 78 def matches_story?(string) string =~ /[a-z]{2,3}-[0-9]+/i end
pick_story_of_mine()
click to toggle source
# File bin/git-jira, line 92 def pick_story_of_mine my_stories = `jira ls -q 'assignee = currentUser() AND (status = "To Do" OR status = Backlog OR status = "In Progress")'`.strip.split("\n") branches = story_branches my_stories = my_stories .map { |s| s.split(':', 2) } .find_all { |s| !branches.include?(s[0].downcase) } puts "which story to start?" my_stories.each_with_index do |story, i| puts "#{i}: #{story.join(' ')}" end my_stories[gets.strip.to_i][0] end
story_branches()
click to toggle source
# File bin/git-jira, line 71 def story_branches `git branch` .strip.each_line.map(&:split).map(&:last) .delete_if { |b| !matches_story?(b) } .map(&:downcase) end
time_ago_in_words(distance_in_seconds)
click to toggle source
# File bin/git-jira, line 105 def time_ago_in_words(distance_in_seconds) distance_in_minutes = (distance_in_seconds / 60.0).round distance_in_hours = (distance_in_minutes / 60.0).round distance_in_days = (distance_in_hours / 24.0).floor case distance_in_seconds when 0..60 'less than a minute ago' when 60..2700 "about #{distance_in_minutes} minutes ago" when 2700..86400 "about #{(distance_in_minutes / 60).round} hours ago" else "#{distance_in_days} days ago" end end