Rally: создать тег не удалось

1

Я пытаюсь создать 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

Заранее благодарим за помощь

Теги:
rally

1 ответ

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("[email protected]", "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"]);
                }

            }

        }
    }
}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню