using System; using System.Collections.Generic; using System.Runtime.Serialization; using GitHub.Services.WebApi; namespace GitHub.Build.WebApi { /// /// Represents a retention policy for a build definition. /// [DataContract] public class RetentionPolicy : BaseSecuredObject { public RetentionPolicy() : this(null) { } public RetentionPolicy( ISecuredObject securedObject) : base(securedObject) { DaysToKeep = 30; // default to 30 days MinimumToKeep = 1; // default to 1 DeleteBuildRecord = true; // default to set Deleted bit on build records DeleteTestResults = false; // For old build definitions, it has to be false. This value in New Definitions will be handled in ts files. } /// /// The list of branches affected by the retention policy. /// public List Branches { get { if (m_branches == null) { m_branches = new List(); } return m_branches; } internal set { m_branches = value; } } /// /// The number of days to keep builds. /// [DataMember] public Int32 DaysToKeep { get { return m_daysToKeep; } set { if (value < 0) { m_daysToKeep = 0; } else { m_daysToKeep = value; } } } /// /// The minimum number of builds to keep. /// [DataMember] public Int32 MinimumToKeep { get { return m_minimumToKeep; } set { if (value < 0) { m_minimumToKeep = 0; } else { m_minimumToKeep = value; } } } /// /// Indicates whether the build record itself should be deleted. /// [DataMember] public Boolean DeleteBuildRecord { get; set; } /// /// The list of artifacts to delete. /// public List ArtifactsToDelete { get { if (m_artifactsToDelete == null) { m_artifactsToDelete = new List(); } return m_artifactsToDelete; } internal set { m_artifactsToDelete = value; } } // This list contains the types of artifacts to be deleted. // These are different from ArtifactsToDelete because for certain artifacts giving user a choice for every single artifact can become cumbersome. // e.g. artifacts in file share - user can choose to delete/keep all the artifacts in file share /// /// The list of types of artifacts to delete. /// public List ArtifactTypesToDelete { get { if (m_artifactTypesToDelete == null) { m_artifactTypesToDelete = new List(); } return m_artifactTypesToDelete; } internal set { m_artifactTypesToDelete = value; } } /// /// Indicates whether to delete test results associated with the build. /// [DataMember] public Boolean DeleteTestResults { get; set; } [DataMember(Name = "Branches", EmitDefaultValue = false)] private List m_branches; [DataMember(Name = "Artifacts", EmitDefaultValue = false)] private List m_artifactsToDelete; [DataMember(Name = "ArtifactTypesToDelete", EmitDefaultValue = false)] private List m_artifactTypesToDelete; private Int32 m_daysToKeep; private Int32 m_minimumToKeep; } }