Skip to content

Commit 13e5221

Browse files
committed
Implement full file CRUD
1 parent ddbe61b commit 13e5221

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

lib/src/common/repos_service.dart

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,35 @@ class RepositoriesService extends Service {
309309
});
310310
}
311311

312-
// TODO: Implement updateFile: https://developer.github.com/v3/repos/contents/#update-a-file
313-
// TODO: Implement deleteFile: https://developer.github.com/v3/repos/contents/#delete-a-file
312+
/// Updates the specified file.
313+
///
314+
/// API docs: https://developer.github.com/v3/repos/contents/#update-a-file
315+
Future<ContentCreation> updateFile(RepositorySlug slug, String path, String message, String content, String sha, {String branch}) {
316+
var map = createNonNullMap({
317+
"message": message,
318+
"content": content,
319+
"sha": sha,
320+
"branch": branch
321+
});
322+
323+
return _github.postJSON("/repos/${slug.fullName}/contents/${path}", body: map, statusCode: 200, convert: ContentCreation.fromJSON);
324+
}
325+
326+
/// Deletes the specified file.
327+
///
328+
/// API docs: https://developer.github.com/v3/repos/contents/#delete-a-file
329+
Future<ContentCreation> deleteFile(RepositorySlug slug, String path, String message, String sha, String branch) {
330+
var map = createNonNullMap({
331+
"message": message,
332+
"sha": sha,
333+
"branch": branch
334+
});
314335

336+
return _github.request("DELETE", "/repos/${slug.fullName}/contents/${path}", body: map, statusCode: 200).then((response) {
337+
return ContentCreation.fromJSON(response.asJSON());
338+
});
339+
}
340+
315341
/// Gets an archive link for the specified repository and reference.
316342
///
317343
/// API docs: https://developer.github.com/v3/repos/contents/#get-archive-link

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy