Skip to main content
 首页 » 编程设计

python之集会 python REST : Query all tasks from chosen iteration

2025年05月04日6cyq1162

我正在尝试使用 python 工具包查询特定迭代中的所有任务以进行集会 REST API .迭代将在运行时选择。

但是我无法设置正确的查询。我觉得我在这里遗漏了一些小而重要的东西。

这是代码:

query_criteria = 'Iteration.Name = "2014 november"' 
response = rally.get('Task', fetch=True, query=query_criteria) 
if response.errors: 
    sys.stdout.write("\n".join(response.errors)) 
    sys.exit(1) 
for Task in response: 
    if getattr(Task,"Iteration"): 
            print "%s %s" % (Task.Name,Task.Iteration.Name) 

它将收到 0 行响应。

如果我删除 、query=query_criteria 并获取所有任务,那么我可以看到有些任务的 Task.Iteration.Name 值为 2014 年 11 月。

查询没有给出错误,所以我假设相关对象(任务->迭代)的值能够包含在查询中。但是我收到 0 行响应。

可能是因为某些任务似乎没有附加到迭代中?

一种解决方案是获取所有任务,然后过滤它们。但这似乎很脏。

请您参考如下方法:

如果您直接在浏览器的 WS API 中查询,您会得到结果吗?

https://rally1.rallydev.com/slm/webservice/v2.0/task?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12352608129&query=(Iteration.Name%20%3D%20%22my%20iteration%22)&pagesize=200 

我验证了此代码适用于 pyral 1.1.0、Python 2.7.0 和 requests-2.3.0 - 它返回分配给迭代的所有工作产品任务(例如用户故事和缺陷)。我测试了 3 个查询:按状态、按迭代引用和按迭代名称(前两个在代码中被注释掉)。

#!/usr/bin/env python 
 
################################################################################################# 
# 
#  showitems -- show artifacts in a workspace/project conforming to some common criterion 
# 
################################################################################################# 
 
import sys, os 
from pyral import Rally, rallyWorkset, RallyRESTAPIError 
 
################################################################################################# 
 
errout = sys.stderr.write 
 
################################################################################################# 
 
def main(args): 
    options = [opt for opt in args if opt.startswith('--')] 
    args    = [arg for arg in args if arg not in options] 
    server, username, password, apikey, workspace, project = rallyWorkset(options) 
    if apikey: 
        rally = Rally(server, apikey=apikey, workspace=workspace, project=project) 
    else: 
        rally = Rally(server, user=username, password=password, workspace=workspace, project=project) 
    rally.enableLogging("rally.history.showitems") 
 
    fields    = "FormattedID,State,Name" 
    #criterion = 'State != Closed' 
    #criterion = 'iteration = /iteration/20502967321' 
    criterion = 'iteration.Name = \"iteration 5\"' 
 
    response = rally.get('Task', fetch=fields, query=criterion, order="FormattedID", 
                                   pagesize=200, limit=400) 
 
    for task in response: 
        print "%s  %s  %s" % (task.FormattedID, task.Name, task.State) 
 
    print "-----------------------------------------------------------------" 
    print response.resultCount, "qualifying tasks" 
 
################################################################################################# 
################################################################################################# 
 
if __name__ == '__main__': 
    main(sys.argv[1:]) 
    sys.exit(0)