Ejemplo n.º 1
0
        /// <summary>
        /// Create a new milestone in GitLab from the given parameters
        /// </summary>
        /// <returns>
        /// The new GitLab Milestone
        /// </returns>
        public static GitLabMilestone createMilestone(string externalProject, RemoteRelease remoteRelease, List <GitLabMilestone> milestones, DataSync sync)
        {
            //create a new milestone in GitLab
            NewGitLabMilestone newMilestone = new NewGitLabMilestone();

            newMilestone.title       = remoteRelease.Name;
            newMilestone.description = remoteRelease.Description;
            newMilestone.dueDate     = remoteRelease.EndDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:MM:ssZ");
            //turn the new milestone into JSON
            string toPost = JsonConvert.SerializeObject(newMilestone);
            //post the new milestone
            //TODO: Milestone, project ID
            string          response = httpPOST(sync.apiUrl + "/projects/" + sync.connectionString + "%2F" + externalProject + "/milestones", sync.externalPassword, toPost);
            GitLabMilestone m        = JsonConvert.DeserializeObject <GitLabMilestone>(response);

            //add the new milestone to our list
            milestones.Add(m);

            return(m);
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes a Jama release, importing into SpiraTeam if necessary
        /// </summary>
        /// <param name="jamaRelease">The jama release</param>
        /// <returns></returns>
        private FinalStatusEnum ProcessRelease(StreamWriter streamWriter, JamaRelease jamaRelease)
        {
            FinalStatusEnum retStatus = FinalStatusEnum.OK;

            try
            {
                //Insert/update the release in SpiraTeam

                //See if the item is already mapped to an item in Spira
                int jamaReleaseId = (int)jamaRelease.Id;
                int jamaProjectId = this._JamaProject.ProjectNum;
                ReleaseMappingData.ReleaseMappingRow dataRow = this._releaseDataMapping.GetFromJamaId(jamaProjectId, jamaReleaseId);
                if (dataRow == null)
                {
                    //We need to insert a new release
                    RemoteRelease remoteRelease = new RemoteRelease();
                    if (String.IsNullOrEmpty(jamaRelease.Name))
                    {
                        remoteRelease.Name = "Unknown (Null)";
                    }
                    else
                    {
                        remoteRelease.Name = jamaRelease.Name;
                    }
                    if (!String.IsNullOrEmpty(jamaRelease.Name) && jamaRelease.Name.Length <= 10)
                    {
                        //If we have a release name that is short enough, use it for the version number
                        //otherwise let Spira auto-generate it
                        remoteRelease.VersionNumber = jamaRelease.Name;
                    }
                    else
                    {
                        //Currently "" denotes that we need to create a new version number
                        //in future versions of the API it should also support passing null
                        remoteRelease.VersionNumber = "";
                    }
                    remoteRelease.Description     = jamaRelease.Description;
                    remoteRelease.ReleaseStatusId = (jamaRelease.Active) ? (int)SpiraProject.ReleaseStatusEnum.Planned : (int)SpiraProject.ReleaseStatusEnum.Completed;
                    remoteRelease.ReleaseTypeId   = (int)SpiraProject.ReleaseTypeEnum.MajorRelease;

                    if (jamaRelease.ReleaseDate.HasValue)
                    {
                        //We assume that the release lasts 1-month by default
                        remoteRelease.StartDate = jamaRelease.ReleaseDate.Value.AddMonths(-1).Date;
                        remoteRelease.EndDate   = jamaRelease.ReleaseDate.Value.Date;
                    }
                    else
                    {
                        //Just create a start/end date based on the current date
                        remoteRelease.StartDate = DateTime.UtcNow.Date;
                        remoteRelease.EndDate   = DateTime.UtcNow.AddMonths(1).Date;
                    }

                    //Create the release
                    remoteRelease = this._spiraClient.Release_Create(remoteRelease, null);
                    this._releaseDataMapping.Add(
                        this._SpiraProject.ProjectNum,
                        remoteRelease.ReleaseId.Value,
                        jamaProjectId,
                        jamaReleaseId
                        );
                }
                else
                {
                    //We need to update an existing release (we leave the dates alone)
                    int           spiraReleaseId = dataRow.SpiraReleaseId;
                    RemoteRelease remoteRelease  = this._spiraClient.Release_RetrieveById(spiraReleaseId);
                    if (remoteRelease == null)
                    {
                        //Could not find release and it was mapped.
                        retStatus = FinalStatusEnum.Warning;
                    }
                    else
                    {
                        //Update the release in Spira
                        if (!String.IsNullOrEmpty(jamaRelease.Name))
                        {
                            remoteRelease.Name = jamaRelease.Name;
                            if (jamaRelease.Name.Length <= 10)
                            {
                                //If we have a release name that is short enough, use it for the version number
                                //otherwise let Spira auto-generate it
                                remoteRelease.VersionNumber = jamaRelease.Name;
                            }
                        }
                        remoteRelease.Description = jamaRelease.Description;
                        remoteRelease.Active      = jamaRelease.Active;
                        this._spiraClient.Release_Update(remoteRelease);
                    }
                }

                if (ProcessThread.WantCancel)
                {
                    return(FinalStatusEnum.Error);
                }
            }
            catch (Exception ex)
            {
                streamWriter.WriteLine("Unable to complete import: " + ex.Message);

                retStatus = FinalStatusEnum.Error;
            }
            return(retStatus);
        }
        public async Task NotifyAsync(TeamFoundationRequestContext requestContext, INotification notification, BotElement bot, EventRuleElement matchingRule)
        {
            string URL        = bot.GetSetting("spiraURL");
            string user       = bot.GetSetting("spiraUser");
            string password   = bot.GetSetting("spiraPassw");
            string projVers   = bot.GetSetting("spiraPvers");
            string projNumber = bot.GetSetting("spiraPnumber");
            int    status     = 0;
            int    projectId;

            Int32.TryParse(projNumber, out projectId);

            //Check that it is the correct kind of notification
            if (notification is BuildCompletionNotification)
            {
                BuildCompletionNotification buildCompletionNotification = (BuildCompletionNotification)notification;

                if (buildCompletionNotification.IsSuccessful)
                {
                    status = 2;  //sucess
                }
                else if (buildCompletionNotification.BuildStatus.ToString() == "Failed")
                {
                    status = 1; //failed
                }
                else if (buildCompletionNotification.BuildStatus.ToString() == "PartiallySucceeded")
                {
                    status = 3; //unstable
                }
                else if (buildCompletionNotification.BuildStatus.ToString() == "Stopped")
                {
                    status = 4; //aborted
                }
                else
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS:: The current build finished with a not supported" +
                                                      " status, please check TFS logs to see detailed information.", 0, EventLogEntryType.Warning);
                }


                DateTime date        = buildCompletionNotification.StartTime;
                String   sname       = buildCompletionNotification.ProjectName + " #" + buildCompletionNotification.BuildNumber;
                String   description = ("Information retrieved from TFS : Build requested by " +
                                        buildCompletionNotification.UserName + "<br/> from Team " +
                                        buildCompletionNotification.TeamNames + "<br/> and project collection " +
                                        buildCompletionNotification.TeamProjectCollection + "<br/> for " + sname +
                                        "<br/> with URL " + buildCompletionNotification.BuildUrl +
                                        "<br/> located at " + buildCompletionNotification.DropLocation +
                                        "<br/> Build Started at " + buildCompletionNotification.StartTime +
                                        "<br/> Build finished at " + buildCompletionNotification.FinishTime +
                                        "<br/> Status " + buildCompletionNotification.BuildStatus);
                //List<int> incidentIds;
                var    locationService = requestContext.GetService <TeamFoundationLocationService>();
                string baseUrl         = String.Format("{0}/", locationService.GetAccessMapping(requestContext,
                                                                                                "PublicAccessMapping").AccessPoint);
                TfsTeamProjectCollection tpc           = new TfsTeamProjectCollection(new Uri(baseUrl));
                VersionControlServer     sourceControl = tpc.GetService <VersionControlServer>();
                int revisionId = sourceControl.GetLatestChangesetId();

                //SPIRA CODE
                Uri uri = new Uri(URL + URL_SUFFIX);
                ImportExportClient spiraClient = SpiraClientFactory.CreateClient(uri);
                bool success = spiraClient.Connection_Authenticate2(user, password, "TFS Notifier for SpiraTeam v. 1.0.0");
                if (!success)
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS :: Unable to connect to the Spira server, please verify" +
                                                      " the provided information in the configuration file.", 0, EventLogEntryType.Error);
                }
                success = spiraClient.Connection_ConnectToProject(projectId);
                if (!success)
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS :: The project Id you specified either does not exist," +
                                                      "or your user does not have access to it! Please verify the configuration file.", 0, EventLogEntryType.Error);
                }

                RemoteRelease[] releases = spiraClient.Release_Retrieve(true);
                RemoteRelease   release  = releases.FirstOrDefault(r => r.VersionNumber == projVers);
                if (release != null)
                {
                    List <RemoteBuildSourceCode> revisions = new List <RemoteBuildSourceCode>();
                    RemoteBuildSourceCode        revision  = new RemoteBuildSourceCode();
                    revision.RevisionKey = revisionId.ToString();
                    revisions.Add(revision);

                    RemoteBuild newBuild = new RemoteBuild();
                    newBuild.Name          = sname;
                    newBuild.BuildStatusId = status;
                    newBuild.Description   = description;
                    newBuild.CreationDate  = date;
                    newBuild.Revisions     = revisions.ToArray();
                    newBuild.ReleaseId     = release.ReleaseId.Value;
                    spiraClient.Build_Create(newBuild);
                    await Task.Delay(10);
                }
                else
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS :: The release version number you specified does not " +
                                                      "exist in the current project! Please verify the configuration file.", 0, EventLogEntryType.Error);
                }
            }
        }