コード例 #1
0
        /// <summary>
        /// Searches for features which match te specified query (e.g. contain the content)
        /// </summary>
        /// <param name="query"></param>
        /// <returns>An enumerable of <see cref="FeatureMatch"/> instances containing the matches.</returns>
        public async Task <IEnumerable <FeatureMatch> > Search(string query)
        {
            using (var session = _storeProvider.Store.OpenAsyncSession())
            {
                var featureQuery = session.Query <DbFeature>()
                                   .Search(feature => feature.Description, query, 5)
                                   .Search(feature => feature.Scenarios, query, 5)
                                   .Search(feature => feature.Background, query, 5)
                                   .Search(feature => feature.Tags, query, 9)
                                   .Search(feature => feature.Title, query, 10);

                var queryResults = await featureQuery.ToListAsync();

                var comparer = new SemanticVersionComparer();

                var filteredResultsQuery = queryResults.Where(feature =>
                                                              !queryResults.Any(feature2 => feature2.Title == feature.Title &&
                                                                                feature2.Product == feature.Product &&
                                                                                feature2.Hash != feature.Hash &&
                                                                                comparer.Compare(feature2.Versions.OrderByDescending(v => v, comparer).First(),
                                                                                                 feature.Versions.OrderByDescending(v => v, comparer).First()) > 0)
                                                              );

                return(filteredResultsQuery.Select(feature => feature.CreateFeatureMatch(query)).ToList());
            }
        }
コード例 #2
0
        public void FindVersion_WithFirstNonTaggedCommit()
        {
            using (var context = new TestVesionContext())
            {
                context.WriteTextAndCommit("test.txt", "dummy", "init commit");

                var finder   = new VersionFinder();
                var version  = finder.FindVersion(context);
                var expected = SemanticVersion.Parse("0.1.0");
                var comparer = new SemanticVersionComparer(SemanticVersionComparation.MajorMinorPatch);

                Assert.That(version, Is.EqualTo(expected).Using(comparer));
            }
        }
コード例 #3
0
        public PreReleaseTag CalculateTag(IVersionContext context, SemanticVersion semVersion, string branchNameOverride)
        {
            var comparer = new SemanticVersionComparer(SemanticVersionComparation.MajorMinorPatch);
            var tagToUse = GetBranchSpecificTag(context.Configuration, context.CurrentBranch.Name, branchNameOverride);

            var lastTag = context.RepositoryMetadataProvider
                          .GetVersionTagsOnBranch(context.CurrentBranch, context.Configuration.TagPrefix)
                          .FirstOrDefault(v => v.PreReleaseTag.Name == tagToUse);

            var baseVersionNotChanged = lastTag != null &&
                                        !lastTag.PreReleaseTag.IsNull() &&
                                        comparer.Equals(lastTag, semVersion);

            if (baseVersionNotChanged)
            {
                return(new PreReleaseTag(tagToUse, lastTag.PreReleaseTag.Number + 1));
            }

            return(new PreReleaseTag(tagToUse, 1));
        }
コード例 #4
0
        /// <summary>
        /// Gets groups containing the descriptions for all features for the specified product.
        /// </summary>
        /// <param name="productName">The name of the product for which the feature descriptions should be retrieved.</param>
        /// <returns>An enumerable collection of <see cref="Entities.Group"/> instances.</returns>
        public async Task <IEnumerable <Group> > GetGroupedFeatureDescriptionsAsync(string productName)
        {
            Dictionary <string, List <FeatureDescription> > featureDescriptions = new Dictionary <string, List <FeatureDescription> >();
            Dictionary <string, Group> groups = new Dictionary <string, Group>();

            using (var session = _storeProvider.Store.OpenAsyncSession())
            {
                var data = await session.Query <DbFeature, Features_ByTitleProductAndGroup>()
                           .Where(feature => feature.Product.Equals(productName, StringComparison.OrdinalIgnoreCase))
                           .Select(feature =>
                                   new
                {
                    feature.Group,
                    feature.ParentTitle,
                    feature.Title,
                    feature.Versions
                })
                           .Take(1000)
                           .ToListAsync();

                var comparer = new SemanticVersionComparer();
                foreach (var uniqueFeature in data.GroupBy(record => (group: record.Group, title: record.Title)))
                {
                    var latestFeature      = uniqueFeature.OrderByDescending(record => record.Versions.OrderByDescending(v => v, comparer).First(), comparer).First();
                    var featureDescription = new FeatureDescription()
                    {
                        Title         = uniqueFeature.Key.title,
                        LatestVersion = latestFeature.Versions.OrderByDescending(v => v, comparer).First(),
                    };

                    if (String.IsNullOrWhiteSpace(latestFeature.ParentTitle))
                    {
                        if (!groups.ContainsKey(latestFeature.Group))
                        {
                            // Create a new group
                            groups.Add(latestFeature.Group, new Group()
                            {
                                Name     = latestFeature.Group,
                                Features = new List <FeatureDescription>()
                            });
                        }

                        // Add the feature to the group
                        ((List <FeatureDescription>)groups[latestFeature.Group].Features).Add(featureDescription);
                    }
                    else
                    {
                        if (!featureDescriptions.ContainsKey(latestFeature.ParentTitle))
                        {
                            featureDescriptions.Add(latestFeature.ParentTitle, new List <FeatureDescription>());
                        }

                        featureDescriptions[latestFeature.ParentTitle].Add(featureDescription);
                    }
                }

                // Map the lower levels
                foreach (var feature in groups.Values.SelectMany(group => group.Features))
                {
                    AddChildren(feature, featureDescriptions);
                }
            }

            return(groups.Values.OrderBy(group => group.Name).ToList());
        }