/// <summary>
    /// Gets the <see cref="BranchConfig"/> for the current commit.
    /// </summary>
    public BranchConfig GetBranchConfiguration(IBranch targetBranch, ICommit?currentCommit, Config configuration, IList <IBranch>?excludedInheritBranches = null)
    {
        var matchingBranches = configuration.GetConfigForBranch(targetBranch.Name.WithoutRemote);

        if (matchingBranches == null)
        {
            this.log.Info($"No branch configuration found for branch {targetBranch}, falling back to default configuration");

            matchingBranches = BranchConfig.CreateDefaultBranchConfig(FallbackConfigName)
                               .Apply(new BranchConfig
            {
                Regex          = "",
                VersioningMode = configuration.VersioningMode,
                Increment      = configuration.Increment ?? IncrementStrategy.Inherit,
            });
        }

        if (matchingBranches.Increment == IncrementStrategy.Inherit)
        {
            matchingBranches = InheritBranchConfiguration(targetBranch, matchingBranches, currentCommit, configuration, excludedInheritBranches);
            if (matchingBranches.Name !.IsEquivalentTo(FallbackConfigName) && matchingBranches.Increment == IncrementStrategy.Inherit)
            {
                // We tried, and failed to inherit, just fall back to patch
                matchingBranches.Increment = IncrementStrategy.Patch;
            }
        }

        return(matchingBranches);
    }
Example #2
0
    private BranchConfig GetBranchConfigurationInternal(int recursions, IBranch targetBranch, ICommit?currentCommit, Config configuration, IList <IBranch>?excludedInheritBranches = null)
    {
        if (recursions >= MaxRecursions)
        {
            throw new InfiniteLoopProtectionException($"Inherited branch configuration caused {recursions} recursions. Aborting!");
        }

        var matchingBranches = configuration.GetConfigForBranch(targetBranch.Name.WithoutRemote);

        if (matchingBranches == null)
        {
            this.log.Info($"No branch configuration found for branch {targetBranch}, falling back to default configuration");

            matchingBranches = BranchConfig.CreateDefaultBranchConfig(FallbackConfigName)
                               .Apply(new BranchConfig
            {
                Regex          = "",
                VersioningMode = configuration.VersioningMode,
                Increment      = configuration.Increment ?? IncrementStrategy.Inherit
            });
        }

        if (matchingBranches.Increment == IncrementStrategy.Inherit)
        {
            matchingBranches = InheritBranchConfiguration(recursions, targetBranch, matchingBranches, currentCommit, configuration, excludedInheritBranches);
            if (matchingBranches.Name.IsEquivalentTo(FallbackConfigName) && matchingBranches.Increment == IncrementStrategy.Inherit)
            {
                // We tried, and failed to inherit, just fall back to patch
                matchingBranches.Increment = IncrementStrategy.Patch;
            }
        }

        return(matchingBranches);
    }