private Channel ToClientModelChannel(Maestro.Data.Models.Channel other) { return(new Channel( other.Id, other.Name, other.Classification)); }
private Channel ToClientModelChannel(Maestro.Data.Models.Channel other) { return(new Channel( other.Id, other.Name, other.Classification, other.ChannelReleasePipelines?.Select(rp => ToClientModelReleasePipeline(rp)).ToImmutableList())); }
public virtual async Task <IActionResult> UpdateSubscription(Guid id, [FromBody] SubscriptionUpdate update) { Data.Models.Subscription subscription = await _context.Subscriptions.Where(sub => sub.Id == id) .FirstOrDefaultAsync(); if (subscription == null) { return(NotFound()); } var doUpdate = false; if (!string.IsNullOrEmpty(update.SourceRepository)) { subscription.SourceRepository = update.SourceRepository; doUpdate = true; } if (update.Policy != null) { subscription.PolicyObject = update.Policy.ToDb(); doUpdate = true; } if (!string.IsNullOrEmpty(update.ChannelName)) { Channel channel = await _context.Channels.Where(c => c.Name == update.ChannelName) .FirstOrDefaultAsync(); if (channel == null) { return(BadRequest( new ApiError( "The request is invalid", new[] { $"The channel '{update.ChannelName}' could not be found." }))); } subscription.Channel = channel; doUpdate = true; } if (update.Enabled.HasValue) { subscription.Enabled = update.Enabled.Value; doUpdate = true; } if (doUpdate) { _context.Subscriptions.Update(subscription); await _context.SaveChangesAsync(); } return(Ok(new Subscription(subscription))); }
public async Task <IActionResult> Update(int id, [FromBody] DefaultChannel.DefaultChannelUpdateData update) { Data.Models.DefaultChannel defaultChannel = await _context.DefaultChannels.FindAsync(id); if (defaultChannel == null) { return(NotFound()); } bool doUpdate = false; if (!string.IsNullOrEmpty(update.Branch)) { defaultChannel.Branch = update.Branch; doUpdate = true; } if (!string.IsNullOrEmpty(update.Repository)) { defaultChannel.Repository = update.Repository; doUpdate = true; } if (update.ChannelId.HasValue) { int channelId = update.ChannelId.Value; Channel channel = await _context.Channels.FindAsync(channelId); if (channel == null) { return(NotFound(new ApiError($"The channel with id '{channelId}' was not found."))); } defaultChannel.ChannelId = channelId; defaultChannel.Channel = channel; doUpdate = true; } if (update.Enabled.HasValue) { defaultChannel.Enabled = update.Enabled.Value; doUpdate = true; } if (doUpdate) { _context.DefaultChannels.Update(defaultChannel); await _context.SaveChangesAsync(); } return(Ok(new DefaultChannel(defaultChannel))); }
public virtual async Task <IActionResult> Create([FromBody, Required] SubscriptionData subscription) { Channel channel = await _context.Channels.Where(c => c.Name == subscription.ChannelName) .FirstOrDefaultAsync(); if (channel == null) { return(BadRequest( new ApiError( "the request is invalid", new[] { $"The channel '{subscription.ChannelName}' could not be found." }))); } Data.Models.Repository repo = await _context.Repositories.FindAsync(subscription.TargetRepository); if (subscription.TargetRepository.Contains("github.com")) { // If we have no repository information or an invalid installation id // then we will fail when trying to update things, so we fail early. if (repo == null || repo.InstallationId <= 0) { return(BadRequest( new ApiError( "the request is invalid", new[] { $"The repository '{subscription.TargetRepository}' does not have an associated github installation. " + "The Maestro github application must be installed by the repository's owner and given access to the repository." }))); } } // In the case of a dev.azure.com repository, we don't have an app installation, // but we should add an entry in the repositories table, as this is required when // adding a new subscription policy. // NOTE: // There is a good chance here that we will need to also handle <account>.visualstudio.com // but leaving it out for now as it would be preferred to use the new format else if (subscription.TargetRepository.Contains("dev.azure.com")) { if (repo == null) { _context.Repositories.Add( new Data.Models.Repository { RepositoryName = subscription.TargetRepository, InstallationId = default });
public async Task <IActionResult> Create([FromBody, Required] DefaultChannel.DefaultChannelCreateData data) { int channelId = data.ChannelId; Channel channel = await _context.Channels.FindAsync(channelId); if (channel == null) { return(NotFound(new ApiError($"The channel with id '{channelId}' was not found."))); } Data.Models.DefaultChannel defaultChannel; // Due to abundant retry logic, we'll return a normal response even if this is creating a duplicate, by simply // returning the one that already exists vs. HTTP 409 / 500 var existingInstance = _context.DefaultChannels .Where(d => d.Channel == channel && d.Repository == data.Repository && d.Branch == data.Branch) .FirstOrDefault(); if (existingInstance != null) { defaultChannel = existingInstance; } else { defaultChannel = new Data.Models.DefaultChannel { Channel = channel, Repository = data.Repository, Branch = data.Branch, Enabled = data.Enabled ?? true }; await _context.DefaultChannels.AddAsync(defaultChannel); await _context.SaveChangesAsync(); } return(CreatedAtRoute( new { action = "Get", id = defaultChannel.Id }, new DefaultChannel(defaultChannel))); }