editReference method Null safety

Future<GitReference> editReference(
  1. RepositorySlug slug,
  2. String ref,
  3. String? sha,
  4. {bool force = false}
)

Updates a reference in a repository.

API docs: https://developer.github.com/v3/git/refs/#update-a-reference

Implementation

Future<GitReference> editReference(
  RepositorySlug slug,
  String ref,
  String? sha, {
  bool force = false,
}) {
  final body = GitHubJson.encode({'sha': sha, 'force': force});
  // Somehow the reference updates PATCH request needs a valid content-length.
  final headers = {'content-length': body.length.toString()};

  return github
      .request('PATCH', '/repos/${slug.fullName}/git/refs/$ref',
          body: body, headers: headers)
      .then((response) {
    return GitReference.fromJson(
        jsonDecode(response.body) as Map<String, dynamic>);
  });
}