コード例 #1
0
        private void ImportReleases(StreamWriter streamWriter, SpiraSoapService.SoapServiceClient spiraClient, APIClient testRailApi)
        {
            //Get the milestones from the TestRail API
            JArray milestones = (JArray)testRailApi.SendGet("get_milestones/" + this.testRailProjectId);

            if (milestones != null)
            {
                foreach (JObject milestone in milestones)
                {
                    try
                    {
                        //Extract the user data
                        int testRailId = milestone["id"].Value <int>();

                        //Load the release and capture the ID
                        RemoteRelease remoteRelease = new RemoteRelease();
                        remoteRelease.Name            = milestone["name"].Value <string>();
                        remoteRelease.Description     = (milestone["description"] == null) ? null : milestone["description"].Value <string>();
                        remoteRelease.VersionNumber   = testRailId.ToString();  //Use the test rail ID as the 'version number
                        remoteRelease.StartDate       = (milestone["start_on"] == null) ? DateTime.UtcNow : FromUnixTime(milestone["start_on"].Value <long>());
                        remoteRelease.EndDate         = (milestone["due_on"] == null) ? DateTime.UtcNow.AddMonths(1) : FromUnixTime(milestone["due_on"].Value <long>());
                        remoteRelease.ResourceCount   = 1;
                        remoteRelease.ReleaseTypeId   = /* Major Release */ 1;
                        remoteRelease.ReleaseStatusId = /* Planned */ 1;
                        bool isStarted   = (milestone["is_started"] == null) ? false : milestone["is_started"].Value <bool>();
                        bool isCompleted = (milestone["is_completed"] == null) ? false : milestone["is_completed"].Value <bool>();
                        if (isCompleted)
                        {
                            remoteRelease.ReleaseStatusId = /* Completed */ 3;
                        }
                        else if (isStarted)
                        {
                            remoteRelease.ReleaseStatusId = /* In Progress */ 2;
                        }

                        //See if we have a matching parent release
                        int?parentReleaseId = null;
                        if (milestone["parent_id"] != null)
                        {
                            int?testRailParentMilestoneId = milestone["parent_id"].Value <int?>();
                            if (testRailParentMilestoneId.HasValue && this.releaseMapping.ContainsKey(testRailParentMilestoneId.Value))
                            {
                                parentReleaseId = this.releaseMapping[testRailParentMilestoneId.Value];
                            }
                        }

                        int newReleaseId = spiraClient.Release_Create(remoteRelease, parentReleaseId).ReleaseId.Value;
                        streamWriter.WriteLine("Added release: " + testRailId);

                        //Add to the mapping hashtables
                        if (!this.releaseMapping.ContainsKey(testRailId))
                        {
                            this.releaseMapping.Add(testRailId, newReleaseId);
                        }
                    }
                    catch (Exception ex)
                    {
                        streamWriter.WriteLine("Ignoring TestRail milestone: " + milestone.ToString() + " - " + ex.Message);
                    }
                }
            }
        }