Ejemplo n.º 1
0
        public async Task <APIGatewayProxyResponse> ReceiveRequest(APIGatewayProxyRequest request, ILambdaContext context)
        {
            LambdaLogger.Log($"Request Arrived: {request.Body}");
            LambdaLogger.Log($"Headers: {request.Headers}");
            _serviceUrl = Environment.GetEnvironmentVariable("ServiceURL");
            _privateKey = Environment.GetEnvironmentVariable("PrivateKey");

            _amazonDynamoDBclient = new AmazonDynamoDBClient(
                new AmazonDynamoDBConfig
            {
                ServiceURL     = _serviceUrl,
                RegionEndpoint = RegionEndpoint.USEast2
            });

            var headerAction = "";

            request.Headers.TryGetValue("X-GitHub-Event", out headerAction);
            LambdaLogger.Log($"X-GitHub-Event: {headerAction}");


            var requestObject            = (request.Body != null) ? JsonConvert.DeserializeObject <GitHubPREvent>(request.Body) : new GitHubPREvent();
            GitHubEventResponse response = null;

            if (requestObject.Action != null && headerAction.Equals("pull_request"))
            {
                LambdaLogger.Log($"Action: {requestObject.Action}");
                response = await ProcessRequest(requestObject);
            }

            return(CreateResponse(response));
        }
Ejemplo n.º 2
0
        private APIGatewayProxyResponse CreateResponse(GitHubEventResponse requestBody)
        {
            int statusCode = (requestBody != null) ?
                             (int)HttpStatusCode.OK :
                             (int)HttpStatusCode.InternalServerError;


            string body = (requestBody != null) ? JsonConvert.SerializeObject(requestBody) : JsonConvert.SerializeObject(new GitHubEventResponse());

            var response = new APIGatewayProxyResponse
            {
                StatusCode = statusCode,
                Body       = body,
                Headers    = new Dictionary <string, string>
                {
                    { "Content-Type", "application/json" },
                    { "Access-Control-Allow-Origin", "*" }
                }
            };

            return(response);
        }