/// <inheritdoc />
        public Altinn.Studio.Designer.Models.Commit GetInitialCommit(string org, string repository)
        {
            List <Altinn.Studio.Designer.Models.Commit> commits = new List <Altinn.Studio.Designer.Models.Commit>();
            string localServiceRepoFolder = _settings.GetServicePath(org, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            using (var repo = new LibGit2Sharp.Repository(localServiceRepoFolder))
            {
                LibGit2Sharp.Commit    firstCommit = repo.Commits.Last();
                Designer.Models.Commit commit      = new Designer.Models.Commit();
                commit.Message      = firstCommit.Message;
                commit.MessageShort = firstCommit.MessageShort;
                commit.Encoding     = firstCommit.Encoding;
                commit.Sha          = firstCommit.Sha;

                commit.Author       = new Designer.Models.Signature();
                commit.Author.Email = firstCommit.Author.Email;
                commit.Author.Name  = firstCommit.Author.Name;
                commit.Author.When  = firstCommit.Author.When;

                commit.Comitter       = new Designer.Models.Signature();
                commit.Comitter.Name  = firstCommit.Committer.Name;
                commit.Comitter.Email = firstCommit.Committer.Email;
                commit.Comitter.When  = firstCommit.Committer.When;

                return(commit);
            }
        }
Example #2
0
        /// <inheritdoc />
        public Designer.Models.Commit GetInitialCommit(string org, string repository)
        {
            string localServiceRepoFolder = _settings.GetServicePath(org, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            Designer.Models.Commit commit = null;

            using var repo = new LibGit2Sharp.Repository(localServiceRepoFolder);
            if (repo.Commits.Any() && repo.Commits.Last() != null)
            {
                LibGit2Sharp.Commit firstCommit = repo.Commits.Last();
                commit              = new Designer.Models.Commit();
                commit.Message      = firstCommit.Message;
                commit.MessageShort = firstCommit.MessageShort;
                commit.Encoding     = firstCommit.Encoding;
                commit.Sha          = firstCommit.Sha;

                commit.Author       = new Designer.Models.Signature();
                commit.Author.Email = firstCommit.Author.Email;
                commit.Author.Name  = firstCommit.Author.Name;
                commit.Author.When  = firstCommit.Author.When;

                commit.Comitter       = new Designer.Models.Signature();
                commit.Comitter.Name  = firstCommit.Committer.Name;
                commit.Comitter.Email = firstCommit.Committer.Email;
                commit.Comitter.When  = firstCommit.Committer.When;
            }
            else
            {
                _logger.LogWarning($" // SourceControlSI // GetInitialCommit // Did not find any commits in repo {localServiceRepoFolder}");
            }

            return(commit);
        }
        /// <summary>
        /// List commits
        /// </summary>
        /// <param name="org">Unique identifier of the organisation responsible for the app.</param>
        /// <param name="repository">The name of the repository</param>
        /// <returns>List of commits</returns>
        public List <Altinn.Studio.Designer.Models.Commit> Log(string org, string repository)
        {
            List <Altinn.Studio.Designer.Models.Commit> commits = new List <Designer.Models.Commit>();
            string localServiceRepoFolder = _settings.GetServicePath(org, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            using (var repo = new LibGit2Sharp.Repository(localServiceRepoFolder))
            {
                foreach (LibGit2Sharp.Commit c in repo.Commits.Take(50))
                {
                    Designer.Models.Commit commit = new Designer.Models.Commit();
                    commit.Message      = c.Message;
                    commit.MessageShort = c.MessageShort;
                    commit.Encoding     = c.Encoding;
                    commit.Sha          = c.Sha;

                    commit.Author       = new Designer.Models.Signature();
                    commit.Author.Email = c.Author.Email;
                    commit.Author.Name  = c.Author.Name;
                    commit.Author.When  = c.Author.When;

                    commit.Comitter       = new Designer.Models.Signature();
                    commit.Comitter.Name  = c.Committer.Name;
                    commit.Comitter.Email = c.Committer.Email;
                    commit.Comitter.When  = c.Committer.When;

                    commits.Add(commit);
                }
            }

            return(commits);
        }
        /// <summary>
        /// List commits
        /// </summary>
        /// <param name="org">Unique identifier of the organisation responsible for the app.</param>
        /// <param name="repository">The name of the repository</param>
        /// <returns>List of commits</returns>
        public List <Altinn.Studio.Designer.Models.Commit> Log(string org, string repository)
        {
            List <Altinn.Studio.Designer.Models.Commit> commits = new List <Designer.Models.Commit>();
            string localServiceRepoFolder = _settings.GetServicePath(org, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));
            var    watch = System.Diagnostics.Stopwatch.StartNew();

            using (var repo = new LibGit2Sharp.Repository(localServiceRepoFolder))
            {
                foreach (LibGit2Sharp.Commit c in repo.Commits.Take(50))
                {
                    Designer.Models.Commit commit = new Designer.Models.Commit();
                    commit.Message      = c.Message;
                    commit.MessageShort = c.MessageShort;
                    commit.Encoding     = c.Encoding;
                    commit.Sha          = c.Sha;

                    commit.Author       = new Designer.Models.Signature();
                    commit.Author.Email = c.Author.Email;
                    commit.Author.Name  = c.Author.Name;
                    commit.Author.When  = c.Author.When;

                    commit.Comitter       = new Designer.Models.Signature();
                    commit.Comitter.Name  = c.Committer.Name;
                    commit.Comitter.Email = c.Committer.Email;
                    commit.Comitter.When  = c.Committer.When;

                    commits.Add(commit);
                }
            }

            watch.Stop();
            _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "Get commits - {0} ", watch.ElapsedMilliseconds);

            return(commits);
        }