1

I am trying to find the syntax for inserting a new Relation between issues in Redmine using Ruby.

The code I've been trying:

require 'rubygems'
require 'active_resource'
class Issue < ActiveResource::Base
     self.site = '[the site]'
     self.user = '[the user]'
     self.password = '[the password]' #not hard coded
     self.format = :json #I've had issues with Issue.find(i) without explicitly stating the format
end

class IssueRelation < ActiveResource::Base
     self.site = '[the site]'
     self.user = '[the user]'
     self.password = '[the password]' #not hard coded
     self.format = :json #I've had issues with Issue.find(i) without explicitly stating the format
end

issue1 = Issue.find(1)
issue2 = Issue.find(2)

puts issue1.id
puts issue2.id

relation = IssueRelation.new(
    :issue => issue1,
    :issue_to => issue2,
    :relation_type => 'relates'
    )

if relation.save
    puts relation.id
else
    puts relation.errors.full_message
end

The output I get back:

1
2
...'handle_response': Failed. Response code = 404. Response Message = not found.

The output suggests that Issue 1 and 2 were successfully found, but that the name I'm using for the relation is not valid, hence the 404 not found.

What is the correct syntax for creating a relation in Redmine's API given that I have found the two issues that it will link?

Centimane
  • 280
  • 5
  • 17

1 Answers1

0

I have discovered the solution to this.

Rather than use the IssueRelation object you need to use the Relation object.

Also, before using the Relation object you must change the site.

Relation.site="[the site]/issues/#{issue1.id}/"
rel = Relation.new(
       :issue_to_id => issue2.id,
       :relation_type => 'relates'
      )
rel.save

You could probably put :site in the Relation.new instead of changing it for the class.

Centimane
  • 280
  • 5
  • 17