Immutable object that can be obtained by calling RepositoryInfo.LoadFromPath(string, RepositoryInfoOptions) that describes the commit and all the CSemVer information.
Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="SimpleRepositoryInfo"/> based on a path (that can be below the folder with the '.git' sub folder).
        /// </summary>
        /// <param name="path">The path to lookup.</param>
        /// <param name="logger">Logger that will be used.</param>
        /// <param name="optionsChecker">
        /// Optional action that accepts the logger, a boolean that is true if a RepositoryInfo.xml has been
        /// found, and the <see cref="RepositoryInfoOptions"/> that will be used.
        /// </param>
        /// <returns>An immutable SimpleRepositoryInfo instance.</returns>
        static public SimpleRepositoryInfo LoadFromPath(ILogger logger, string path, Action <ILogger, bool, RepositoryInfoOptions> optionsChecker = null)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            RepositoryInfo info = RepositoryInfo.LoadFromPath(path, gitPath =>
            {
                string optionFile = Path.Combine(gitPath, "RepositoryInfo.xml");
                bool fileExists   = File.Exists(optionFile);
                var options       = fileExists ? RepositoryInfoOptions.Read(optionFile) : new RepositoryInfoOptions();
                optionsChecker?.Invoke(logger, fileExists, options);
                return(options);
            });

            return(new SimpleRepositoryInfo(logger, info));
        }
Esempio n. 2
0
 void LogValidVersions(ILogger logger, RepositoryInfo info)
 {
     if (info.PossibleVersions.Count == 0)
     {
         logger.Info("No possible versions.");
     }
     else
     {
         if (info.Options.PossibleVersionsMode == PossibleVersionsMode.Restricted)
         {
             logger.Info("Possible version(s) (Restricted): {0}", string.Join(", ", info.PossibleVersionsStrict));
         }
         else
         {
             logger.Info("Possible version(s) (AllSuccessors): {0}", string.Join(", ", info.PossibleVersions));
         }
     }
 }
Esempio n. 3
0
 public RepositoryInfo GetRepositoryInfo(string commitSha, TagsOverride tags = null)
 {
     return(RepositoryInfo.LoadFromPath(Path, new RepositoryInfoOptions {
         StartingCommitSha = commitSha, OverriddenTags = tags != null ? tags.Overrides : null
     }));
 }
Esempio n. 4
0
 public RepositoryInfo GetRepositoryInfo(RepositoryInfoOptions options = null)
 {
     return(RepositoryInfo.LoadFromPath(Path, options));
 }
 void LogValidVersions( ILogger logger, RepositoryInfo info )
 {
     if( info.PossibleVersions.Count == 0 )
     {
         logger.Info( "No possible versions." );
     }
     else
     {
         if( info.Options.PossibleVersionsMode == PossibleVersionsMode.Restricted )
         {
             logger.Info( "Possible version(s) (Restricted): {0}", string.Join( ", ", info.PossibleVersionsStrict ) );
         }
         else
         {
             logger.Info( "Possible version(s) (AllSuccessors): {0}", string.Join( ", ", info.PossibleVersions ) );
         }
     }
 }
 bool HandleRepositoryInfoError( ILogger logger, RepositoryInfo info )
 {
     if( !info.HasError ) return false;
     string allText = info.RepositoryError ?? info.ReleaseTagErrorText;
     string oneLine = info.ErrorHeaderText;
     logger.Error( allText );
     SetInvalidValues( oneLine );
     return true;
 }
        /// <summary>
        /// Initializes a new <see cref="SimpleRepositoryInfo"/> based on a (more complex) <see cref="Info"/>.
        /// </summary>
        /// <param name="logger">Logger that will be used.</param>
        /// <param name="info">The simplified repository information.</param>
        public SimpleRepositoryInfo( ILogger logger, RepositoryInfo info )
        {
            if( logger == null ) throw new ArgumentNullException( nameof(logger) );
            if( info == null ) throw new ArgumentNullException( nameof( info ) );

            Info = info;
            if( !HandleRepositoryInfoError( logger, info ) )
            {
                CommitSha = info.CommitSha;
                CommitDateUtc = info.CommitDateUtc;
                var t = info.ValidReleaseTag;
                // Always warn on non standard pre release name.
                if( t != null && t.IsPreRelease && !t.IsPreReleaseNameStandard )
                {
                    logger.Warn( "Non standard pre release name '{0}' is mapped to '{1}'.", t.PreReleaseNameFromTag, t.PreReleaseName );
                }
                if( info.IsDirty && !info.Options.IgnoreDirtyWorkingFolder )
                {
                    SetInvalidValuesAndLog( logger, "Working folder has non committed changes.", false );
                    logger.Info( info.IsDirtyExplanations );
                }
                else
                {
                    Debug.Assert( info.PossibleVersions != null );
                    if( info.IsDirty )
                    {
                        logger.Warn( "Working folder is Dirty! Checking this has been disabled since RepositoryInfoOptions.IgnoreDirtyWorkingFolder is true." );
                        logger.Warn( info.IsDirtyExplanations );
                    }
                    if( info.PreviousRelease != null )
                    {
                        logger.Trace( "Previous release found '{0}' on commit '{1}'.", info.PreviousRelease.ThisTag, info.PreviousRelease.CommitSha );
                    }
                    if( info.PreviousMaxRelease != null && info.PreviousMaxRelease != info.PreviousRelease )
                    {
                        logger.Trace( "Previous max release found '{0}' on commit '{1}'.", info.PreviousMaxRelease.ThisTag, info.PreviousMaxRelease.CommitSha );
                    }
                    if( info.PreviousRelease == null && info.PreviousMaxRelease == null )
                    {
                        logger.Trace( "No previous release found'." );
                    }

                    if( info.CIRelease != null )
                    {
                        IsValidCIBuild = true;
                        SetNumericalVersionValues( info.CIRelease.BaseTag, true );
                        NuGetVersion = info.CIRelease.BuildVersionNuGet;
                        SemVer = info.CIRelease.BuildVersion;
                        logger.Info( "CI release: '{0}'.", SemVer );
                        LogValidVersions( logger, info );
                    }
                    else
                    {
                        if( t == null )
                        {
                            SetInvalidValuesAndLog( logger, "No valid release tag.", false );
                            LogValidVersions( logger, info );
                        }
                        else
                        {
                            IsValidRelease = true;
                            OriginalTagText = t.OriginalTagText;
                            SetNumericalVersionValues( t, false );
                            NuGetVersion = t.ToString( ReleaseTagFormat.NuGetPackage );
                            SemVer = t.ToString( ReleaseTagFormat.SemVerWithMarker );
                            logger.Info( "Release: '{0}'.", SemVer );
                        }
                    }
                }
            }
            MajorMinor = string.Format( "{0}.{1}", Major, Minor );
            MajorMinorPatch = string.Format( "{0}.{1}", MajorMinor, Patch );
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new <see cref="SimpleRepositoryInfo"/> based on a (more complex) <see cref="Info"/>.
        /// </summary>
        /// <param name="logger">Logger that will be used.</param>
        /// <param name="info">The simplified repository information.</param>
        public SimpleRepositoryInfo(ILogger logger, RepositoryInfo info)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            Info = info;
            if (!HandleRepositoryInfoError(logger, info))
            {
                CommitSha     = info.CommitSha;
                CommitDateUtc = info.CommitDateUtc;
                var t = info.ValidReleaseTag;
                if (info.IsDirty && !info.Options.IgnoreDirtyWorkingFolder)
                {
                    SetInvalidValuesAndLog(logger, "Working folder has non committed changes.", false);
                    logger.Info(info.IsDirtyExplanations);
                }
                else
                {
                    Debug.Assert(info.PossibleVersions != null);
                    if (info.IsDirty)
                    {
                        logger.Warn("Working folder is Dirty! Checking this has been disabled since RepositoryInfoOptions.IgnoreDirtyWorkingFolder is true.");
                        logger.Warn(info.IsDirtyExplanations);
                    }
                    var basic = info.CommitInfo.BasicInfo;
                    if (basic == null)
                    {
                        logger.Trace($"No version information found.");
                    }
                    else
                    {
                        var tag = basic.UnfilteredThisCommit?.ThisTag;
                        logger.Trace(tag != null ? $"Tag: {tag}" : "No tag found on commit itself.");
                        var bestContent = info.BetterExistingVersion;
                        if (bestContent != null)
                        {
                            logger.Trace($"Better version found: {bestContent.ThisTag}, sha: {bestContent.CommitSha}");
                        }
                        var baseTag = basic.BestCommitBelow?.ThisTag;
                        logger.Trace(baseTag != null ? $"Base tag below: {baseTag}" : "No base tag found below.");
                    }

                    // Will be replaced by SetInvalidValuesAndLog if needed.
                    SafeNuGetVersion = info.FinalNuGetVersion.NormalizedTextWithBuildMetaData;
                    SafeSemVersion   = info.FinalSemVersion.NormalizedTextWithBuildMetaData;

                    if (info.CIRelease != null)
                    {
                        IsValidCIBuild = true;
                        if (!info.CIRelease.IsZeroTimed)
                        {
                            SetNumericalVersionValues(info.CIRelease.BaseTag, true);
                        }
                        else
                        {
                            Major = info.CIRelease.BuildVersion.Major;
                            Minor = info.CIRelease.BuildVersion.Minor;
                            Patch = info.CIRelease.BuildVersion.Patch;

                            PreReleaseName   = String.Empty;
                            PreReleaseNumber = 0;
                            PreReleaseFix    = 0;
                            FileVersion      = InformationalVersion.ZeroFileVersion;
                            OrderedVersion   = 0;
                        }
                        logger.Info($"CI release: '{SafeNuGetVersion}'.");
                        LogValidVersions(logger, info);
                    }
                    else
                    {
                        if (t == null)
                        {
                            SetInvalidValuesAndLog(logger, "No valid release tag found on the commit.", false);
                            LogValidVersions(logger, info);
                        }
                        else
                        {
                            IsValidRelease  = true;
                            OriginalTagText = t.ParsedText;
                            SetNumericalVersionValues(t, false);
                            logger.Info($"Release: '{SafeNuGetVersion}'.");
                        }
                    }
                }
            }
            MajorMinor      = $"{Major}.{Minor}";
            MajorMinorPatch = $"{MajorMinor}.{Patch}";
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new <see cref="SimpleRepositoryInfo"/> based on a (more complex) <see cref="Info"/>.
        /// </summary>
        /// <param name="logger">Logger that will be used.</param>
        /// <param name="info">The simplified repository information.</param>
        public SimpleRepositoryInfo(ILogger logger, RepositoryInfo info)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            Info = info;
            if (!HandleRepositoryInfoError(logger, info))
            {
                CommitSha     = info.CommitSha;
                CommitDateUtc = info.CommitDateUtc;
                var t = info.ValidReleaseTag;
                // Always warn on non standard pre release name.
                if (t != null && t.IsPreRelease && !t.IsPreReleaseNameStandard)
                {
                    logger.Warn("Non standard pre release name '{0}' is mapped to '{1}'.", t.PreReleaseNameFromTag, t.PreReleaseName);
                }
                if (info.IsDirty && !info.Options.IgnoreDirtyWorkingFolder)
                {
                    SetInvalidValuesAndLog(logger, "Working folder has non committed changes.", false);
                    logger.Info(info.IsDirtyExplanations);
                }
                else
                {
                    Debug.Assert(info.PossibleVersions != null);
                    if (info.IsDirty)
                    {
                        logger.Warn("Working folder is Dirty! Checking this has been disabled since RepositoryInfoOptions.IgnoreDirtyWorkingFolder is true.");
                        logger.Warn(info.IsDirtyExplanations);
                    }
                    if (info.PreviousRelease != null)
                    {
                        logger.Trace("Previous release found '{0}' on commit '{1}'.", info.PreviousRelease.ThisTag, info.PreviousRelease.CommitSha);
                    }
                    if (info.PreviousMaxRelease != null && info.PreviousMaxRelease != info.PreviousRelease)
                    {
                        logger.Trace("Previous max release found '{0}' on commit '{1}'.", info.PreviousMaxRelease.ThisTag, info.PreviousMaxRelease.CommitSha);
                    }
                    if (info.PreviousRelease == null && info.PreviousMaxRelease == null)
                    {
                        logger.Trace("No previous release found'.");
                    }

                    if (info.CIRelease != null)
                    {
                        IsValidCIBuild = true;
                        SetNumericalVersionValues(info.CIRelease.BaseTag, true);
                        NuGetVersion = info.CIRelease.BuildVersionNuGet;
                        SemVer       = info.CIRelease.BuildVersion;
                        logger.Info("CI release: '{0}'.", SemVer);
                        LogValidVersions(logger, info);
                    }
                    else
                    {
                        if (t == null)
                        {
                            SetInvalidValuesAndLog(logger, "No valid release tag.", false);
                            LogValidVersions(logger, info);
                        }
                        else
                        {
                            IsValidRelease  = true;
                            OriginalTagText = t.OriginalTagText;
                            SetNumericalVersionValues(t, false);
                            NuGetVersion = t.ToString(ReleaseTagFormat.NuGetPackage);
                            SemVer       = t.ToString(ReleaseTagFormat.SemVerWithMarker);
                            logger.Info("Release: '{0}'.", SemVer);
                        }
                    }
                }
            }
            MajorMinor      = string.Format("{0}.{1}", Major, Minor);
            MajorMinorPatch = string.Format("{0}.{1}", MajorMinor, Patch);
        }