Updating requested_by for a bunch of Pivotal Tracker stories
I recently imported a bunch of stories into Pivotal Tracker via the Import CSV function. This worked like a charm, the problem was I wanted all the stories to be requested by a different user than what was in the CSV file.
I could use the web browser to do this, but that would take a while to update 85 stories.
I pulled out the Pivotal Tracker gem (Github | RubyGems) to see if it could help.
[ruby]
$ gem install pivotal-tracker
$ irb
>> require ‘pivotal-tracker’
=> true
>> PivotalTracker::Client.token = ‘12345678asdfghj’
=> "12345678asdfghj"
>> project = PivotalTracker::Project.find(456789)
=> #<PivotalTracker::Project:0x007fd128b9fe50 … >
>> project.stories.all(:requested_by => ‘John Doe’).count
=> 85
>> project.stories.all(:requested_by => ‘John Doe’).each{|story| story.update(:requested_by => ‘Jane Doe’) }
=> [#<PivotalTracker::Story:0x007fd12a28fa48 … ]
>> project = PivotalTracker::Project.find(456789)
=> #<PivotalTracker::Project:0x007fd128b9fe50 … >
>> project.stories.all(:requested_by => ‘John Doe’).count
=> 0
>>
[/ruby]
Note, I had to reload the project because the stories get cached by the pivotal-tracker gem.
1 Comment
I watched you do this in class in a just a few minutes. A neat trick, all done from irb. I actually understand what you did. One of my goals at DaVinci is to be able to look at problems and script quick solutions like this.