Exemplo n.º 1
0
 void StageCore(CommonRepository repository)
 {
     using (var repo = new Repository(repository.Path)) {
         Commands.Stage(repo, "*.png");
         Commands.Stage(repo, "*.xml");
     }
 }
Exemplo n.º 2
0
        void CommitCore(CommonRepository repository)
        {
            string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\').Last();

            using (var repo = new Repository(repository.Path)) {
                Signature author    = new Signature("DXVisualTestsBot", "*****@*****.**", DateTime.Now);
                Signature committer = author;
                Commit    commit    = repo.Commit($"Update tests ({userName})", author, committer);
            }
        }
Exemplo n.º 3
0
        bool CloneCore(CommonRepository repository)
        {
            var co = new CloneOptions();

            co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials {
                Username = "******", Password = "******"
            };
            co.BranchName = $"20{repository.Version}";
            var result = Repository.Clone("http://gitserver/XPF/VisualTests.git", repository.Path, co);

            return(Directory.Exists(result));
        }
Exemplo n.º 4
0
 public async Task <GitUpdateResult> Update(CommonRepository repository)
 {
     if (!repository.IsDownloaded())
     {
         return(await Task.FromResult(GitUpdateResult.Error));
     }
     FetchCore(repository);
     if (!PullCore(repository))
     {
         return(await Task.FromResult(GitUpdateResult.Error));
     }
     return(await Task.FromResult(GitUpdateResult.None));
 }
Exemplo n.º 5
0
 public async Task <GitCommitResult> Commit(CommonRepository repository)
 {
     if (!repository.IsDownloaded())
     {
         return(await Task.FromResult(GitCommitResult.Error));
     }
     StageCore(repository);
     CommitCore(repository);
     if (!(PushCore(repository)))
     {
         return(await Task.FromResult(GitCommitResult.Error));
     }
     return(await Task.FromResult(GitCommitResult.None));
 }
Exemplo n.º 6
0
 public async Task <bool> Clone(CommonRepository repository)
 {
     if (repository.IsDownloaded())
     {
         return(await Task.FromResult(true));
     }
     if (!Directory.Exists(repository.Path))
     {
         Directory.CreateDirectory(repository.Path);
     }
     if (!CloneCore(repository))
     {
         return(await Task.FromResult(false));
     }
     return(await Task.FromResult(repository.IsDownloaded()));
 }
Exemplo n.º 7
0
        bool PullCore(CommonRepository repository)
        {
            using (var repo = new Repository(repository.Path)) {
                LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
                options.FetchOptions = new FetchOptions();
                options.FetchOptions.CredentialsProvider = new CredentialsHandler(
                    (url, usernameFromUrl, types) =>
                    new UsernamePasswordCredentials()
                {
                    Username = "******",
                    Password = "******"
                });

                var signature = new LibGit2Sharp.Signature(new Identity("DXVisualTestsBot", "*****@*****.**"), DateTimeOffset.Now);
                return(Commands.Pull(repo, signature, options).Status != MergeStatus.Conflicts);
            }
        }
Exemplo n.º 8
0
 public bool SetHttpRepository(CommonRepository repository)
 {
     if (!repository.IsDownloaded())
     {
         return(false);
     }
     using (var repo = new Repository(repository.Path)) {
         foreach (Remote remote in repo.Network.Remotes.ToList())
         {
             if (!remote.PushUrl.StartsWith("http"))
             {
                 repo.Network.Remotes.Update(remote.Name, r => r.PushUrl = r.Url = "http://gitserver/XPF/VisualTests.git");
             }
         }
     }
     return(true);
 }
Exemplo n.º 9
0
        void FetchCore(CommonRepository repository)
        {
            string logMessage = "";

            using (var repo = new Repository(repository.Path)) {
                FetchOptions options = new FetchOptions();
                options.CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) =>
                                                                     new UsernamePasswordCredentials()
                {
                    Username = "******",
                    Password = "******"
                });
                foreach (Remote remote in repo.Network.Remotes)
                {
                    IEnumerable <string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                    Commands.Fetch(repo, remote.Name, refSpecs, options, logMessage);
                }
            }
        }
Exemplo n.º 10
0
 bool PushCore(CommonRepository repository)
 {
     using (var repo = new Repository(repository.Path)) {
         LibGit2Sharp.PushOptions options = new LibGit2Sharp.PushOptions();
         options.CredentialsProvider = new CredentialsHandler(
             (url, usernameFromUrl, types) =>
             new UsernamePasswordCredentials()
         {
             Username = "******",
             Password = "******"
         });
         var branch = repo.Branches.FirstOrDefault(b => b.FriendlyName == $"20{repository.Version}");
         if (branch == null)
         {
             return(false);
         }
         repo.Network.Push(branch, options);
         return(true);
     }
 }