-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
CreateFileRequest.cs
242 lines (212 loc) · 8.79 KB
/
CreateFileRequest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using System.Diagnostics;
using System.Globalization;
using Octokit.Helpers;
namespace Octokit
{
/// <summary>
/// Base class with common properties for all the Repository Content Request APIs.
/// </summary>
public abstract class ContentRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="ContentRequest"/> class.
/// </summary>
/// <param name="message">The message.</param>
protected ContentRequest(string message)
{
Ensure.ArgumentNotNullOrEmptyString(message, nameof(message));
Message = message;
}
/// <summary>
/// Initializes a new instance of the <see cref="ContentRequest"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="branch">The branch the request is for.</param>
protected ContentRequest(string message, string branch) : this(message)
{
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
Branch = branch;
}
/// <summary>
/// The commit message. This is required.
/// </summary>
public string Message { get; private set; }
/// <summary>
/// The branch name. If null, this defaults to the default branch which is usually "main".
/// </summary>
public string Branch { get; set; }
/// <summary>
/// Specifies the committer to use for the commit. This is optional.
/// </summary>
public Committer Committer { get; set; }
/// <summary>
/// Specifies the author to use for the commit. This is optional.
/// </summary>
public Committer Author { get; set; }
}
/// <summary>
/// Represents the request to delete a file in a repository.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class DeleteFileRequest : ContentRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteFileRequest"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="sha">The sha.</param>
public DeleteFileRequest(string message, string sha) : base(message)
{
Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha));
Sha = sha;
}
/// <summary>
/// Initializes a new instance of the <see cref="DeleteFileRequest"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="sha">The sha.</param>
/// <param name="branch">The branch the request is for.</param>
public DeleteFileRequest(string message, string sha, string branch) : base(message, branch)
{
Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha));
Sha = sha;
}
public string Sha { get; private set; }
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "SHA: {0} Message: {1}", Sha, Message);
}
}
}
/// <summary>
/// Represents the parameters to create a file in a repository.
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#create-a-file</remarks>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class CreateFileRequest : ContentRequest
{
/// <summary>
/// Creates an instance of a <see cref="CreateFileRequest" />.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
public CreateFileRequest(string message, string content) : this(message, content, true)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="CreateFileRequest"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="branch">The branch the request is for.</param>
public CreateFileRequest(string message, string content, string branch) : this(message, content, branch, true)
{ }
/// <summary>
/// Creates an instance of a <see cref="CreateFileRequest" />.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="convertContentToBase64">True to convert content to base64.</param>
public CreateFileRequest(string message, string content, bool convertContentToBase64) : base(message)
{
Ensure.ArgumentNotNull(content, nameof(content));
if (convertContentToBase64)
{
content = content.ToBase64String();
}
Content = content;
}
/// <summary>
/// Initializes a new instance of the <see cref="CreateFileRequest"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="branch">The branch the request is for.</param>
/// <param name="convertContentToBase64">True to convert content to base64.</param>
public CreateFileRequest(string message, string content, string branch, bool convertContentToBase64) : base(message, branch)
{
Ensure.ArgumentNotNullOrEmptyString(content, nameof(content));
if (convertContentToBase64)
{
content = content.ToBase64String();
}
Content = content;
}
/// <summary>
/// The contents of the file to create, Base64 encoded. This is required.
/// </summary>
public string Content { get; private set; }
internal virtual string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "Message: {0} Content: {1}", Message, Content);
}
}
}
/// <summary>
/// Represents the parameters to update a file in a repository.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class UpdateFileRequest : CreateFileRequest
{
/// <summary>
/// Creates an instance of a <see cref="UpdateFileRequest" />.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="sha">The sha.</param>
public UpdateFileRequest(string message, string content, string sha)
: this(message, content, sha, true)
{ }
/// <summary>
/// Creates an instance of a <see cref="UpdateFileRequest" />.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="sha">The sha.</param>
/// <param name="branch">The branch the request is for.</param>
public UpdateFileRequest(string message, string content, string sha, string branch)
: this(message, content, sha, branch, true)
{ }
/// <summary>
/// Creates an instance of a <see cref="UpdateFileRequest" />.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="sha">The sha.</param>
/// <param name="convertContentToBase64">True to convert content to base64.</param>
public UpdateFileRequest(string message, string content, string sha, bool convertContentToBase64)
: base(message, content, convertContentToBase64)
{
Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha));
Sha = sha;
}
/// <summary>
/// Creates an instance of a <see cref="UpdateFileRequest" />.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="sha">The sha.</param>
/// <param name="branch">The branch the request is for.</param>
/// <param name="convertContentToBase64">True to convert content to base64.</param>
public UpdateFileRequest(string message, string content, string sha, string branch, bool convertContentToBase64)
: base(message, content, branch, convertContentToBase64)
{
Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha));
Sha = sha;
}
/// <summary>
/// The blob SHA of the file being replaced.
/// </summary>
public string Sha { get; private set; }
internal override string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "SHA: {0} Message: {1}", Sha, Message);
}
}
}
}