Beispiel #1
0
        public async Task <(string fileName, Uri artifactUri)> GetArtifactAsync(int buildNumber, BuildRequest request)
        {
            var url = $"https://circleci.com/api/v1.1/project/github/MarshallOfSound/Google-Play-Music-Desktop-Player-UNOFFICIAL-/{buildNumber}/artifacts";

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                var json = await client.GetStringAsync(url);

                var artifacts  = JsonSerializer.Deserialize <List <CircleCIArtifact> >(json.Trim('(', ')'));
                var firstMatch = artifacts.FirstOrDefault(a => a.Path.Contains(request.ToMatchString()));
                if (firstMatch == null)
                {
                    throw new Exception("Valid artifact not found!");
                }
                return(System.IO.Path.GetFileName(firstMatch.Path), new Uri(firstMatch.Url));
            }
        }