using System; using System.Diagnostics; using System.Globalization; using Octokit.Helpers; namespace Octokit { /// /// Base class with common properties for all the Repository Content Request APIs. /// public abstract class ContentRequest { /// /// Initializes a new instance of the class. /// /// The message. protected ContentRequest(string message) { Ensure.ArgumentNotNullOrEmptyString(message, "message"); Message = message; } /// /// Initializes a new instance of the class. /// /// The message. /// The branch the request is for. protected ContentRequest(string message, string branch) : this(message) { Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); Branch = branch; } /// /// The commit message. This is required. /// public string Message { get; private set; } /// /// The branch name. If null, this defaults to the default branch which is usually "master". /// public string Branch { get; set; } /// /// Specifies the committer to use for the commit. This is optional. /// public Committer Committer { get; set; } /// /// Specifies the author to use for the commit. This is optional. /// public Committer Author { get; set; } } /// /// Represents the request to delete a file in a repository. /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class DeleteFileRequest : ContentRequest { /// /// Initializes a new instance of the class. /// /// The message. /// The sha. public DeleteFileRequest(string message, string sha) : base(message) { Ensure.ArgumentNotNullOrEmptyString(sha, "content"); Sha = sha; } /// /// Initializes a new instance of the class. /// /// The message. /// The sha. /// The branch the request is for. public DeleteFileRequest(string message, string sha, string branch) : base(message, branch) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Sha = sha; } public string Sha { get; private set; } internal string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "SHA: {0} Message: {1}", Sha, Message); } } } /// /// Represents the parameters to create a file in a repository. /// /// https://developer.github.com/v3/repos/contents/#create-a-file [DebuggerDisplay("{DebuggerDisplay,nq}")] public class CreateFileRequest : ContentRequest { /// /// Creates an instance of a . /// /// The message. /// The content. public CreateFileRequest(string message, string content) : base(message) { Ensure.ArgumentNotNull(content, "content"); Content = content; } /// /// Initializes a new instance of the class. /// /// The message. /// The content. /// The branch the request is for. public CreateFileRequest(string message, string content, string branch) : base(message, branch) { Ensure.ArgumentNotNullOrEmptyString(content, "content"); Content = content; } /// /// The contents of the file to create. This is required. /// [SerializeAsBase64] public string Content { get; private set; } internal virtual string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Message: {0} Content: {1}", Message, Content); } } } /// /// Represents the parameters to update a file in a repository. /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class UpdateFileRequest : CreateFileRequest { /// /// Creates an instance of a . /// /// The message. /// The content. /// The sha. public UpdateFileRequest(string message, string content, string sha) : base(message, content) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Sha = sha; } /// /// Creates an instance of a . /// /// The message. /// The content. /// The sha. /// The branch the request is for. public UpdateFileRequest(string message, string content, string sha, string branch) : base(message, content, branch) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Sha = sha; } /// /// The blob SHA of the file being replaced. /// public string Sha { get; private set; } internal override string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "SHA: {0} Message: {1}", Sha, Message); } } } }