我正在尝试同时在两个工作区中创建TAG。
我遍历我们的订阅工作区并查询标签,看看TAG是否已经存在。
如果TAG不存在,我就创建它。
然而,它只会在我们以后的工作区中创建TAG,而不会在较旧的工作区上创建。
任何想法我可能做错了什么?
static void Main(string[] args)
{
string id = "TEST";
RallyRestApi restApi = new RallyRestApi("myuserid@mycompany", "mypassword", "https://rally1.rallydev.com", "v2.0");
DynamicJsonObject sub = restApi.GetSubscription("Workspaces");
Request wRequest = new Request(sub["Workspaces"]);
Rally.RestApi.Response.QueryResult queryResult = restApi.Query(wRequest);
foreach (var result in queryResult.Results)
{
var workspaceReference = result["_ref"];
Request tagRequest = new Request("tag")
{
Workspace = workspaceReference,
Fetch = new List<string>() { "Name", "ObjectID" },
Query = new Query("Name", Query.Operator.Equals, id)
};
QueryResult tagResult = restApi.Query(tagRequest);
if (tagResult.TotalResultCount == 0)
{
DynamicJsonObject newTag = new DynamicJsonObject();
newTag["Name"] = id;
CreateResult createResult = restApi.Create(workspaceReference, "Tag", newTag);
Console.Out.WriteLine("TAG " + id + " not found, creating");
Console.Out.WriteLine(createResult.Reference);
}
else
{
Console.Out.WriteLine("TAG " + id + " found");
Console.Out.WriteLine(tagResult.Results.First()["_ref"]);
}
}
Console.ReadKey();
}
当我运行时,我总是得到以下结果
TAG TEST not found, creating
https://rally1.rallydev.com/slm/webservice/v2.0/tag/19735777148
TAG TEST found
https://rally1.rallydev.com/slm/webservice/v2.0/tag/19735777148
提前感谢您对此的任何帮助
答案 0 :(得分:0)
而不是将引用传递给create:
中的工作区newTag["Name"] = id;
CreateResult createResult = restApi.Create(workspaceReference, "Tag", newTag);
像这样设置工作区:
newTag["Name"] = tagName;
newTag["Workspace"] = workspaceReference;
CreateResult createResult = restApi.Create("Tag", newTag);
这是一个完整的例子。我首先过滤掉所有者对订阅的工作区集合,但其余代码与您的类似:
namespace aRESTcreateTags
{
class Program
{
static void Main(string[] args)
{
string tagName = "T3$T";
RallyRestApi restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");
//get current user
DynamicJsonObject user = new DynamicJsonObject();
user = restApi.GetCurrentUser();
Console.Out.WriteLine("owner " + user["_ref"]);
//find workspaces owned by this user
//equivalent to this endpoint: https://rally1.rallydev.com/slm/webservice/v2.0/subscription/1154643/workspaces?query=(Owner%20=%20%22/user/12345%22)
DynamicJsonObject sub = restApi.GetSubscription("Workspaces");
Request wRequest = new Request(sub["Workspaces"]);
wRequest.Query = new Query("Owner", Query.Operator.Equals, user["_ref"]);
QueryResult wResult = restApi.Query(wRequest);
foreach (var workspace in wResult.Results)
{
//Console.Out.WriteLine(workspace["_refObjectName"] + " : " + workspace["_ref"]);
Request tagRequest = new Request("tag");
tagRequest.Query = new Query("Name", Query.Operator.Equals, tagName);
QueryResult tagResult = restApi.Query(tagRequest);
if (tagResult.TotalResultCount == 0)
{
Console.Out.WriteLine("TAG " + tagName + " not found, creating");
DynamicJsonObject newTag = new DynamicJsonObject();
newTag["Name"] = tagName;
newTag["Workspace"] = workspace["_ref"];
CreateResult createResult = restApi.Create("Tag", newTag);
Console.Out.WriteLine(createResult.Reference + " created in workspace " + workspace["_refObjectName"]);
}
else
{
Console.Out.WriteLine("TAG " + tagName + " found in " + workspace["_refObjectName"]);
Console.Out.WriteLine(tagResult.Results.First()["_refObjectName"] + " " + tagResult.Results.First()["_ref"]);
}
}
}
}
}