public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var dict = new Dictionary<string, IRepository>(); serializer.Populate(reader, dict); var response = new GetRepositoryResponse(); if (!dict.HasAny()) return response; response.Repositories = dict; return response; }
/// <summary> /// gets the Repository information /// </summary> /// <param name="codeCommit"></param> /// <param name="repositoryName"></param> /// <param name="commitId"></param> /// <returns></returns> private GetRepositoryResponse GetRepositoryInfo(AmazonCodeCommitClient codeCommit, string repositoryName) { GetRepositoryRequest repoRequest = new GetRepositoryRequest() { RepositoryName = repositoryName }; GetRepositoryResponse returnValue = codeCommit.GetRepositoryAsync(repoRequest).GetAwaiter().GetResult(); return(returnValue); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var dict = new Dictionary <string, IRepository>(); serializer.Populate(reader, dict); var response = new GetRepositoryResponse(); if (!dict.HasAny()) { return(response); } response.Repositories = dict; return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetRepositoryResponse response = new GetRepositoryResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("repositoryMetadata", targetDepth)) { var unmarshaller = RepositoryMetadataUnmarshaller.Instance; response.RepositoryMetadata = unmarshaller.Unmarshall(context); continue; } } return(response); }
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"); }
public static void WriteResults(HttpResponseMessage response, string configPath, Cc2AfConfig config, GetRepositoryResponse repository, string region, string repositoryName, string branch, string commit, string srcBranch) { var dictionary = new Dictionary <string, object>() { // Display only fields that do not contain secrets { "Response", new Dictionary <string, object>() { { "Headers", response.Headers }, { "Status", response.StatusCode }, { "ReasonPhrase", response.ReasonPhrase }, { "Content", response.Content }, { "IsSuccessStatusCode", response.IsSuccessStatusCode } } }, { "Resquest", new Dictionary <string, object>() { { "Uri", response.RequestMessage.RequestUri }, { "Method", response.RequestMessage.Method }, { "ContentHeaders", response.Content.Headers } } }, { "ConfigPath", configPath }, { "Config", config }, { "Region", region }, { "Repository", repository }, { "RepositoryName", repositoryName }, { "Branch", branch }, { "Commit", commit }, { "SrcBranch", srcBranch } }; Console.WriteLine(JsonConvert.SerializeObject(dictionary)); }