From b208057af6d6f56f310b285cb59b958dbec067f2 Mon Sep 17 00:00:00 2001 From: Slyck Lizzie <19241000+SlyckLizzie@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:00:00 -0400 Subject: [PATCH] [Feat] Add Advanced Security Properties to Repository Get/Update (#2865) * add SecurityAndAnalysis to repository get/update * add repository advanced security * cleanup --------- Co-authored-by: Dirty Gooback <19241000+dirtygooback@users.noreply.github.com> Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com> --- Octokit/Models/Common/Status.cs | 12 ++ Octokit/Models/Request/RepositoryUpdate.cs | 3 + .../Request/SecurityAndAnalysisRequest.cs | 184 ++++++++++++++++++ Octokit/Models/Response/Repository.cs | 7 +- .../Models/Response/SecurityAndAnalysis.cs | 177 +++++++++++++++++ 5 files changed, 379 insertions(+), 4 deletions(-) create mode 100644 Octokit/Models/Common/Status.cs create mode 100644 Octokit/Models/Request/SecurityAndAnalysisRequest.cs create mode 100644 Octokit/Models/Response/SecurityAndAnalysis.cs diff --git a/Octokit/Models/Common/Status.cs b/Octokit/Models/Common/Status.cs new file mode 100644 index 0000000000..94a80c947b --- /dev/null +++ b/Octokit/Models/Common/Status.cs @@ -0,0 +1,12 @@ +using Octokit.Internal; + +namespace Octokit +{ + public enum Status + { + [Parameter(Value = "enabled")] + Enabled, + [Parameter(Value = "disabled")] + Disabled + } +} diff --git a/Octokit/Models/Request/RepositoryUpdate.cs b/Octokit/Models/Request/RepositoryUpdate.cs index b8a3c9c2a8..16e53b2671 100644 --- a/Octokit/Models/Request/RepositoryUpdate.cs +++ b/Octokit/Models/Request/RepositoryUpdate.cs @@ -1,4 +1,5 @@ using Octokit.Internal; +using Octokit.Models.Response; using System; using System.Diagnostics; @@ -133,6 +134,8 @@ public RepositoryUpdate() { } /// public bool? HasDiscussions { get; set; } + public SecurityAndAnalysisRequest SecurityAndAnalysis { get; set; } + internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this); } } diff --git a/Octokit/Models/Request/SecurityAndAnalysisRequest.cs b/Octokit/Models/Request/SecurityAndAnalysisRequest.cs new file mode 100644 index 0000000000..38705d4a05 --- /dev/null +++ b/Octokit/Models/Request/SecurityAndAnalysisRequest.cs @@ -0,0 +1,184 @@ +using Octokit.Internal; +using System.Diagnostics; + + +namespace Octokit +{ + /// + /// The security and analysis features that are enabled or disabled for the repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecurityAndAnalysisRequest + { + public SecurityAndAnalysisRequest() + { } + + public SecurityAndAnalysisRequest(AdvancedSecurityRequest advancedSecurity, DependabotSecurityUpdatesRequest dependabotSecurityUpdates, + SecretScanningRequest secretScanning, SecretScanningPushProtectionRequest secretScanningPushProtection, + SecretScanningValidityChecksRequest secretScanningValidityChecks) + { + this.AdvancedSecurity = advancedSecurity; + this.DependabotSecurityUpdates = dependabotSecurityUpdates; + this.SecretScanning = secretScanning; + this.SecretScanningPushProtection = secretScanningPushProtection; + this.SecretScanningValidityChecks = secretScanningValidityChecks; + } + + + public AdvancedSecurityRequest AdvancedSecurity { get; set; } + public DependabotSecurityUpdatesRequest DependabotSecurityUpdates { get; set; } + public SecretScanningRequest SecretScanning { get; set; } + public SecretScanningPushProtectionRequest SecretScanningPushProtection { get; set; } + public SecretScanningValidityChecksRequest SecretScanningValidityChecks { get; set; } + + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + + /// + /// Use the status property to enable or disable GitHub Advanced Security for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class AdvancedSecurityRequest + { + public AdvancedSecurityRequest() + { } + + public AdvancedSecurityRequest(Status? status) + { + this.Status = status; + } + + /// + /// Can be enabled, disabled, or null + /// + public Status? Status { get; set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable Dependabot security updates for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class DependabotSecurityUpdatesRequest + { + public DependabotSecurityUpdatesRequest() + { } + + public DependabotSecurityUpdatesRequest(Status? status) + { + this.Status = status; + } + + /// + /// Can be enabled, disabled, or null + /// + public Status? Status { get; set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable secret scanning for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecretScanningRequest + { + public SecretScanningRequest() + { } + + public SecretScanningRequest(Status? status) + { + this.Status = status; + } + + /// + /// Can be enabled, disabled, or null + /// + public Status? Status { get; set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable secret scanning push protection for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecretScanningPushProtectionRequest + { + public SecretScanningPushProtectionRequest() + { } + + public SecretScanningPushProtectionRequest(Status? status) + { + this.Status = status; + } + + /// + /// Can be enabled, disabled, or null + /// + public Status? Status { get; set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable secret scanning validity checks for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecretScanningValidityChecksRequest + { + public SecretScanningValidityChecksRequest() + { } + + public SecretScanningValidityChecksRequest(Status? status) + { + this.Status = status; + } + + /// + /// Can be enabled, disabled, or null + /// + public Status? Status { get; set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } +} diff --git a/Octokit/Models/Response/Repository.cs b/Octokit/Models/Response/Repository.cs index 7075c302ad..5ec70a9a1f 100644 --- a/Octokit/Models/Response/Repository.cs +++ b/Octokit/Models/Response/Repository.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.Linq; @@ -17,7 +16,7 @@ public Repository(long id) Id = id; } - public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, string archiveUrl, long id, string nodeId, User owner, string name, string fullName, bool isTemplate, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, Repository parent, Repository source, LicenseMetadata license, bool hasDiscussions, bool hasIssues, bool hasWiki, bool hasDownloads, bool hasPages, int subscribersCount, long size, bool? allowRebaseMerge, bool? allowSquashMerge, bool? allowMergeCommit, bool archived, int watchersCount, bool? deleteBranchOnMerge, RepositoryVisibility visibility, IEnumerable topics, bool? allowAutoMerge, bool? allowUpdateBranch, bool? webCommitSignoffRequired, IReadOnlyDictionary customProperties) + public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, string archiveUrl, long id, string nodeId, User owner, string name, string fullName, bool isTemplate, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, Repository parent, Repository source, LicenseMetadata license, bool hasDiscussions, bool hasIssues, bool hasWiki, bool hasDownloads, bool hasPages, int subscribersCount, long size, bool? allowRebaseMerge, bool? allowSquashMerge, bool? allowMergeCommit, bool archived, int watchersCount, bool? deleteBranchOnMerge, RepositoryVisibility visibility, IEnumerable topics, bool? allowAutoMerge, bool? allowUpdateBranch, bool? webCommitSignoffRequired, SecurityAndAnalysis securityAndAnalysis) { Url = url; HtmlUrl = htmlUrl; @@ -69,7 +68,7 @@ public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, st AllowAutoMerge = allowAutoMerge; AllowUpdateBranch = allowUpdateBranch; WebCommitSignoffRequired = webCommitSignoffRequired; - CustomProperties = customProperties; + SecurityAndAnalysis = securityAndAnalysis; } public string Url { get; private set; } @@ -171,7 +170,7 @@ public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, st public bool? WebCommitSignoffRequired { get; private set; } - public IReadOnlyDictionary CustomProperties { get; private set; } + public SecurityAndAnalysis SecurityAndAnalysis { get; private set;} internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/SecurityAndAnalysis.cs b/Octokit/Models/Response/SecurityAndAnalysis.cs new file mode 100644 index 0000000000..594e462d29 --- /dev/null +++ b/Octokit/Models/Response/SecurityAndAnalysis.cs @@ -0,0 +1,177 @@ +using Octokit.Internal; +using System.Diagnostics; + + +namespace Octokit +{ + /// + /// The security and analysis features that are enabled or disabled for the repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecurityAndAnalysis + { + public SecurityAndAnalysis() + { } + + public SecurityAndAnalysis(AdvancedSecurity advancedSecurity, DependabotSecurityUpdates dependabotSecurityUpdates, SecretScanning secretScanning, SecretScanningPushProtection secretScanningPushProtection, SecretScanningValidityChecks secretScanningValidityChecks) + { + this.AdvancedSecurity = advancedSecurity; + this.DependabotSecurityUpdates = dependabotSecurityUpdates; + this.SecretScanning = secretScanning; + this.SecretScanningPushProtection = secretScanningPushProtection; + this.SecretScanningValidityChecks = secretScanningValidityChecks; + } + + + public AdvancedSecurity AdvancedSecurity { get; protected set; } + + public DependabotSecurityUpdates DependabotSecurityUpdates { get; protected set; } + + public SecretScanning SecretScanning { get; protected set; } + + public SecretScanningPushProtection SecretScanningPushProtection { get; protected set; } + + public SecretScanningValidityChecks SecretScanningValidityChecks { get; protected set; } + + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + + /// + /// Use the status property to enable or disable GitHub Advanced Security for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class AdvancedSecurity + { + public AdvancedSecurity() + { } + + public AdvancedSecurity(string status) + { + this.Status = status; + } + + + public string Status { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable Dependabot security updates for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class DependabotSecurityUpdates + { + public DependabotSecurityUpdates() + { } + + public DependabotSecurityUpdates(string status) + { + this.Status = status; + } + + + public string Status { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable secret scanning for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecretScanning + { + public SecretScanning() + { } + + public SecretScanning(string status) + { + this.Status = status; + } + + + public string Status { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable secret scanning push protection for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecretScanningPushProtection + { + public SecretScanningPushProtection() + { } + + public SecretScanningPushProtection(string status) + { + this.Status = status; + } + + + public string Status { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + + /// + /// Use the status property to enable or disable secret scanning validity checks for this repository + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SecretScanningValidityChecks + { + public SecretScanningValidityChecks() + { } + + public SecretScanningValidityChecks(string status) + { + this.Status = status; + } + + + public string Status { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return new SimpleJsonSerializer().Serialize(this); + } + } + } + +}