Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="diffFile"></param>
        /// <returns>basePath and headPath</returns>
        private async Task <Tuple <string, string> > FetchDiffContent(ICommitFile diffFile)
        {
            var fetcher = new DiffContentFetcher(PullRequestLocator, _fileContentPersist,
                                                 _patchService, new FileContentRetriever(_client));

            return(await fetcher.FetchDiffContent(diffFile, HeadCommit, BaseCommit));
        }
Exemplo n.º 2
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));
        }