Exemple #1
0
        public Snapshot GetRepositorySnapshot(string gitHubUrl, string repoName, string snapshotId, string requestId)
        {
            Directory.CreateDirectory($"../Repos/{requestId}");
            string repoPath = $"../Repos/{requestId}/{repoName}";
            string barePath = $"../Repos/{requestId}/.git";

            try
            {
                CloneGitRepo(gitHubUrl, barePath);

                Repository bareRepo = new Repository(barePath);
                string     md5      = "";
                byte[]     repoBytes;

                if (snapshotId == "none")
                {
                    md5       = CreateRepoChecksum(bareRepo);
                    repoBytes = compressionService.ZipBytes(barePath, repoName, $"../Repos/{requestId}");

                    bareRepo.Dispose();

                    DirectoryHelper.SetAttributesNormal(new DirectoryInfo(barePath));
                }
                else
                {
                    Commit commit = bareRepo.Commits.Where(x => x.Sha == snapshotId).First();

                    Repository.Clone(barePath, repoPath);
                    Repository repo = new Repository(repoPath);

                    CheckoutGitSnapshot(repo, commit);
                    md5 = CreateSnapshotChecksum(commit);

                    bareRepo.Dispose();
                    repo.Dispose();

                    DirectoryHelper.SetAttributesNormal(new DirectoryInfo(repoPath));
                    Directory.Delete($"{repoPath}/.git", true);

                    repoBytes = compressionService.ZipBytes(repoPath, repoName, $"../Repos/{requestId}");
                }

                DeleteRequestDirectory(requestId);

                return(new Snapshot()
                {
                    checksum = md5,
                    zippedBytes = repoBytes
                });
            }
            catch (Exception e)
            {
                DeleteRequestDirectory(requestId);

                throw e;
            }
        }
        public Snapshot GetRepositorySnapshot(string svnUrl, string repoName, string snapshotId, string requestId)
        {
            Directory.CreateDirectory($"../Repos/{requestId}");
            repoName = repoName.Replace(' ', '_');
            string repoPath     = $"../Repos/{requestId}/{repoName}";
            string revisionPath = $"../Repos/{requestId}/revision";

            try
            {
                string dumpPath = $"../Repos/{requestId}/{repoName}.svndump";

                // Dump external SVN repo
                ShellHelper.Bash("svnrdump.exe", $"dump {svnUrl} -F {dumpPath}");
                // Create new empty local SVN repo
                ShellHelper.Bash("svnadmin.exe", $"create {repoPath}");
                // Load external dump to local repo
                ShellHelper.Bash("svnadmin.exe", $"load {repoPath} -F {dumpPath}");

                string md5       = "";
                byte[] repoBytes = new byte[0];

                if (snapshotId == "none")
                {
                    md5       = CreateRepositoryChecksum(dumpPath);
                    repoBytes = compressionService.ZipBytes(repoPath, repoName, $"../Repos/{requestId}");
                }
                else
                {
                    // Checkout SVN revision
                    ShellHelper.Bash("svn.exe", $"checkout {svnUrl} {revisionPath}");

                    DirectoryHelper.SetAttributesNormal(new DirectoryInfo(revisionPath));
                    Directory.Delete($"{revisionPath}/.svn", true);

                    md5       = CreateSnapshotChecksum(repoPath, int.Parse(snapshotId));
                    repoBytes = compressionService.ZipBytes(revisionPath, repoName, $"../Repos/{requestId}");
                }


                File.Delete(dumpPath);
                DeleteRequestDirectory(requestId);

                return(new Snapshot()
                {
                    checksum = md5,
                    zippedBytes = repoBytes
                });
            }
            catch (Exception e)
            {
                DeleteRequestDirectory(requestId);

                throw e;
            }
        }