Ejemplo n.º 1
0
        /// <summary>
        /// Gathers the last from the passed Project and Environment.
        /// </summary>
        /// <param name="octRepository">The repository to call against.</param>
        /// <param name="project">Project to gather from.</param>
        /// <param name="environment">Environment to gather from.</param>
        /// <param name="state">Task state to look for.</param>
        /// <returns></returns>
        public static ReleaseResource GetLastestDeployedReleaseFromProjectEnvironmentByStatus(OctopusRepository octRepository, ProjectResource project, EnvironmentResource environment, TaskState state)
        {
            var projectArray     = new string[] { project.Id };
            var environmentArray = new string[] { environment.Id };

            var lastDeployedReleases = octRepository.Client.GetProjectEnvironmentDeployments(projectArray, environmentArray).Where(r => TaskHelper.GetTaskFromId(octRepository, r.TaskId).State == state).ToList();

            if (lastDeployedReleases != null && lastDeployedReleases.Count > 0)
            {
                var lastDeployedReleaseId = lastDeployedReleases.OrderByDescending(p => p.Created).FirstOrDefault().ReleaseId;
                var lastDeployedRelease   = octRepository.Releases.Get(lastDeployedReleaseId);
                return(lastDeployedRelease);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gathers the last non active Deployed Release from the passed projet and environment.
        /// </summary>
        /// <param name="octRepository">The repository to call against.</param>
        /// <param name="project">Project to gather from.</param>
        /// <param name="environment">Environment to gather from.</param>
        /// <returns>ReleaseResource</returns>
        public static ReleaseResource GetLastNonActiveDeployedReleaseFromProjectEnvironment(OctopusRepository octRepository, ProjectResource project, EnvironmentResource environment)
        {
            var nonActiveStatusList = new List <TaskState>()
            {
                TaskState.Queued,
                TaskState.Executing
            };
            var projectArray         = new string[] { project.Id };
            var environmentArray     = new string[] { environment.Id };
            var lastDeployedReleases = octRepository.Client.GetProjectEnvironmentDeployments(projectArray, environmentArray);

            if (lastDeployedReleases != null && lastDeployedReleases.Count() > 0)
            {
                var nonActiveStatusDeployedReleases = lastDeployedReleases.Where(x => !(nonActiveStatusList.Contains(TaskHelper.GetTaskFromId(octRepository, x.TaskId).State)));
                if (nonActiveStatusDeployedReleases != null && nonActiveStatusDeployedReleases.Count() > 0)
                {
                    var lastDeployment      = lastDeployedReleases.OrderByDescending(p => p.Created).First();
                    var lastDeployedRelease = octRepository.Releases.Get(lastDeployment.ReleaseId);
                    return(lastDeployedRelease);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }