Exemple #1
0
        /// <summary>
        /// Stage, Commit, and Push
        /// </summary>
        public void StageCommitPush(Models.GetRepository getRepository, string message)
        {
            var path = Path.Combine(BaseDirectory, getRepository.Name);

            using (var repository = new Repository(path))
            {
                if (!repository.RetrieveStatus().IsDirty)
                {
                    return;
                }

                Commands.Stage(repository, "*");

                // Create the committer's signature and commit
                Signature author    = new Signature(Username, Email, DateTime.Now);
                Signature committer = author;

                // Commit to the repository
                Commit commit = repository.Commit(message, author, committer);

                var remote = repository.Network.Remotes["origin"];
                if (!remote.Url.Equals(getRepository.RemoteUrl, StringComparison.OrdinalIgnoreCase))
                {
                    repository.Network.Remotes.Update("origin", r => r.Url = getRepository.RemoteUrl);
                    remote = repository.Network.Remotes["origin"];
                }
                var options = new PushOptions
                {
                    CredentialsProvider = new LibGit2Sharp.Handlers.CredentialsHandler(
                        (url, usernameFromUrl, types) =>
                        new UsernamePasswordCredentials()
                    {
                        Username = "******",
                        Password = PersonalAccessToken
                    })
                };
                var pushRefSpec = @"refs/heads/master";
                repository.Network.Push(remote, pushRefSpec, options);
            }
        }
Exemple #2
0
        public bool FolderChanged(Models.GetRepository getRepository, string folder)
        {
            var path = Path.Combine(BaseDirectory, getRepository.Name);

            using (var repository = new Repository(path))
            {
                var status = repository.RetrieveStatus(new StatusOptions
                {
                    PathSpec = new string[] { folder }
                });

                foreach (var statusEntry in status)
                {
                    if (statusEntry.State != FileStatus.Ignored)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Pull
        /// </summary>
        public void Pull(Models.GetRepository getRepository)
        {
            var path = Path.Combine(BaseDirectory, getRepository.Name);

            using (var repository = new Repository(path))
            {
                var masterBranch = repository.Branches["master"];
                if (masterBranch == null)
                {
                    // nothing to pull
                    return;
                }

                if (repository.RetrieveStatus().IsDirty)
                {
                    Commands.Checkout(repository, masterBranch, new CheckoutOptions()
                    {
                        CheckoutModifiers = CheckoutModifiers.Force
                    });
                }

                Commands.Pull(repository,
                              new Signature(Username, Email, DateTime.Now),
                              new PullOptions()
                {
                    FetchOptions = new FetchOptions()
                    {
                        CredentialsProvider = new LibGit2Sharp.Handlers.CredentialsHandler(
                            (url, usernameFromUrl, types) =>
                            new UsernamePasswordCredentials()
                        {
                            Username = "******",
                            Password = PersonalAccessToken
                        })
                    }
                }
                              );
            }
        }
Exemple #4
0
        /// <summary>
        /// Ensure Repository is Intitialised
        /// </summary>
        public async Task <Models.GetRepository> EnsureRepoistoryIsInitialised(string name, string directory, Models.GetRepository repo, VisualStudioTeamServices vsts)
        {
            if (repo == null)
            {
                repo = await vsts.CreateRepository(name);
            }

            // Create repo folder
            FileHelper.CreateFolder(directory);

            // Check if local repo has been initalised
            if (!Repository.IsValid(directory))
            {
                // if not intialised then also check if directory is empty if not clear it
                if (!FileHelper.IsDirectoryEmpty(directory))
                {
                    Directory.Delete(directory, true);
                    FileHelper.CreateFolder(directory);
                }

                // clone remote repo
                var cloneOptions = new CloneOptions
                {
                    CredentialsProvider =
                        (_url, _user, _cred) => new UsernamePasswordCredentials
                    {
                        Username = "******",
                        Password = PersonalAccessToken
                    }
                };
                Repository.Clone(repo.RemoteUrl, directory, cloneOptions);
            }
            else
            {
                Pull(repo);
            }

            return(repo);
        }
        /// <summary>
        /// Run Master Builder
        /// </summary>
        public async Task <string> RunAsync(Request.Project project)
        {
            if (project == null)
            {
                return("null project");
            }

            // Validate & Pre Process Project
            if (!project.ValidateAndResolve(out string messages))
            {
                return(messages);
            }

            var topProjectDirectory = FileHelper.CreateFolder(builderSettings.OutputDirectory, project.InternalName);

            SourceControl.Git git = null;
            SourceControl.Models.GetRepository repository = null;
            Dictionary <string, SourceControl.Models.GetRepository> repos = null;

            if (builderSettings.GitPushOn || builderSettings.GitPullOn)
            {
                git = new SourceControl.Git(topProjectDirectory, project, builderSettings.GitUserName, builderSettings.GitEmail, builderSettings.VstsPersonalAccessToken);
            }

            if (builderSettings.GitPullOn)
            {
                repos = await git.SetupAndGetRepos();

                repository = repos[project.InternalName];
            }

            // Create Solution Directory
            var solutionDirectory = FileHelper.CreateFolder(topProjectDirectory, project.InternalName);

            var solutionWriter = new Helpers.SolutionWriter(solutionDirectory, project.CleanDirectoryIgnoreDirectories);

            // Solution
            var solution = new SolutionBuilder();
            var errors   = await solution.RunAsync(builderSettings, project, solutionWriter, solutionDirectory);

            if (!string.IsNullOrEmpty(errors))
            {
                return(errors);
            }

            // React
            var react = new Templates.React.ProjectBuilder();

            errors = await react.RunAsync(builderSettings, project, solutionWriter, solutionDirectory);

            if (!string.IsNullOrEmpty(errors))
            {
                return(errors);
            }

            // Shared
            var shared = new Templates.Shared.ProjectBuilder();

            errors = await shared.RunAsync(builderSettings, project, solutionWriter, solutionDirectory, git, repository);

            if (!string.IsNullOrEmpty(errors))
            {
                return(errors);
            }

            // Api
            var api = new Templates.Api.ProjectBuilder();

            errors = await api.RunAsync(builderSettings, project, solutionWriter, solutionDirectory, git, repository);

            if (!string.IsNullOrEmpty(errors))
            {
                return(errors);
            }

            // Data Access Layer
            var dal = new Templates.DataAccessLayer.ProjectBuilder();

            errors = await dal.RunAsync(builderSettings, project, solutionWriter, solutionDirectory, git, repository);

            if (!string.IsNullOrEmpty(errors))
            {
                return(errors);
            }

            // Api.Custom, only created once, not updated
            var apiCustom = new Templates.Api.Custom.ProjectBuilder();

            errors = await apiCustom.RunAsync(builderSettings, project, solutionWriter, solutionDirectory, git, repository);

            if (!string.IsNullOrEmpty(errors))
            {
                return(errors);
            }

            if (builderSettings.GitPushOn)
            {
                var rtf = new SourceControl.RequestToFileSystem(topProjectDirectory, project);
                await rtf.Write();

                git.StageCommitPush(repos["Json"], "Build");
                git.StageCommitPush(repository, "Build");
            }
            return("Success");
        }