Exemple #1
0
        public async Task <Tuple <string, string> > FetchDiffContent(ICommitFile diffFile,
                                                                     string headCommit, string baseCommit)
        {
            var    headFileName  = BuildHeadFileName(headCommit, diffFile.Filename);
            var    headPath      = "";
            string contentOfHead = null;

            if (diffFile.Status == FileStatus.Removed)
            {
                headPath = await SaveToFile(headFileName, "");
            }
            else if (!_fileContentPersist.ExistsInCached(_pullRequestLocator, headFileName))
            {
                contentOfHead = await _fileContentRetriever.GetContent(_pullRequestLocator, diffFile.GetFilePath(headCommit));

                headPath = await SaveToFile(headFileName, contentOfHead);
            }
            else
            {
                headPath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, headFileName);
            }

            var baseFileName = BuildBaseFileName(baseCommit, diffFile.Filename);
            var basePath     = "";

            if (_fileContentPersist.ExistsInCached(_pullRequestLocator, baseFileName))
            {
                basePath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, baseFileName);
            }
            else if (diffFile.Status == FileStatus.Renamed)
            {
                if (contentOfHead == null)
                {
                    contentOfHead = await _fileContentPersist.ReadContent(headPath);
                }

                basePath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, baseFileName);

                await _patchService.RevertViaPatch(contentOfHead, diffFile.Patch, basePath);
            }
            else if (diffFile.Status == FileStatus.New)
            {
                basePath = await SaveToFile(baseFileName, "");
            }
            else
            {
                var contentOfBase = await _fileContentRetriever.GetContent(_pullRequestLocator, diffFile.GetFilePath(baseCommit));

                basePath = await SaveToFile(baseFileName, contentOfBase);
            }
            return(new Tuple <string, string>(basePath, headPath));
        }
        public async Task <Tuple <string, string> > FetchDiffContent(GitHubCommitFile diffFile,
                                                                     string headCommit, string baseCommit)
        {
            var    headFileName  = BuildHeadFileName(headCommit, diffFile.Filename);
            var    headPath      = "";
            string contentOfHead = null;

            if (diffFile.Status == GitFileStatus.Removed)
            {
                headPath = await SaveToFile(headFileName, "");
            }
            else if (!_fileContentPersist.ExistsInCached(_pullRequestLocator, headFileName))
            {
                var collectionOfContentOfHead =
                    await
                    _client.Repository.Content.GetAllContents(_pullRequestLocator.Owner,
                                                              _pullRequestLocator.Repository,
                                                              diffFile.GetFilePath(headCommit));

                contentOfHead = collectionOfContentOfHead.First().Content;
                headPath      = await SaveToFile(headFileName, contentOfHead);
            }
            else
            {
                headPath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, headFileName);
            }

            var baseFileName = BuildBaseFileName(baseCommit, diffFile.Filename);
            var basePath     = "";

            if (_fileContentPersist.ExistsInCached(_pullRequestLocator, baseFileName))
            {
                basePath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, baseFileName);
            }
            else if (diffFile.Status == GitFileStatus.Renamed)
            {
                if (contentOfHead == null)
                {
                    contentOfHead = await _fileContentPersist.ReadContent(headPath);
                }

                basePath = _fileContentPersist.GetCachedFilePath(_pullRequestLocator, baseFileName);

                await _patchService.RevertViaPatch(contentOfHead, diffFile.Patch, basePath);
            }
            else if (diffFile.Status == GitFileStatus.New)
            {
                basePath = await SaveToFile(baseFileName, "");
            }
            else
            {
                var contentOfBase =
                    await
                    _client.Repository.Content.GetAllContents(_pullRequestLocator.Owner,
                                                              _pullRequestLocator.Repository,
                                                              diffFile.GetFilePath(baseCommit));

                basePath = await SaveToFile(baseFileName, contentOfBase.First().Content);
            }
            return(new Tuple <string, string>(basePath, headPath));
        }