Skip to content

Instantly share code, notes, and snippets.

@litichevskiydv
Created July 22, 2017 10:04
Show Gist options
  • Save litichevskiydv/35c46b5fb1747de8991f275afd790e58 to your computer and use it in GitHub Desktop.
Save litichevskiydv/35c46b5fb1747de8991f275afd790e58 to your computer and use it in GitHub Desktop.
[HttpPost]
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}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment