static Startup() { Triggers <BuildChannel> .Inserting += entry => { BuildAssetRegistryContext context = entry.Context as BuildAssetRegistryContext; BuildChannel entity = entry.Entity; Build build = context.Builds.Find(entity.BuildId); if (build == null) { ILogger <Startup> logger = context.GetService <ILogger <Startup> >(); logger.LogError($"Could not find build with id {entity.BuildId} in BAR. Skipping pipeline triggering."); } else { if (build.PublishUsingPipelines && ChannelHasAssociatedReleasePipeline(entity.ChannelId, context)) { entry.Cancel = true; var queue = context.GetService <BackgroundQueue>(); var releasePipelineRunner = context.GetService <IReleasePipelineRunner>(); queue.Post(() => releasePipelineRunner.StartAssociatedReleasePipelinesAsync(entity.BuildId, entity.ChannelId)); } } }; Triggers <BuildChannel> .Inserted += entry => { DbContext context = entry.Context; BuildChannel entity = entry.Entity; var queue = context.GetService <BackgroundQueue>(); var dependencyUpdater = context.GetService <IDependencyUpdater>(); queue.Post(() => dependencyUpdater.StartUpdateDependenciesAsync(entity.BuildId, entity.ChannelId)); }; }
static Startup() { Triggers <BuildChannel> .Inserted += entry => { BuildAssetRegistryContext context = entry.Context as BuildAssetRegistryContext; ILogger <Startup> logger = context.GetService <ILogger <Startup> >(); BuildChannel entity = entry.Entity; Build build = context.Builds .Include(b => b.Assets) .ThenInclude(a => a.Locations) .FirstOrDefault(b => b.Id == entity.BuildId); if (build == null) { logger.LogError($"Could not find build with id {entity.BuildId} in BAR. Skipping dependency update."); } else { bool hasAssetsWithPublishedLocations = build.Assets .Any(a => a.Locations.Any(al => al.Type != LocationType.None && !al.Location.EndsWith("/artifacts"))); if (hasAssetsWithPublishedLocations || ReposWithoutAssetLocationAllowList.Contains(build.GitHubRepository)) { var queue = context.GetService <IBackgroundQueue>(); queue.Post <StartDependencyUpdate>(StartDependencyUpdate.CreateArgs(entity)); } else { logger.LogInformation($"Skipping Dependency update for Build {entity.BuildId} because it contains no assets in valid locations"); } } }; }
static Startup() { Triggers <BuildChannel> .Inserting += entry => { BuildAssetRegistryContext context = entry.Context as BuildAssetRegistryContext; BuildChannel entity = entry.Entity; Build build = context.Builds.Find(entity.BuildId); if (build == null) { ILogger <Startup> logger = context.GetService <ILogger <Startup> >(); logger.LogError($"Could not find build with id {entity.BuildId} in BAR. Skipping pipeline triggering."); } else { if (build.PublishUsingPipelines && ChannelHasAssociatedReleasePipeline(entity.ChannelId, context)) { entry.Cancel = true; var queue = context.GetService <BackgroundQueue>(); var releasePipelineRunner = context.GetService <IReleasePipelineRunner>(); queue.Post(() => releasePipelineRunner.StartAssociatedReleasePipelinesAsync(entity.BuildId, entity.ChannelId)); } } }; Triggers <BuildChannel> .Inserted += entry => { BuildAssetRegistryContext context = entry.Context as BuildAssetRegistryContext; ILogger <Startup> logger = context.GetService <ILogger <Startup> >(); BuildChannel entity = entry.Entity; Build build = context.Builds .Include(b => b.Assets) .ThenInclude(a => a.Locations) .FirstOrDefault(b => b.Id == entity.BuildId); if (build == null) { logger.LogError($"Could not find build with id {entity.BuildId} in BAR. Skipping dependency update."); } else { bool hasAssetsWithPublishedLocations = build.Assets .Any(a => a.Locations.Any(al => al.Type != LocationType.None && !al.Location.EndsWith("/artifacts"))); if (hasAssetsWithPublishedLocations) { var queue = context.GetService <BackgroundQueue>(); var dependencyUpdater = context.GetService <IDependencyUpdater>(); queue.Post(() => dependencyUpdater.StartUpdateDependenciesAsync(entity.BuildId, entity.ChannelId)); } else { logger.LogInformation($"Skipping Dependency update for Build {entity.BuildId} because it contains no assets in valid locations"); } } }; }
/// <summary> /// Github authentication. /// </summary> /// <param name="issueRepo">Repository where gitHub issue is created.</param> /// <returns>Authenticated GithubClient</returns> private async Task <GitHubClient> AuthenticateGitHubClient(string issueRepo) { IGitHubTokenProvider gitHubTokenProvider = _context.GetService <IGitHubTokenProvider>(); long installationId = await _context.GetInstallationId(issueRepo); string gitHubToken = await gitHubTokenProvider.GetTokenForInstallationAsync(installationId); _logger.LogInformation($"GitHub token acquired for '{issueRepo}'"); string version = Assembly.GetExecutingAssembly() .GetCustomAttribute <AssemblyInformationalVersionAttribute>() .InformationalVersion; ProductHeaderValue product = new ProductHeaderValue("Maestro", version); return(new GitHubClient(product) { Credentials = new Credentials(gitHubToken), }); }
static Build() { Triggers <Build> .Inserted += entry => { // The need to check for null here is because these properties are usually set in Startup.cs in Maestro.Web // however they aren't set for unit test cases but this class is used there. if (s_dynamicConfigs != null) { bool.TryParse(s_dynamicConfigs["EnableAutoBuildPromotion"], out var autoBuildPromotion); if (autoBuildPromotion) { Build build = entry.Entity; var context = (BuildAssetRegistryContext)entry.Context; context.BuildChannels.AddRange(( from dc in context.DefaultChannels where (dc.Enabled) where (dc.Repository == build.GitHubRepository || dc.Repository == build.AzureDevOpsRepository) where (dc.Branch == build.GitHubBranch || dc.Branch == build.AzureDevOpsBranch) select new BuildChannel { Channel = dc.Channel, Build = build, DateTimeAdded = DateTimeOffset.UtcNow }).Distinct()); context.SaveChangesWithTriggers(b => context.SaveChanges(b)); } } else { BuildAssetRegistryContext context = entry.Context as BuildAssetRegistryContext; ILogger <Build> logger = context.GetService <ILogger <Build> >(); logger.LogInformation("Automatic build promotion is disabled because no App Configuration was available."); } }; }