示例#1
0
        async Task <string> ExtractToTempFile(
            IRepository repo,
            int pullRequestNumber,
            string commitSha,
            string fileName,
            Encoding encoding)
        {
            string contents;

            try
            {
                contents = await gitClient.ExtractFile(repo, commitSha, fileName) ?? string.Empty;
            }
            catch (FileNotFoundException)
            {
                var pullHeadRef = $"refs/pull/{pullRequestNumber}/head";
                var remote      = await gitClient.GetHttpRemote(repo, "origin");

                await gitClient.Fetch(repo, remote.Name, commitSha, pullHeadRef);

                contents = await gitClient.ExtractFile(repo, commitSha, fileName) ?? string.Empty;
            }

            return(CreateTempFile(fileName, commitSha, contents, encoding));
        }
        async Task ExtractToTempFile(
            IRepository repo,
            int pullRequestNumber,
            string commitSha,
            string relativePath,
            Encoding encoding,
            string tempFilePath)
        {
            string contents;

            try
            {
                contents = await gitClient.ExtractFile(repo, commitSha, relativePath) ?? string.Empty;
            }
            catch (FileNotFoundException)
            {
                var pullHeadRef = $"refs/pull/{pullRequestNumber}/head";
                var remote      = await gitClient.GetHttpRemote(repo, "origin");

                await gitClient.Fetch(repo, remote.Name, commitSha, pullHeadRef);

                contents = await gitClient.ExtractFile(repo, commitSha, relativePath) ?? string.Empty;
            }

            Directory.CreateDirectory(Path.GetDirectoryName(tempFilePath));
            File.WriteAllText(tempFilePath, contents, encoding);
        }
        public IObservable <Tuple <string, string> > ExtractDiffFiles(
            ILocalRepositoryModel repository,
            IModelService modelService,
            IPullRequestModel pullRequest,
            string fileName,
            string fileSha)
        {
            return(Observable.Defer(async() =>
            {
                var repo = gitService.GetRepository(repository.LocalPath);
                var remote = await gitClient.GetHttpRemote(repo, "origin");
                await gitClient.Fetch(repo, remote.Name);

                // The left file is the target of the PR so this should already be fetched.
                var left = await gitClient.ExtractFile(repo, pullRequest.Base.Sha, fileName);

                // The right file - if it comes from a fork - may not be fetched so fall back to
                // getting the file contents from the model service.
                var right = await GetFileFromRepositoryOrApi(repository, repo, modelService, pullRequest.Head.Sha, fileName, fileSha);

                if (left == null)
                {
                    throw new FileNotFoundException($"Could not retrieve {fileName}@{pullRequest.Base.Sha}");
                }

                if (right == null)
                {
                    throw new FileNotFoundException($"Could not retrieve {fileName}@{pullRequest.Head.Sha}");
                }

                return Observable.Return(Tuple.Create(left, right));
            }));
        }
 public IObservable <string> ExtractFile(ILocalRepositoryModel repository, string commitSha, string fileName)
 {
     return(Observable.Defer(async() =>
     {
         var repo = gitService.GetRepository(repository.LocalPath);
         await gitClient.Fetch(repo, "origin");
         var result = await gitClient.ExtractFile(repo, commitSha, fileName);
         return Observable.Return(result);
     }));
 }
        async Task <string> ExtractToTempFile(IRepository repo, string commitSha, string fileName, Encoding encoding)
        {
            var contents = await gitClient.ExtractFile(repo, commitSha, fileName) ?? string.Empty;

            return(CreateTempFile(fileName, commitSha, contents, encoding));
        }