From bce1e7070235eb2807e6a87a4150781f97826b93 Mon Sep 17 00:00:00 2001 From: Chris Wendt Date: Wed, 24 Oct 2018 11:51:49 -0700 Subject: [PATCH] fix: call resolveRev when getting file info --- src/libs/code_intelligence/utils/file_info.ts | 17 +++++++++++++++++ src/libs/github/file_info.ts | 3 ++- src/libs/gitlab/file_info.ts | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/libs/code_intelligence/utils/file_info.ts diff --git a/src/libs/code_intelligence/utils/file_info.ts b/src/libs/code_intelligence/utils/file_info.ts new file mode 100644 index 00000000..048d9350 --- /dev/null +++ b/src/libs/code_intelligence/utils/file_info.ts @@ -0,0 +1,17 @@ +import { Observable, zip } from 'rxjs' +import { map, switchMap } from 'rxjs/operators' +import { FileInfo } from '..' +import { resolveRev, retryWhenCloneInProgressError } from '../../../shared/repo/backend' + +export const ensureRevisionsAreCloned = (files: Observable): Observable => + files.pipe( + switchMap(({ repoPath, rev, baseRev, ...rest }) => { + // Although we get the commit SHA's from elesewhere, we still need to + // use `resolveRev` otherwise we can't guarantee Sourcegraph has the + // revision cloned. + const resolvingHeadRev = resolveRev({ repoPath, rev }).pipe(retryWhenCloneInProgressError()) + const resolvingBaseRev = resolveRev({ repoPath, rev: baseRev }).pipe(retryWhenCloneInProgressError()) + + return zip(resolvingHeadRev, resolvingBaseRev).pipe(map(() => ({ repoPath, rev, baseRev, ...rest }))) + }) + ) diff --git a/src/libs/github/file_info.ts b/src/libs/github/file_info.ts index 18c35cb6..4dc14d5c 100644 --- a/src/libs/github/file_info.ts +++ b/src/libs/github/file_info.ts @@ -4,6 +4,7 @@ import { filter, map, switchMap } from 'rxjs/operators' import { GitHubBlobUrl } from '.' import { resolveRev, retryWhenCloneInProgressError } from '../../shared/repo/backend' import { FileInfo } from '../code_intelligence' +import { ensureRevisionsAreCloned } from '../code_intelligence/utils/file_info' import { getCommitIDFromPermalink } from './scrape' import { getDeltaFileName, getDiffResolvedRev, getGitHubState, parseURL } from './util' @@ -85,7 +86,7 @@ export const resolveFileInfo = (): Observable => { filePath, commitID, rev: rev || commitID, - }) + }).pipe(ensureRevisionsAreCloned) } catch (error) { return throwError(error) } diff --git a/src/libs/gitlab/file_info.ts b/src/libs/gitlab/file_info.ts index 3c2fe81d..8c465eff 100644 --- a/src/libs/gitlab/file_info.ts +++ b/src/libs/gitlab/file_info.ts @@ -37,7 +37,7 @@ export const resolveFileInfo = (): Observable => { filePath, commitID, rev, - }) + }).pipe(ensureRevisionsAreCloned) } catch (error) { return throwError(error) }