public async Task Post([FromBody] DockerRequest request) { var body = @" { ""request"": { ""branch"":""<ImageValidatorBranch>"", ""config"": { ""env"": { ""IMAGE_TAG"": ""<ImageTag>"" } } } }" .Replace("<ImageValidatorBranch>", _integrationOptions.ImageValidatorBranch) .Replace("<ImageTag>", request.PushData.Tag); var labelParts = request.Repository.Dockerfile.Split('\n') .Single(x => x.StartsWith("LABEL", StringComparison.OrdinalIgnoreCase)) .Split('/') .Select(x => x.Trim('"')) .ToArray(); var response = await $"https://api.travis-ci.org/repo/{labelParts[labelParts.Length - 2]}%2F{labelParts[labelParts.Length - 1]}/requests" .WithHeader("Accept", "application/json") .WithHeader("Travis-API-Version", "3") .WithHeader("Authorization", $"token {_integrationOptions.ApiKey}") .PostAsync(new StringContent(body, Encoding.UTF8, "application/json")) .ReceiveJson(); _logger.LogInformation($"Validation build was started for image {request.Repository.RepoName}:{request.PushData.Tag}"); }
public async Task <ActionResult> PostAsync( DockerRequest dockerRequest) { using (Metrics.CreateHistogram("testpoint_POST_docker_duration_seconds", "").NewTimer()) { var sb = new StringBuilder(); var dt = dockerRequest.PushData.PushedAt.ToDateTime(); sb.AppendLine($"Docker push from {dockerRequest.PushData.Pusher} | {dt}"); sb.Append($"{dockerRequest.Repository.RepoName}:{dockerRequest.PushData.Tag}"); _logger.LogInformation(1212, $"{sb.ToString()}"); var dockerImage = new DockerImage { Id = Guid.NewGuid(), Name = dockerRequest.Repository.Name, Namespace = dockerRequest.Repository.Namespace, Owner = dockerRequest.Repository.Owner, Pusher = dockerRequest.PushData.Pusher, RepoName = dockerRequest.Repository.RepoName, RepoUrl = dockerRequest.Repository.RepoUrl, Tag = dockerRequest.PushData.Tag, Updated = DateTime.Now, TimeHash = Guid.NewGuid().ToString() }; var old = await _rep.DockerImage.SelectByImageAsync(dockerRequest.Repository.RepoName, dockerRequest.PushData.Tag); if (old != null) { dockerImage.Id = old.Id; old.Updated = DateTime.Now; old.Pusher = dockerRequest.PushData.Pusher; old.Tag = dockerRequest.PushData.Tag; old.TimeHash = Guid.NewGuid().ToString(); _ = _rep.DockerImage.Update(old); } else { _ = await _rep.DockerImage.InsertAsync(dockerImage); } return(Ok()); } }