Beispiel #1
0
        public async Task Update([FromBody] PullRequestUpdated pullRequestUpdated)
        {
            //TODO: throw if id not exists
            //if there are reviewers with vote == 10(approved)
            if (pullRequestUpdated.resource.reviewers.Any(y => y.vote == 10))
            {
                //get the existing list of approvers and compare
                var approvers   = _DBHelper.GetApprovers(pullRequestUpdated).Result;
                var newApprover = pullRequestUpdated.resource.reviewers.Where(x => x.vote == 10 && !x.displayName.EndsWith(" Team") && !approvers.Contains(x.displayName));
                if (newApprover.Count() != 1)
                {
                    throw new ArgumentException();
                }                                                               //why would this happen??

                var approvedBy = newApprover.First().displayName;
                var approved   = new Approved
                {
                    pullRequestId = pullRequestUpdated.resource.pullRequestId,
                    approvedBy    = approvedBy,
                    approvedAt    = DateTime.UtcNow
                };
                await _DBHelper.InsertApproved(approved);

                var pullRequests = await _DBHelper.GetPullRequests();

                await _hub.Clients.All.SendAsync("updatePullRequests", pullRequests);
            }
        }
        public async Task <IEnumerable <string> > GetApprovers(PullRequestUpdated pullRequest)
        {
            string selectQuery = "SELECT ApprovedBy FROM Approved WHERE PullRequestid = @pullRequestId";

            using (IDbConnection dbConnection = Connection)
            {
                return(await dbConnection.QueryAsync <string>(selectQuery, pullRequest.resource));
            }
        }