Skip to content

Commit

Permalink
[api] return right instance when getting issue update
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Jan 20, 2012
1 parent 33aa859 commit ca95fef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/api/app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ def show
required_parameters :id, :issue_tracker_id

# NOTE: issue_tracker_id is here actually the name
issue = nil
begin
issue = Issue.get_by_name_and_tracker( params[:id], params[:issue_tracker_id], params[:force_update] )
rescue
# not yet existing, try to create
issue = Issue.find_or_create_by_name_and_tracker( params[:id], params[:issue_tracker_id] )
issue = Issue.get_by_name_and_tracker( params[:id], params[:issue_tracker_id], 1 ) if params[:force_update]
end
issue = Issue.find_or_create_by_name_and_tracker( params[:id], params[:issue_tracker_id], params[:force_update] )

render :text => issue.render_axml, :content_type => 'text/xml'
end
Expand Down
10 changes: 8 additions & 2 deletions src/api/app/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def self.get_by_name_and_tracker( name, issue_tracker_name, force_update=nil )
issue = Issue.find_by_name name, :conditions => [ "issue_tracker_id = BINARY ?", issue_tracker.id ]
raise IssueNotFoundError.new( "Error: Issue '#{name}' not found." ) unless issue

issue.fetch_updates if force_update
if force_update
issue.fetch_updates
return Issue.find_by_name name, :conditions => [ "issue_tracker_id = BINARY ?", issue_tracker.id ]
end

return issue
end
Expand All @@ -30,7 +33,10 @@ def self.find_by_name_and_tracker( name, issue_tracker_name, force_update=nil, c
issue = Issue.create( :name => name, :issue_tracker => issue_tracker ) if issue.nil? and create_missing

# force update
issue.fetch_updates if force_update and not issue.nil?
if force_update and not issue.nil?
issue.fetch_updates
return Issue.find_by_name name, :conditions => [ "issue_tracker_id = BINARY ?", issue_tracker.id ]
end

return issue
end
Expand Down

0 comments on commit ca95fef

Please sign in to comment.