/// <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); }
/// <summary> /// A function to handle a CodeCommit Event. /// </summary> /// <param name="commitEvent"></param> /// <param name="context"></param> /// <returns></returns> public void FunctionHandler(CodeCommitEvent commitEvent, ILambdaContext context) { string repositoryName = commitEvent.Records[0].RepositoryName; string branch = commitEvent.Records[0].codecommit.references[0].Branch; string commit = commitEvent.Records[0].codecommit.references[0].commit; string region = commitEvent.Records[0].awsRegion; string configPath = Environment.GetEnvironmentVariable(ConfigPathEnvVar); configPath = String.IsNullOrWhiteSpace(configPath) ? ConfigPathDefault : configPath; var codeCommit = new AmazonCodeCommitClient(RegionEndpoint.GetBySystemName(region)); var repository = codeCommit.GetRepositoryAsync( new GetRepositoryRequest() { RepositoryName = repositoryName } ).GetAwaiter().GetResult(); var config = GetCc2AfConfig(codeCommit, repositoryName, commit, configPath); var srcBranch = String.IsNullOrWhiteSpace(config.CodeCommitBranch) ? SrcBranchDefault : config.CodeCommitBranch; HttpResponseMessage response = null; if (branch == srcBranch) { var deploymentPassword = ConvertFromEncryptedBase64(config.DeploymentPassword); var codeCommitPassword = ConvertFromEncryptedBase64(config.CodeCommitPassword); response = InvokeDeployment(http: Http, deploymentAppUrl: config.DeploymentTriggerUrl, deploymentAppName: config.DeploymentAppName, deploymentUser: config.DeploymentUser, deploymentPassword: deploymentPassword, codeCommitHttpsUrl: repository.RepositoryMetadata.CloneUrlHttp, codeCommitUser: config.CodeCommitUser, codeCommitPassword: codeCommitPassword); } WriteResults(response, configPath, config, repository, region, repositoryName, branch, commit, srcBranch); }