从拉力赛(敏捷中心)拉出项目层次结构时出错

时间:2016-07-15 12:31:47

标签: ruby rally

尝试使用https://github.com/RallyTools/Rally-User-Management处的user_permissions_summary.rb脚本同时提取项目层次结构以及用户权限。 以下代码添加在 go_user_permissions_summary.rb 中以包含ProjectPath:

def find_path(name,rally,workspaceRef)
  puts "Finding Path... -> #{name}"
  query = RallyAPI::RallyQuery.new()
  query.workspace = {"_ref" => workspaceRef}
  query.fetch = "Parent"
  query.type = :project
  query.query_string = "(Name = \"#{name}\")"   
  results = rally.find(query)

  if results[0].Parent == nil
    path = name
  else
    path = [ find_path(results[0].Parent,rally,workspaceRef), name ].join('/')
  end

  return path
end

使用以下行将ProjectPath列添加到输出:

project_path = find_path(strip_role_from_permission(this_permission.Name),@rally,workspace_obj._ref)

user_permissions_summary.rb运行正常一段时间,然后失败并出现以下错误:

寻找路径...... - &gt;改善旅程 C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_object.rb:19:in initialize' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:27:in new' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:27:in []' C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/lib/go_user_permissions_summary_MODIFIED.rb:128:in find_path' C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/lib/go_user_permissions_summary_MODIFIED.rb:261:in block (2 levels) in go_user_permissions_summary' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_collection.rb:36:in each' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_collection.rb:36:在go_user_permissions_summary中的each' C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/lib/go_user_permissions_summary_MODIFIED.rb:219:in块中 C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:22:in block in each' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:21:in each' C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:21:in each' C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/lib/go_user_permissions_summary_MODIFIED.rb:198:in go_user_permissions_summary' C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/user_permissions_summary.rb:38:in <main>' undefined method []'for nil:NilClass

有关解决此问题的任何提示吗?

1 个答案:

答案 0 :(得分:0)

Ramaprakash,

查询可能无法返回任何结果。由于此情况没有错误检查,因此失败并显示<main> ' undefined method []' for nil:NilClass错误。

有必要进行一些进一步的错误检查或处理其他情况。

类似的东西:

if results.length > 0 && results[0].Parent == nil
    path = name
elsif results.length > 0  
    path = [ find_path(results[0].Parent,rally,workspaceRef), name ].join('/')
else
    path = "Unknown"
end

应该有所帮助。