예제 #1
0
        private async Task SendStatusAsync(Payload payload, ReviewStatus status)
        {
            var owner = payload.repository.owner.login;
            var repo = payload.repository.name;
            var repository = await Client.Repository.Get(owner, repo);
            var issueNumber = payload.issue.number;
            var commits = await Client.Repository.PullRequest.Commits(owner, repo, issueNumber);
            var lastCommit = commits.Last();

            var commitStatus = new NewCommitStatus
            {
                Context = "code-review/treshold",
                State = status.Status,
                Description = status.Comment,

            };
            await Client.Repository.CommitStatus.Create(owner, repo, lastCommit.Sha, commitStatus);
        }
예제 #2
0
 private async Task<ReviewStatus> EvaluateReviewStatusAsync(Payload payload, int threshold)
 {
     var owner = payload.repository.owner.login;
     var repo = payload.repository.name;
     var issueNumber = payload.issue.number;
     var pullRequest = await Client.Repository.PullRequest.Get(owner, repo, issueNumber).ConfigureAwait(false);
     if (pullRequest != null)
     {
         var comments = await Client.Issue.Comment.GetAllForIssue(owner, repo, issueNumber).ConfigureAwait(false);
         var reviewers = new HashSet<string>();
         foreach (var comment in comments)
         {
             if (comment.Body.Contains(Configuration.ReviewedMessage))
             {
                 reviewers.Add(comment.User.Login);
             }
         }
         if (reviewers.Count > (threshold - 1))
         {
             return new ReviewStatus
             {
                 Comment = "Reviewed",
                 Status = CommitState.Success
             };
         }
         return new ReviewStatus
         {
             Comment = $"{reviewers.Count} signatures of {threshold} are done.",
             Status = CommitState.Pending
         };
     }
     return new ReviewStatus
     {
         Comment = $"This request has to be signed by {threshold} reviewers",
         Status = CommitState.Pending
     };
 }
예제 #3
0
 public async Task UpdateStatusAsync(Payload payload)
 {
     var status = await EvaluateReviewStatusAsync(payload, Configuration.Treshold).ConfigureAwait(false);
     await SendStatusAsync(payload, status).ConfigureAwait(false);
 }