Пример #1
0
        private async Task <Build?> GetOldestUnconsumedBuild(int lastConsumedBuildOfDependencyId)
        {
            // Note: We fetch `build` again here so that it will have channel information, which it doesn't when coming from the graph :(
            var build = await _client.GetBuildAsync(lastConsumedBuildOfDependencyId, ApiVersion8._20190116, CancellationToken.None);

            var buildCollection = await _client.ListBuildsAsync(
                build.GitHubRepository,
                commit : null,
                buildNumber : null,
                channelId : build.Channels.FirstOrDefault(c => c.Classification == "product" || c.Classification == "tools")?.Id,
                notBefore : build.DateProduced.Subtract(TimeSpan.FromSeconds(5)),
                notAfter : null,
                loadCollections : false,
                page : null,
                perPage : null,
                api_version : ApiVersion6._20190116,
                CancellationToken.None);

            var publishedBuildsOfDependency = new List <Build>(buildCollection);

            var last = publishedBuildsOfDependency.LastOrDefault();

            if (last == null)
            {
                this._logger.LogWarning("Last build didn't match last consumed build, treating dependency '{Dependency}' as up to date", build.GitHubRepository);
                return(null);
            }

            if (last.AzureDevOpsBuildId != build.AzureDevOpsBuildId)
            {
                this._logger.LogWarning("Last build didn't match last consumed build");
            }

            return(publishedBuildsOfDependency.Count > 1
                ? publishedBuildsOfDependency[publishedBuildsOfDependency.Count - 2]
                : null);
        }