Exemple #1
0
        /// <summary>
        /// this is our callback for all of the AWS triggers and notifications. We do not
        /// use the AWS LambdaSerializer because we are processing more than
        /// one type of JSON data packages on the same endpoint.
        ///
        ///Use this name to register with Lambda
        ///BalsamicSolutions.CodeCommit2Slack::BalsamicSolutions.CodeCommit2Slack.LambdaNotificationHandlers::HandleEvent
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        public void HandleEvent(Stream input, ILambdaContext context)
        {
            string jsonAsText = string.Empty;

            Console.WriteLine("Dispatching CodeCommitEvent");
            if (null != input)
            {
                StreamReader streamReader = new StreamReader(input);
                jsonAsText = streamReader.ReadToEnd();
            }
            Console.WriteLine($"CodeCommitEvent: received the following JSON: {jsonAsText}");
            if (_Enabled)
            {
                //instead of desesralizing the object, look for the "Records" text which indicates we have a
                //branch notification, its faster than parsing the entire jsonData twice for a typed object
                int indexOfRecords = jsonAsText.IndexOf("\"Records\"", 0, StringComparison.OrdinalIgnoreCase);
                if (-1 == indexOfRecords)
                {
                    PullTypes.CodeCommitPullEvent codeCommitEvent = jsonAsText.FromJson <PullTypes.CodeCommitPullEvent>();
                    HandlePullEvent(codeCommitEvent, context);
                }
                else
                {
                    BranchTypes.CodeCommitBranchEvent codeCommitEvent = jsonAsText.FromJson <BranchTypes.CodeCommitBranchEvent>();
                    HandleBranchEvent(codeCommitEvent, context);
                }
            }
            else
            {
                Console.WriteLine("This Lambda handler requires additional configuration");
            }
            Console.WriteLine("Dispatch of CodeCommitEvent complete");
        }
Exemple #2
0
 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;
         SlackClient slackClient         = new SlackClient(_SlackUrl);
         slackClient.PostMessage(notificationMessage);
     }
     Console.WriteLine("Completed HandlePullEvent");
 }