getReadme method
Fetches the readme file for a repository.
The name of the commit/branch/tag may be specified with ref
. If no ref
is defined, the repository's default branch is used (usually master).
API docs: https://developer.github.com/v3/repos/contents/#get-the-readme
Implementation
Future<GitHubFile> getReadme(RepositorySlug slug, {String? ref}) async {
ArgumentError.checkNotNull(slug);
final headers = <String, String>{};
var url = '/repos/${slug.fullName}/readme';
if (ref != null) {
url += '?ref=$ref';
}
return github.getJSON(url, headers: headers, statusCode: StatusCodes.OK,
fail: (http.Response response) {
if (response.statusCode == StatusCodes.NOT_FOUND) {
throw NotFound(github, response.body);
}
}, convert: (Map<String, dynamic> input) {
var file = GitHubFile.fromJson(input);
file.sourceRepository = slug;
return file;
});
}