fetch method

  1. @override
Future<List<CommitInfo>> fetch()

Main method to fetch all the git information and generate the changelog from the source.

Implementation

@override
Future<List<CommitInfo>> fetch() async {
  if (_client == null) {
    configure();
  }
  List<CommitInfo> commits = [];
  var tokens = githubRepo.split("/");

  // TODO: what happens if there are no release?
  var lastTag = await _client!.query(
      query: Options$Query$GetLastTag(
          variables: Variables$Query$GetLastTag(
    owner: tokens[0],
    name: tokens[1],
  )));

  var rawLastTags = Query$GetLastTag.fromJson(lastTag).repository;
  var releases = cleanListOfTags(rawLastTags);
  if (releases.isEmpty) {
    return commits;
  }

  var lastRelease = releases.first;
  if (lastRelease == null) {
    return commits;
  }
  var listCommits = await _client!.query(
      query: Options$Query$GetLastCommits(
          variables: Variables$Query$GetLastCommits(
    owner: tokens[0],
    name: tokens[1],
    branch: fromBranch,
    since: lastRelease.node!.createdAt,
  )));

  var rawCommits = Query$GetLastCommits.fromJson(listCommits).repository;
  var rawListCommit = cleanListOfCommit(rawCommits);

  for (var rawCommit in rawListCommit) {
    var author = CommitAuthor(
        commitDate: DateTime.parse(rawCommit!.committedDate),
        gitNickname: rawCommit.author?.user?.login ?? "",
        email: rawCommit.author?.user?.email ?? "");
    var commitBody = CommitContent(
        commitHeader: rawCommit.messageHeadline,
        commitBody: rawCommit.messageBody);
    var commitInfo = CommitInfo(
        author: author, content: commitBody, url: rawCommit.commitUrl);
    commits.add(commitInfo);
  }
  commits.sort();
  return commits;
}