pythonrallypyral

Rally Python Api: Add discussion to defect


How can I create a discussion item for a Rally defect with Pyral?

This is what I have so far:

rally = Rally(server, user, password)
rally.enableLogging('rallyConnection.log')
rally.setProject("RallyTestPrj")

defectID = 'DE9221'
notes = "Adding new note from Python"
discussion = "Adding discussion from Python"

defect_data = { "FormattedID" : defectID,
                "Notes"       : notes,
                "Discussion"  : discussion
}

try:
defect = rally.update('Defect', defect_data)
except Exception, details:
sys.stderr.write('ERROR: %s \n' % details)
sys.exit(1)
print "Defect updated"

Solution

  • Actually, a discussion item in rally is a rally artifact, just like a defect, story, or task. In order to do what you want, you need to create a new Discussion artifact (or ConversationPost in rally API terms), and tell it which existing artifact (in your case a defect) to associate itself with.

    rally = Rally(server, user, password)
    rally.enableLogging('rallyConnection.log')
    rally.setProject("RallyTestPrj")
    
    defectID = 'DE9221'
    discussion_text = "Adding discussion from Python"
    
    # get the defect entity so we can grab the defect oid which we'll need when
    # creating the new ConversationPost
    defect = rally.get('Defect', query='FormattedID = %s' % defectID, instance=True)
    
    discussion_data = {"Artifact": defect.oid, "Text": discussion_text}
    
    # create the discussion
    try:
        discussion = rally.create('ConversationPost', discussion_data)
    except Exception, details:
        sys.stderr.write('ERROR: %s \n' % details)
        sys.exit(1)
    print "Defect updated with a new discussion entry"