private void UpdateStatus(JObject contents, IGitHubStatusChanges gitHubStatusChanges)
 {
     gitHubStatusChanges.ReceiveCommitStatus(contents["sha"].ToString(),
                                             new GitService.CommitStatus
     {
         Key         = contents["context"].ToString(),
         Description = contents["description"].ToString(),
         Url         = contents["target_url"].ToString(),
         State       = GitHubConverters.ToCommitState(contents["state"].ToString()),
     });
 }
        private void UpdatePullRequestReview(JObject contents, IGitHubPullRequestChanges gitHubPullRequestChanges)
        {
            var targetPrId = contents["pull_request"]["number"].ToString();
            var state      = GitHubConverters.ToApprovalState(contents["review"]["state"].ToString());

            if (state.HasValue)
            {
                gitHubPullRequestChanges.ReceivePullRequestReview(id: targetPrId, review: new GitService.PullRequestReview
                {
                    Author        = contents["review"]["user"]["login"].ToString(),
                    State         = state.Value,
                    SubmittedDate = contents["review"].Value <DateTimeOffset>("submitted_at").ToString("s", System.Globalization.CultureInfo.InvariantCulture),
                    Url           = contents["review"]["_links"]["html"]["href"].ToString()
                }, remove: contents["action"].ToString() == "dismissed");
            }
        }
 private ImmutableList <PullRequestReview> ToPullRequestReviews(JArray data)
 {
     return((from entry in data
             let user = entry["author"]["login"].ToString()
                        let state = GitHubConverters.ToApprovalState(entry["state"].ToString())
                                    where state.HasValue
                                    group new
     {
         state = state.Value,
         createdAt = entry["createdAt"].ToString(),
         resourcePath = entry["resourcePath"].ToString()
     } by user into states
             let target = states.OrderByDescending(t => t.createdAt).Last()
                          select new PullRequestReview
     {
         State = target.state,
         SubmittedDate = target.createdAt,
         Url = ResourcePathToUrl(target.resourcePath.ToString()),
         Author = states.Key,
     }).ToImmutableList());
 }
        public async Task <ImmutableDictionary <string, ImmutableList <CommitStatus> > > GetCommitStatuses(ImmutableList <string> commitShas)
        {
            if (!serviceOptions.CheckStatus)
            {
                return(commitShas.Distinct().ToImmutableDictionary(sha => sha, _ => ImmutableList <CommitStatus> .Empty));
            }

            var needed = commitShas.Where(sha => !commitStatus.ContainsKey(sha)).ToHashSet();

            if (needed.Count > 0)
            {
                var requests = string.Join("\n    ",
                                           from sha in needed.Distinct()
                                           select $"_{sha}: object(oid: \"{sha}\") {{ ...commitStatus }}"
                                           );

                var data = await graphqlClient.Query(@"
query($owner: String!, $repository: String!) {
  repository(owner: $owner, name: $repository) {
    " + requests + @"
  }
  ...rateLimit
}

fragment commitStatus on Commit {
  status {
    contexts {
      context
      targetUrl
      description
      state
    }
    state
  }
}
" + rateLimitFragment, new
                {
                    owner,
                    repository
                }).ConfigureAwait(false);

                var result = (from sha in commitShas.Distinct()
                              select new
                {
                    sha,
                    result = data["repository"]["_" + sha] != null &&
                             data["repository"]["_" + sha].Type != JTokenType.Null &&
                             data["repository"]["_" + sha]["status"].Type != JTokenType.Null
                                            ? from entry in data["repository"]["_" + sha]["status"]["contexts"] as JArray
                             select new CommitStatus
                    {
                        Key = entry["context"].ToString(),
                        Url = entry["targetUrl"].ToString(),
                        Description = entry["description"].ToString(),
                        State = GitHubConverters.ToCommitState(entry["state"].ToString())
                    }
                                            : Enumerable.Empty <CommitStatus>()
                }).ToImmutableDictionary(v => v.sha, v => v.result.ToImmutableList());

                foreach (var entry in needed)
                {
                    commitStatus.TryAdd(entry, result[entry]);
                }
            }
            return(commitShas.Distinct().ToImmutableDictionary(sha => sha, sha => commitStatus[sha]));
        }