/// <summary> /// Called when the command is to be executed. /// </summary> protected override int ExecuteCore() { Console.WriteLine($"Pruning features for product {Options.ProductName} in Augurk at {Options.AugurkUrl}"); using (var client = AugurkHttpClientFactory.CreateHttpClient(Options)) { try { // Get features of the provided product (and group name if provided) var groups = string.IsNullOrWhiteSpace(Options.GroupName) ? this.GetGroupsForProduct(client) : this.GetFeaturesForGroup(client); foreach (var group in groups) { Console.WriteLine($"Processing features in group {group.Name}"); foreach (var feature in group.Features) { var versions = this.GetVersionsForFeature(client, group.Name, feature).ToList(); List <string> versionsToDelete; if (Options.PrereleaseOnly) { versionsToDelete = versions.Where(version => version.Contains("-")).ToList(); } else { versionsToDelete = versions.Where(version => Regex.Match(version, Options.VersionRegex).Success).ToList(); } Console.WriteLine($"\tFound {versions.Count} version(s) for feature {feature.Title} of which {versionsToDelete.Count} will be deleted"); foreach (var versionToDelete in versionsToDelete) { DeleteVersionOfFeature(client, group.Name, feature, versionToDelete); } } } Console.WriteLine("Finished pruning features."); return(0); } catch (Exception ex) { Console.Error.WriteLine($"An error occured while pruning features in Augurk at {Options.AugurkUrl}"); Console.Error.WriteLine(ex.ToString()); return(-1); } } }
/// <summary> /// Publishes the product description. /// </summary> private void PublishProductDescription() { // Make sure that the product description file exists if (!File.Exists(Options.ProductDescription)) { Console.Error.WriteLine($"Product description file {Options.ProductDescription} does not exist!"); return; } // Upload the contents of the file to Augurk using (var client = AugurkHttpClientFactory.CreateHttpClient(Options)) { // Determine the Uri for the product and read the contents of the file string productUri = $"{Options.AugurkUrl.TrimEnd('/')}/api/v2/products/{Options.ProductName}/description"; string productDescription = File.ReadAllText(Options.ProductDescription); // Process the description through the images embedder productDescription = ProcessDescription(productDescription); try { // Perform a Put request to the API var response = client.PutAsync(productUri, new StringContent(productDescription, System.Text.Encoding.UTF8, "text/plain")).Result; if (response.IsSuccessStatusCode) { Console.WriteLine($"Succesfully published description for product {Options.ProductName} from {Options.ProductDescription}"); } else { Console.WriteLine($"Publishing description for product {Options.ProductName} to {productUri} resulted in status code {response.StatusCode}"); } } catch (Exception ex) { Console.Error.WriteLine($"An error occured while publishing the product description file {Options.ProductDescription}"); Console.Error.WriteLine(ex.ToString()); } } }
private int PublishFeatureFiles() { // Create the HttpClient that will communicate with the API bool usev2api = !string.IsNullOrWhiteSpace(Options.ProductName); using (var client = AugurkHttpClientFactory.CreateHttpClient(Options)) { // Get the base uri for all further operations string groupUri = GetGroupUri(usev2api); // Clear any existing features in this group, if required if (!usev2api && Options.ClearGroup) { Console.WriteLine($"Clearing existing features in group {Options.GroupName ?? "Default"} for branch {Options.BranchName}."); try { client.DeleteAsync(groupUri).Wait(); } catch (Exception e) { Console.Error.WriteLine($"An exception occured while clearing existing features in group {Options.GroupName ?? "Default"} for branch {Options.BranchName}."); Console.Error.WriteLine(e.ToString()); return(-1); } } // Parse and publish each of the provided feature files var expandedList = Expand(Options.FeatureFiles, Options.Recursive); foreach (var featureFile in expandedList) { try { // Parse the feature and convert it to the correct format Feature feature = ParseFeatureFile(featureFile); // Get the uri to which the feature should be published string targetUri = GetTargetUri(usev2api, groupUri, feature); // Publish the feature var response = client.PostAsJsonAsync <Feature>(targetUri, feature).Result; // Process the result if (response.IsSuccessStatusCode) { WriteSuccesfulPublishMessage(usev2api, feature); } else { WriteUnsuccesfulPublishMessage(usev2api, targetUri, feature, response); return(-1); } } catch (InvalidOperationException) { Console.Out.WriteLine($"WARNING: Unable to parse feature file '{featureFile}' since it doesn't contain any Gherkin content."); } catch (CompositeParserException) { Console.Out.WriteLine($"WARNING: Unable to parse feature file '{featureFile}'. Are you missing a language comment or --language option?"); } catch (Exception e) { Console.Error.WriteLine($"An exception occured while uploading feature file '{featureFile}"); Console.Error.WriteLine(e.ToString()); return(-1); } } } return(0); }
/// <summary> /// Called when the command is to be executed. /// </summary> protected override int ExecuteCore() { // Determine the base Uri we're going to perform the delete on var baseUri = new Uri($"{Options.AugurkUrl}/api/v2/products/{Options.ProductName}/"); var deleteUri = baseUri; // If a group name is specified if (!String.IsNullOrWhiteSpace(Options.GroupName)) { // Append it to the base uri deleteUri = new Uri(deleteUri, $"groups/{Options.GroupName}/"); } // If a feature name is specified if (!String.IsNullOrWhiteSpace(Options.FeatureName)) { // Make sure that the group name is also specified if (String.IsNullOrWhiteSpace(Options.GroupName)) { Console.WriteLine("When deleting a specific feature a group name that the feature belongs to must also be specified."); return(-1); } // Append the feature name to the base uri deleteUri = new Uri(deleteUri, $"features/{Options.FeatureName}/"); } // If a version is specified if (!String.IsNullOrWhiteSpace(Options.Version)) { // Append the version to the base uri deleteUri = new Uri(deleteUri, $"versions/{Options.Version}/"); } // Perform the delete operation using (var client = AugurkHttpClientFactory.CreateHttpClient(Options)) { // Call the URL var response = client.DeleteAsync(deleteUri).Result; if (response.IsSuccessStatusCode) { if (!String.IsNullOrWhiteSpace(Options.FeatureName)) { Console.WriteLine($"Succesfully deleted feature {Options.FeatureName} from Augurk at {Options.AugurkUrl}"); } else { Console.WriteLine($"Succesfully deleted features from Augurk at {Options.AugurkUrl}"); } return(0); } else { if (!String.IsNullOrWhiteSpace(Options.FeatureName)) { Console.WriteLine($"Deleting feature {Options.FeatureName} from Augurk at {Options.AugurkUrl} failed with statuscode {response.StatusCode}"); } else { Console.WriteLine($"Deleting features from Augurk at {Options.AugurkUrl} failed with statuscode {response.StatusCode}"); } return(-1); } } }