Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
[#3] change pivotal gem to use newer v5 api.
Browse files Browse the repository at this point in the history
  • Loading branch information
alemata committed May 28, 2015
1 parent ed19d74 commit 1fc2fe0
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 120 deletions.
92 changes: 58 additions & 34 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,84 @@ PATH
hashie (~> 2.0.5)
jiralicious (~> 0.4.0)
octokit (~> 2.0)
pivotal-tracker (~> 0.5.12)
thor (~> 0.18.1)
tracker_api (~> 0.2.0)

GEM
remote: https://rubygems.org/
specs:
addressable (2.3.5)
activemodel (4.2.1)
activesupport (= 4.2.1)
builder (~> 3.1)
activesupport (4.2.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
builder (3.2.2)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
crack (0.1.8)
fakefs (0.5.0)
faraday (0.9.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
equalizer (0.0.11)
excon (0.45.3)
fakefs (0.6.7)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
happymapper (0.4.1)
libxml-ruby (~> 2.0)
faraday_middleware (0.9.1)
faraday (>= 0.7.4, < 0.10)
hashie (2.0.5)
httparty (0.11.0)
multi_json (~> 1.0)
httparty (0.13.5)
json (~> 1.8)
multi_xml (>= 0.5.2)
jiralicious (0.4.0)
i18n (0.7.0)
ice_nine (0.11.1)
jiralicious (0.4.3)
crack (~> 0.1.8)
hashie (>= 1.1)
httparty (>= 0.10, < 0.12.0)
httparty (>= 0.10)
json (>= 1.6, < 1.9.0)
json (1.8.1)
libxml-ruby (2.7.0)
mime-types (2.1)
mini_portile (0.5.2)
multi_json (1.8.4)
nokogiri
oauth
json (1.8.2)
mini_portile (0.6.2)
minitest (5.6.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
nokogiri-happymapper (0.5.8)
nokogiri (~> 1.5)
octokit (2.7.1)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth (0.4.7)
octokit (2.7.2)
sawyer (~> 0.5.2)
pivotal-tracker (0.5.12)
builder
builder
crack
happymapper (>= 0.3.2)
nokogiri (>= 1.4.3)
nokogiri (>= 1.5.5)
nokogiri-happymapper (>= 0.5.4)
rest-client (~> 1.6.0)
rest-client (~> 1.6.0)
rake (10.1.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rake (10.4.2)
rr (1.1.2)
sawyer (0.5.3)
sawyer (0.5.5)
addressable (~> 2.3.5)
faraday (~> 0.8, < 0.10)
thor (0.18.1)
thread_safe (0.3.5)
tracker_api (0.2.9)
activemodel
activesupport
addressable
excon
faraday (~> 0.9.0)
faraday_middleware
virtus
tzinfo (1.2.2)
thread_safe (~> 0.1)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion assisted_workflow.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "fakefs"

gem.add_dependency "thor", "~> 0.18.1"
gem.add_dependency "pivotal-tracker", "~> 0.5.12"
gem.add_dependency "jiralicious", "~> 0.4.0"
gem.add_dependency "octokit", "~> 2.0"
gem.add_dependency "hashie", "~> 2.0.5"
gem.add_dependency "tracker_api", "~> 0.2.0"

gem.description = <<desc
`aw` is a command line tool to automate software development workflows based on github pull requests.
Expand Down
10 changes: 5 additions & 5 deletions lib/assisted_workflow/addons/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def initialize(output, options = {})
# creates a new git branch based on story attributes
# the branch name format is:
# => story_onwer_username.story_id.story_name
def create_story_branch(story)
def create_story_branch(story, username)
log "creating the feature branch"
branch = branch_name(story)
branch = branch_name(story, username)
git "checkout -b #{branch}"
# git "push --set-upstream origin #{branch}"
end
Expand Down Expand Up @@ -97,9 +97,9 @@ def system_error?
$? != 0
end

def branch_name(story)
def branch_name(story, username)
description = story.name.to_s.downcase.gsub(/\W/, "_").slice(0, DESCRIPTION_LIMIT)
[story.other_id, story.id, description].join(".").downcase
[username, story.id, description].join(".").downcase
end

def not_commited_changes
Expand All @@ -110,4 +110,4 @@ def check_everything_commited!
raise AssistedWorkflow::Error, "git: there are not commited changes" unless not_commited_changes.empty?
end
end
end
end
12 changes: 6 additions & 6 deletions lib/assisted_workflow/addons/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ def description
@issue.body.to_s.gsub("\r\n", "\n")
end

def other_id
@issue.assignee.login
end

def current_state
other_id
@issue.assignee.login
end

def labels
Expand Down Expand Up @@ -118,5 +114,9 @@ def pending_stories(options = {})
def valid?
@client.user_authenticated?
end

def username
@username
end
end
end
end
6 changes: 1 addition & 5 deletions lib/assisted_workflow/addons/jira.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def name
@issue.summary
end

def other_id
@issue.fields.current["assignee"]["name"].split.join
end

def current_state
@issue.fields.current["status"]["name"]
end
Expand Down Expand Up @@ -102,4 +98,4 @@ def move_story!(story, status)
end
end
end
end
end
47 changes: 31 additions & 16 deletions lib/assisted_workflow/addons/pivotal.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "assisted_workflow/exceptions"
require "assisted_workflow/addons/base"
require 'pivotal_tracker'
require "tracker_api"

# wrapper class to pivotal api client
module AssistedWorkflow::Addons
Expand All @@ -10,9 +10,9 @@ class Pivotal < Base
def initialize(output, options = {})
super

PivotalTracker::Client.token = options["token"]
@client = TrackerApi::Client.new(token: options["token"])
begin
@project = PivotalTracker::Project.find(options["project_id"])
@project = @client.project(options["project_id"])
rescue
raise AssistedWorkflow::Error, "pivotal project #{options["project_id"]} not found."
end
Expand All @@ -23,37 +23,46 @@ def initialize(output, options = {})
def find_story(story_id)
if story_id.to_i > 0
log "loading story ##{story_id}"
story = @project.stories.find(story_id)
story.other_id = @username || @fullname
story.other_id = story.other_id.to_s.downcase.split.join
story
@project.story(story_id)
end
end

def start_story(story, options = {})
log "starting story ##{story.id}"
update_story! story, options.merge(:current_state => "started")
options.delete(:estimate) if options[:estimate].nil?
update_story!(story, options.merge(:current_state => "started"))
end

def finish_story(story, options = {})
log "finishing story ##{story.id}"
if update_story! story, :current_state => finished_state(story)
story.notes.create(:text => options[:note]) if options[:note]
saved = update_story! story, :current_state => finished_state(story)
if saved && options[:note]
add_comment_to_story(story, options[:note])
end
end

def pending_stories(options = {})
log "loading pending stories"
states = ["unstarted"]
states << "started" if options[:include_started]
@project.stories.all(:state => states, :owned_by => @fullname, :limit => 5)
filter_str = "state:#{states.join(',')} owned_by:#{@client.me.id}"
@project.stories(:filter => filter_str, :limit => 5)
end

def valid?
!@project.nil?
end

private

def add_comment_to_story(story, text)
url = "/projects/#{story.project_id}/stories/#{story.id}/comments"
@client.post(url, params: {:text => text})
rescue TrackerApi::Error => e
body = e.response[:body]
msg = body["possible_fix"] || body["general_problem"]
raise AssistedWorkflow::Error, msg
end

def finished_state(story)
if story.story_type == "chore"
Expand All @@ -65,10 +74,16 @@ def finished_state(story)

def update_story!(story, attributes)
if story
story.update(attributes)
raise AssistedWorkflow::Error, story.errors.first.to_s if story.errors.any?
begin
story.attributes = attributes
story.save
rescue TrackerApi::Error => e
body = e.response[:body]
msg = body["possible_fix"] || body["general_problem"]
raise AssistedWorkflow::Error, msg
end
true
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/assisted_workflow/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def start(story_id=nil)
else
tracker.start_story(story, :estimate => options[:estimate])
out.print_story story
git.create_story_branch(story)
git.create_story_branch(story, github.username)
out.next_command "after commiting your changes, submit a pull request using:", "$ aw submit"
end
end
Expand Down Expand Up @@ -151,4 +151,4 @@ def awfile
end
end
end
end
end
Loading

0 comments on commit 1fc2fe0

Please sign in to comment.