Add tag to a Rally Defect using python pyral

烂漫一生 提交于 2019-12-24 03:30:53

问题


I am trying to create Rally defect using pyral python package. Need to add a tag "#TestTag2". Is there a way to add Tag at the time defect is created? I am trying to add tag after the defect is created. But getting following error -

info = {"Workspace": "/workspace/123",
        "Project": "/project/123",
        "Name": "Test Defect",
        "Description": "Test Defect details",
        "Owner": "/user/123",
        "ScheduleState": "Defined",
        }

try:
    defect = rally.create('Defect', info )
    print ("Rally Defect Opened - {0} \n").format(defect.FormattedID)
    adds = rally.addCollectionItems(defect, 'Tag',"#TestTag")
    rally.addCollectionItems(defect,)
    print(adds)
except Exception, details:
    sys.stderr.write('ERROR: %s \n' % details)
    sys.exit(1)

Getting following ERROR -

Rally Defect Opened - DE1234
ERROR: addCollectionItems() takes exactly 3 arguments (4 given) 

Please help here, how to add a tag to a defect. Thanks in advance.


回答1:


You got this error because of the signature of the method is the following:

def addCollectionItems(self, target, items)

You need to adjust your code to pass the list of tags:

tag_req = rally.get('Tag', fetch=True, query='Name = "TAG NAME"')
tag = tag_req.next()
adds = rally.addCollectionItems(defect, [tag])

Or you can use directly during Defect creation without any additional API calls:

from pyral import Rally

SERVER = 'SERVER URL'
USER = 'USER'
PASSWORD = 'PASSWORD'
WORKSPACE = 'WORKSPACE'
TAG = 'TAG NAME'
OWNER_EMAIL = 'bla@bla.com'

rally = Rally(SERVER, USER, PASSWORD, workspace=WORKSPACE)

target_project = rally.getProject()

user_req = rally.get('User', fetch=True, query='EmailAddress = "%s"' % (OWNER_EMAIL))
user = user_req.next()

tag_req = rally.get('Tag', fetch=True, query='Name = "%s"' % (TAG))
tag = tag_req.next()

defect_info ={"Project": target_project.ref,
        "Name": "Test Defect",
        "Description": "Test Defect details",
        "ScheduleState": "Defined",
        "Owner": user.ref,
        "TAGS": [tag],
        }

try:
    defect = rally.create('Defect', defect_info )
    print ("Rally Defect Opened - {0} \n").format(defect.FormattedID)
except Exception, details:
    sys.stderr.write('ERROR: %s \n' % details)


来源:https://stackoverflow.com/questions/49434512/add-tag-to-a-rally-defect-using-python-pyral

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!