/// <summary> /// Get a specific build of a repository /// </summary> /// <returns>Process exit code.</returns> public override async Task <int> ExecuteAsync() { try { IRemote remote = RemoteFactory.GetBarOnlyRemote(_options, Logger); Build build = await remote.GetBuildAsync(_options.Id); if (build != null) { OutputHelpers.PrintBuild(build); } else { Console.WriteLine($"Could not find build with id '{_options.Id}'"); return(Constants.ErrorCode); } return(Constants.SuccessCode); } catch (Exception e) { Logger.LogError(e, $"Error: Failed to retrieve build with id '{_options.Id}'"); return(Constants.ErrorCode); } }
/// <summary> /// Assigns a build to a channel. /// </summary> /// <returns>Process exit code.</returns> public override async Task <int> ExecuteAsync() { try { IRemote remote = RemoteFactory.GetBarOnlyRemote(_options, Logger); // Find the build to give someone info Build build = await remote.GetBuildAsync(_options.Id); if (build == null) { Console.WriteLine($"Could not find a build with id '{_options.Id}'"); return(Constants.ErrorCode); } Channel targetChannel = await UxHelpers.ResolveSingleChannel(remote, _options.Channel); if (targetChannel == null) { return(Constants.ErrorCode); } if (build.Channels.Any(c => c.Id == targetChannel.Id)) { Console.WriteLine($"Build '{build.Id}' has already been assigned to '{targetChannel.Name}'"); return(Constants.SuccessCode); } Console.WriteLine($"Assigning the following build to channel '{targetChannel.Name}':"); Console.WriteLine(); OutputHelpers.PrintBuild(build); await remote.AssignBuildToChannel(_options.Id, targetChannel.Id); // Be helpful. Let the user know what will happen. string buildRepo = build.GitHubRepository ?? build.AzureDevOpsRepository; List <Subscription> applicableSubscriptions = (await remote.GetSubscriptionsAsync( sourceRepo: buildRepo, channelId: targetChannel.Id)).ToList(); PrintSubscriptionInfo(applicableSubscriptions); return(Constants.SuccessCode); } catch (Exception e) { Logger.LogError(e, $"Error: Failed to assign build '{_options.Id}' to channel '{_options.Channel}'."); return(Constants.ErrorCode); } }
/// <summary> /// Gets the latest build for a repo /// </summary> /// <returns>Process exit code.</returns> public override async Task <int> ExecuteAsync() { try { IRemote remote = RemoteFactory.GetBarOnlyRemote(_options, Logger); // Calculate out possible repos based on the input strings. // Today the DB has no way of searching for builds by substring, so for now // grab source/targets repos of subscriptions matched on substring, // and then add the explicit repo from the options. // Then search channels by substring // Then run GetLatestBuild for each permutation. var subscriptions = await remote.GetSubscriptionsAsync(); var possibleRepos = subscriptions .SelectMany(subscription => new List <string> { subscription.SourceRepository, subscription.TargetRepository }) .Where(r => r.Contains(_options.Repo, StringComparison.OrdinalIgnoreCase)) .ToHashSet(StringComparer.OrdinalIgnoreCase); possibleRepos.Add(_options.Repo); var channels = (await remote.GetChannelsAsync()) .Where(c => string.IsNullOrEmpty(_options.Channel) || c.Name.Contains(_options.Channel, StringComparison.OrdinalIgnoreCase)); if (!channels.Any()) { Console.WriteLine($"Could not find a channel with name containing '{_options.Channel}'"); return(Constants.ErrorCode); } bool foundBuilds = false; foreach (string possibleRepo in possibleRepos) { foreach (Channel channel in channels) { Build latestBuild = await remote.GetLatestBuildAsync(possibleRepo, channel.Id); if (latestBuild != null) { if (foundBuilds) { Console.WriteLine(); } foundBuilds = true; OutputHelpers.PrintBuild(latestBuild); } } } if (!foundBuilds) { Console.WriteLine("No latest build found matching the specified criteria"); return(Constants.ErrorCode); } return(Constants.SuccessCode); } catch (Exception e) { Logger.LogError(e, "Error: Failed to retrieve latest build."); return(Constants.ErrorCode); } }