Merge latest changes from origin before rebuilding docs (#2117)

* Added missing tests and make sure we merge latest changes before building docs from a repo

* Removed flaky test
This commit is contained in:
Sebastian Qvarfordt
2020-08-25 17:03:10 +02:00
committed by GitHub
parent 2e0ede67e9
commit a027e632a0
2 changed files with 63 additions and 1 deletions
@@ -0,0 +1,56 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getVoidLogger } from '@backstage/backend-common';
import { GithubPreparer } from './github';
import { checkoutGitRepository } from './helpers';
jest.mock('./helpers', () => ({
...jest.requireActual<{}>('./helpers'),
checkoutGitRepository: jest.fn(() => '/tmp/backstage-repo/org/name/branch'),
}));
const createMockEntity = (annotations = {}) => {
return {
apiVersion: 'version',
kind: 'TestKind',
metadata: {
name: 'test-component-name',
annotations: {
...annotations,
},
},
};
};
const logger = getVoidLogger();
describe('github preparer', () => {
it('should prepare temp docs path from github repo', async () => {
const preparer = new GithubPreparer(logger);
const mockEntity = createMockEntity({
'backstage.io/techdocs-ref':
'github:https://github.com/spotify/backstage/blob/master/plugins/techdocs-backend/examples/documented-component',
});
const tempDocsPath = await preparer.prepare(mockEntity);
expect(checkoutGitRepository).toHaveBeenCalledTimes(1);
expect(tempDocsPath).toEqual(
'/tmp/backstage-repo/org/name/branch/plugins/techdocs-backend/examples/documented-component',
);
});
});
@@ -17,7 +17,7 @@ import { Entity } from '@backstage/catalog-model';
import { InputError } from '@backstage/backend-common';
import { RemoteProtocol } from './types';
import parseGitUrl from 'git-url-parse';
import { Clone } from 'nodegit';
import { Clone, Repository } from 'nodegit';
import fs from 'fs-extra';
import os from 'os';
import path from 'path';
@@ -78,8 +78,14 @@ export const checkoutGitRepository = async (
);
if (fs.existsSync(repositoryTmpPath)) {
const repository = await Repository.open(repositoryTmpPath);
await repository.mergeBranches(
parsedGitLocation.ref,
`origin/${parsedGitLocation.ref}`,
);
return repositoryTmpPath;
}
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
fs.mkdirSync(repositoryTmpPath, { recursive: true });