Exemple #1
0
        public static INotNullEnumerable <String> GetHeadCommitsFromRepository(LibGit2Sharp.IRepository repository)
        {
            Contract.Ensures(Contract.Result <INotNullEnumerable <String> >() != null);

            if (repository == null)
            {
                return(EmptyEnumerable <String> .Instance);
            }

            var head = repository.Head;

            if (head == null)
            {
                return(EmptyEnumerable <String> .Instance);
            }

            var commits = head.Commits;

            if (commits == null)
            {
                return(EmptyEnumerable <String> .Instance);
            }

            return(commits
                   .NotNull()
                   .Select(commit => commit.Sha));
        }
Exemple #2
0
    static IRepositoryFacade CreateRepositoryFacade(string path, IRepository repo)
    {
        var repositoryFacade = Substitute.For <IRepositoryFacade>();

        repositoryFacade.Discover(path).Returns(path);
        repositoryFacade.NewRepository(path).Returns(repo);
        return(repositoryFacade);
    }
Exemple #3
0
        /// <summary>
        /// Using the repo and the repoConfiguration determine whether
        /// the schedule permits an optimization at this time.
        /// </summary>
        /// <param name="repoConfiguration">The configuration for the repository.</param>
        /// <param name="repo">The repository.</param>
        /// <returns>True when the images can be optimized.</returns>
        public static bool ShouldOptimizeImages(RepoConfiguration repoConfiguration, LibGit2Sharp.IRepository repo)
        {
            if (string.IsNullOrEmpty(repoConfiguration.Schedule))
            {
                // no schedule specified - let's optimize those images
                return(true);
            }

            // determine backofftime from keywords
            TimeSpan backofftime;

            switch (repoConfiguration.Schedule)
            {
            case KnownScheduleSettings.Daily:
                backofftime = TimeSpan.FromDays(1);
                break;

            case KnownScheduleSettings.Weekly:
                backofftime = TimeSpan.FromDays(7);
                break;

            case KnownScheduleSettings.Monthly:
                backofftime = TimeSpan.FromDays(30);
                break;

            default:
                backofftime = TimeSpan.Zero;
                break;
            }

            // find the last time imgbot committed here
            var imgbotCommit = repo.Commits.FirstOrDefault(x => x.Author.Email == KnownGitHubs.ImgBotEmail);

            if (imgbotCommit == null)
            {
                // no imgbot commit in history - let's optimize those images
                return(true);
            }

            if (DateTimeOffset.Now - imgbotCommit.Author.When > backofftime)
            {
                // Now minus the last imgbot commit is greater than the backoff time - let's optimize those images
                return(true);
            }

            return(false);
        }
Exemple #4
0
        public static ILookup <String, Tag> GetTagsFromRepository(LibGit2Sharp.IRepository repository)
        {
            Contract.Ensures(Contract.Result <ILookup <String, Tag> >() != null);

            if (repository == null)
            {
                return(Enumerable.Empty <Tag>().ToLookup(tag => tag.Sha));
            }
            if (repository.Tags == null)
            {
                return(Enumerable.Empty <Tag>().ToLookup(tag => tag.Sha));
            }

            return(repository.Tags
                   .Where(tag => tag != null)
                   .Where(tag => tag.Name != null)
                   .Where(tag => tag.Target != null)
                   .Where(tag => tag.Target.Sha != null)
                   .Select(tag => new Tag(tag.Name, tag.Target.Sha))
                   .ToLookup(tag => tag.Sha));
        }
Exemple #5
0
        public static String GenerateFileContents(VersionConfiguration configuration, LibGit2Sharp.IRepository repository)
        {
            Contract.Requires(configuration != null);
            Contract.Ensures(Contract.Result <String>() != null);

            var commits  = GetHeadCommitsFromRepository(repository);
            var tags     = GetTagsFromRepository(repository);
            var versions = VersionFinder.GetVersions(commits, tags);
            var versionConfigurationApplicator = new VersionConfigurationApplicator(versions, configuration);

            return(VersionFileGenerator.GenerateFileContents(versionConfigurationApplicator.Version, versionConfigurationApplicator.FileVersion, versionConfigurationApplicator.InfoVersion));
        }