From d3af079e0e5ffaaefd3ed78fb7ee0196f6c1de6a Mon Sep 17 00:00:00 2001 From: dougmcbride Date: Fri, 20 Nov 2009 22:15:33 -0800 Subject: [PATCH] keep track of last mentioned story/project and let a user choose them --- trakbot.rb | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/trakbot.rb b/trakbot.rb index 5abdcab..5bbcaf4 100644 --- a/trakbot.rb +++ b/trakbot.rb @@ -58,9 +58,11 @@ def initialize(options) "initials [nick] : Teach me your nick's (or another nick's) Pivotal Tracker initials", "list found: List results of the last find (even if it's long).", "new feature|chore|bug|release : Create a story in the project's Icebox with given name", + "project: Set your current project to the last mentioned project", "project |: Set your current project", "projects: List all known projects", "status: Show current project and story", + "story: Set your current story to the last mentioned story", "story : Set your current story", "story current_state unstarted|started|finished|delivered|rejected|accepted: Update the story", "story name|estimate : Update the story", @@ -76,8 +78,10 @@ def initialize(options) ".f = find ", ".l = list found", ".n(f|c|b|r) = new feature|chore|bug|release ", + ".p = project", ".p = project |", ".ps = projects", + ".s = story", ".s = story ", ".s(n|e) = story name|estimate ", ".se = story estimate ", @@ -111,6 +115,7 @@ def initialize(options) user = User.for_nick nick user.current_project_id = match[1] reply event, "#{nick}, you're on #{user.current_project.name}." + @last_project = user.current_project end project_set_by_name = lambda do |nick, event, match| @@ -124,6 +129,7 @@ def initialize(options) else user.current_project_id = projects.first.id reply event, "#{nick}, you're on #{user.current_project.name}." + @last_project = user.current_project end end @@ -149,6 +155,8 @@ def initialize(options) user = User.for_nick nick story = user.create_story :name => match[2], :story_type => match[1] reply event, "Added story #{story.id}" + @last_story = story + @last_project = user.current_project end create_story_short = lambda do |nick, event, match| @@ -163,6 +171,8 @@ def initialize(options) fail IndexError unless story = user.found_stories[match[1].to_i - 1] user.current_story_id = story.id reply event, "#{nick}'s current story: #{user.current_story.name}" + @last_story = user.current_story + @last_project = user.current_project rescue NoSearchError reply event, "#{nick}, you haven't done a search, and that's too short to be a Pivotal Tracker id." rescue IndexError @@ -177,6 +187,8 @@ def initialize(options) user = User.for_nick nick user.current_story_id = match[1] reply event, "#{nick}'s current story: #{user.current_story.name}" + @last_story = user.current_story + @last_project = user.current_project rescue RestClient::ResourceNotFound reply event, "#{nick}, I couldn't find that one. Maybe it's not in your current project (#{user.current_project.name})?" end @@ -188,6 +200,8 @@ def initialize(options) fail ChoreFinishedError if user.current_story.story_type == 'chore' and match[1] == 'current_state' and match[2] == 'finished' user.update_story match[1] => match[2] reply event, "#{user.current_story.id}: #{match[1]} --> #{match[2]}" + @last_story = user.current_story + @last_project = user.current_project rescue RestClient::ResourceNotFound reply event, "#{nick}, I couldn't find that one. Maybe it's not in your current project (#{user.current_project.name})?" rescue ChoreFinishedError @@ -291,13 +305,37 @@ def update_story_attribute(attribute, nick, event, match) reply event, "#{nick}'s story: #{user.current_story.story_type.capitalize} #{user.current_story.id}: #{user.current_story.name}" if user.current_story end + set_last_story = lambda do |nick, event, match| + user = User.for_nick nick + if @last_story + user.current_story = @last_story + user.current_project_id = @last_project.id + reply event, "#{nick}'s current story: #{user.current_story.name}" + else + reply event, "No last-mentioned story to use, sorry." + end + end + + set_last_project = lambda do |nick, event, match| + user = User.for_nick nick + if @last_project + user.current_project_id = @last_project.id + reply event, "#{nick}'s current project: #{user.current_project.name}" + else + reply event, "No last-mentioned project to use, sorry." + end + end + + add_trackbot_actions({ %w[token (\S+)] => set_token, %w[initials (\w+)] => set_initials_self, %w[initials (\w+) (\w+)] => set_initials_other, %w[(?:new|add) (feature|chore|bug|release) (.+)] => create_story, + %w[project] => set_last_project, %w[project (\d+)] => project_set_by_id, - %w[project (.*[a-z].*)] => project_set_by_name, + %w[project ([a-z]+.*)] => project_set_by_name, + %w[story] => set_last_story, %w[story (\d{1,3})] => set_story_from_list, %w[story (\d{4,})] => set_story_from_id, %w[story (story_type|estimate|current_state|name) (.+)] => @update_story, @@ -316,9 +354,11 @@ def update_story_attribute(attribute, nick, event, match) add_short_tracker_actions({ %w[h] => send_help, + %w[p] => set_last_project, %w[p (\d+)] => project_set_by_id, - %w[p (.*[a-z].*)] => project_set_by_name, + %w[p ([a-z]+.*)] => project_set_by_name, %w[ps] => list_projects, + %w[s] => set_last_story, %w[s (\d{1,3})] => set_story_from_list, %w[s (\d{4,})] => set_story_from_id, %w[(?:sn|m) (\w+)] => update_story_name,