1

为了清理 Rally,我想更改标记为的项目的父级"Closed"

--MyWorkspace
  - Project 1
  - Project 2
    - Child 1 (Status = Closed)
    - Child 2 (Status = Closed)
    - Child 3 (Status = Open)
  - Project 3

我想更新"Child 1" and "Child 2" to "Project 1"(想将那些子项目移动到不同的父项下)的父项。

import sys
from pyral import Rally, rallyWorkset
options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args    = [arg for arg in sys.argv[1:] if arg not in options]
server = <server>
apikey = <api_key>
workspace = <workspace>
project = <project_name>
rally = Rally(server,apikey=apikey, workspace=workspace, project=project)
rally.enableLogging('mypyral.log')

我正在使用以下方法检查所需工作区下的所有项目

projects = rally.getProjects(workspace=workspace)
for proj in projects:
    print ("    %12.12s  %s  %s" % (proj.oid, proj.Name, proj.State))

这仅给了我父级项目

<id> <Name>  <status>

但是,此逻辑不会返回所有子项目。

post此外,一旦我获得要关闭的项目列表,我正在寻找更新父母的方法。

4

1 回答 1

2

这是正确的 -projects = rally.getProjects(workspace=workspace)返回所有父母项目。

为了获得所有子项目,您需要询问它的父母:

for proj in projects:
children = proj.Children
for child in children:
    print ("    %12.12s  %s  %s" % (child.oid, child.Name, child.State))

我将通过以下方式解决整个任务:

#get object for 'New Parent':
target_project = rally.getProject('NewParentForClosedProjects')

projects = rally.getProjects(workspace=workspace)
for proj in projects:

    #get children of project
    children = proj.Children

    for child in children:

        #if project closed:
        if child.State == 'Closed':
            #Then update Parent to new one:
            project_fields = {
                "ObjectID": child.oid,
                "Parent": target_project.ref
            }
            try:
                result = rally.update('Project', project_fields)
                print "Project %s has been successfully updated with new %s parent" % (str(child.Name), str(child.Parent))
            except RallyRESTException, ex:
                print "Update failure for Project %s" % (str(child.Name))
                print ex
于 2017-02-13T09:36:12.340 回答