public void HandlePullEvent(PullTypes.CodeCommitPullEvent input, ILambdaContext context)
 {
     Console.WriteLine("Starting HandlePullEvent");
     if (_Enabled)
     {
         //for this one we are just going to re use the existing notification body
         string        notificationMessage = input.Detail.NotificationBody;
         ChannelClient teamsClient         = new ChannelClient(_TeamsChannelUrls);
         teamsClient.PostMessage(notificationMessage);
     }
     Console.WriteLine("Completed HandlePullEvent");
 }
        public void HandleBranchEvent(BranchTypes.CodeCommitBranchEvent input, ILambdaContext context)
        {
            Console.WriteLine("Starting HandleBranchEvent");
            if (_Enabled)
            {
                string commitId  = "Unknown CommitID";
                string refBranch = "Unknown Branch";

                BranchTypes.Record     ccRecord     = input.Records[0];
                BranchTypes.Codecommit commitRecord = ccRecord.Codecommit;
                //I have only seen multiple references nodes in the test data
                //so we only process record [0]
                if (null != commitRecord && null != commitRecord.References && commitRecord.References.Length > 0)
                {
                    bool isDelete  = false;
                    bool isCreated = false;
                    BranchTypes.Reference ccRef = commitRecord.References[0];
                    commitId  = ccRef.Commit;
                    refBranch = ccRef.Ref;
                    if (ccRef.Deleted.HasValue)
                    {
                        isDelete = ccRef.Deleted.Value;
                    }
                    else if (ccRef.Created.HasValue)
                    {
                        isCreated = true;
                    }

                    string[] branchParts                 = refBranch.Split('/');
                    string   branchName                  = branchParts[branchParts.Length - 1];
                    string   eventSourceARN              = ccRecord.EventSourceArn;
                    string[] eventSourcARNParts          = eventSourceARN.Split(':');
                    string   repositoryName              = eventSourcARNParts[5];
                    string   regionName                  = eventSourcARNParts[3];
                    Amazon.RegionEndpoint regionEndPoint = Amazon.RegionEndpoint.GetBySystemName(regionName);
                    string   userIdentityARN             = ccRecord.UserIdentityArn;
                    string   eventTimeAsText             = ccRecord.EventTime;
                    DateTime eventTime = DateTime.Parse(eventTimeAsText).ToUniversalTime();
                    DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(eventTime, _TimeZone);

                    using (AmazonCodeCommitClient codeCommit = new AmazonCodeCommitClient(_AwsCredentials, regionEndPoint))
                    {
                        GetRepositoryResponse repositoryInfo = GetRepositoryInfo(codeCommit, repositoryName);
                        GetCommitResponse     commitInfo     = GetCommitInfo(codeCommit, repositoryName, commitId);
                        string authorName          = userIdentityARN.LastSplitElement('/');
                        string notificationMessage = "Unknown Lambda Event";
                        if (isCreated)
                        {
                            notificationMessage = GenerateBranchCreateMessage(authorName, localTime, repositoryName, branchName);
                        }
                        else if (isDelete)
                        {
                            notificationMessage = GenerateBranchDeleteMessage(authorName, localTime, repositoryName, branchName);
                        }
                        else
                        {
                            string commitParentId = "HEAD";
                            if (commitInfo.Commit.Parents.Count > 0)
                            {
                                commitParentId = commitInfo.Commit.Parents[0];
                            }
                            List <Difference> commitDifferences = GetCommitDifferences(codeCommit, repositoryName, commitId, commitParentId, _MaxChangesWarningThreshold);
                            if (_MaxChangesWarningThreshold > 0 && commitDifferences.Count >= _MaxChangesWarningThreshold)
                            {
                                notificationMessage = GenerateBranchWarningMessage(authorName, commitId, localTime, commitInfo.Commit.Message, repositoryName, branchName);
                            }
                            else
                            {
                                notificationMessage = GenerateBranchCommitMessage(authorName, commitId, localTime, commitInfo.Commit.Message, repositoryName, branchName, commitDifferences);
                            }
                        }
                        ChannelClient teamsClient = new ChannelClient(_TeamsChannelUrls);
                        teamsClient.PostMessage(notificationMessage);
                    }
                }
                else
                {
                    Console.WriteLine("No References node, nothing to process");
                }
            }
            Console.WriteLine("Completed HandleBranchEvent");
        }