refactor: git/storage -> git/index

This commit is contained in:
Rhys Arkins 2020-06-29 09:11:55 +02:00
parent 93130c5634
commit 7611e6353a
23 changed files with 91 additions and 92 deletions

View file

@ -2,7 +2,7 @@ import { exec as _exec } from 'child_process';
import { join } from 'upath'; import { join } from 'upath';
import { envMock, mockExecAll } from '../../../test/execUtil'; import { envMock, mockExecAll } from '../../../test/execUtil';
import { mocked, platform } from '../../../test/util'; import { mocked, platform } from '../../../test/util';
import { StatusResult } from '../../platform/git/storage'; import { StatusResult } from '../../platform/git';
import { setUtilConfig } from '../../util'; import { setUtilConfig } from '../../util';
import { BinarySource } from '../../util/exec/common'; import { BinarySource } from '../../util/exec/common';
import * as docker from '../../util/exec/docker'; import * as docker from '../../util/exec/docker';

View file

@ -3,7 +3,7 @@ import _fs from 'fs-extra';
import { join } from 'upath'; import { join } from 'upath';
import { envMock, mockExecAll } from '../../../test/execUtil'; import { envMock, mockExecAll } from '../../../test/execUtil';
import { mocked, platform } from '../../../test/util'; import { mocked, platform } from '../../../test/util';
import { StatusResult } from '../../platform/git/storage'; import { StatusResult } from '../../platform/git';
import { setUtilConfig } from '../../util'; import { setUtilConfig } from '../../util';
import { BinarySource } from '../../util/exec/common'; import { BinarySource } from '../../util/exec/common';
import * as docker from '../../util/exec/docker'; import * as docker from '../../util/exec/docker';

View file

@ -3,7 +3,7 @@ import _fs from 'fs-extra';
import { join } from 'upath'; import { join } from 'upath';
import { envMock, mockExecAll } from '../../../test/execUtil'; import { envMock, mockExecAll } from '../../../test/execUtil';
import { mocked, platform } from '../../../test/util'; import { mocked, platform } from '../../../test/util';
import { StatusResult } from '../../platform/git/storage'; import { StatusResult } from '../../platform/git';
import { setUtilConfig } from '../../util'; import { setUtilConfig } from '../../util';
import { BinarySource } from '../../util/exec/common'; import { BinarySource } from '../../util/exec/common';
import * as docker from '../../util/exec/docker'; import * as docker from '../../util/exec/docker';

View file

@ -15,14 +15,14 @@ describe('platform/azure', () => {
jest.resetModules(); jest.resetModules();
jest.mock('./azure-got-wrapper'); jest.mock('./azure-got-wrapper');
jest.mock('./azure-helper'); jest.mock('./azure-helper');
jest.mock('../git/storage'); jest.mock('../git');
jest.mock('../../util/host-rules'); jest.mock('../../util/host-rules');
hostRules = require('../../util/host-rules'); hostRules = require('../../util/host-rules');
require('../../util/sanitize').sanitize = jest.fn((input) => input); require('../../util/sanitize').sanitize = jest.fn((input) => input);
azure = await import('.'); azure = await import('.');
azureApi = require('./azure-got-wrapper'); azureApi = require('./azure-got-wrapper');
azureHelper = require('./azure-helper'); azureHelper = require('./azure-helper');
GitStorage = require('../git/storage').Storage; GitStorage = require('../git').Storage;
GitStorage.mockImplementation(() => ({ GitStorage.mockImplementation(() => ({
initRepo: jest.fn(), initRepo: jest.fn(),
cleanRepo: jest.fn(), cleanRepo: jest.fn(),

View file

@ -31,7 +31,7 @@ import {
RepoParams, RepoParams,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import GitStorage, { StatusResult } from '../git/storage'; import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
import * as azureApi from './azure-got-wrapper'; import * as azureApi from './azure-got-wrapper';
import * as azureHelper from './azure-helper'; import * as azureHelper from './azure-helper';

View file

@ -8,7 +8,7 @@ import {
import { PR_STATE_CLOSED, PR_STATE_OPEN } from '../../constants/pull-requests'; import { PR_STATE_CLOSED, PR_STATE_OPEN } from '../../constants/pull-requests';
import { BranchStatus } from '../../types'; import { BranchStatus } from '../../types';
import { Platform } from '../common'; import { Platform } from '../common';
import { Storage } from '../git/storage'; import { Storage } from '../git';
function repoMock( function repoMock(
endpoint: URL | string, endpoint: URL | string,
@ -174,11 +174,11 @@ describe('platform/bitbucket-server', () => {
httpMock.reset(); httpMock.reset();
httpMock.setup(); httpMock.setup();
jest.mock('delay'); jest.mock('delay');
jest.mock('../git/storage'); jest.mock('../git');
jest.mock('../../util/host-rules'); jest.mock('../../util/host-rules');
hostRules = require('../../util/host-rules'); hostRules = require('../../util/host-rules');
bitbucket = await import('.'); bitbucket = await import('.');
GitStorage = require('../git/storage').Storage; GitStorage = require('../git').Storage;
GitStorage.mockImplementation( GitStorage.mockImplementation(
() => () =>
({ ({

View file

@ -34,7 +34,7 @@ import {
RepoParams, RepoParams,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import GitStorage, { StatusResult } from '../git/storage'; import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
import { BbbsRestPr, BbsConfig, BbsPr, BbsRestUserRef } from './types'; import { BbbsRestPr, BbsConfig, BbsPr, BbsRestUserRef } from './types';
import * as utils from './utils'; import * as utils from './utils';

View file

@ -1,5 +1,5 @@
import { Pr } from '../common'; import { Pr } from '../common';
import GitStorage from '../git/storage'; import GitStorage from '../git';
export interface BbsConfig { export interface BbsConfig {
baseBranch: string; baseBranch: string;

View file

@ -47,20 +47,20 @@ const commits = {
describe('platform/bitbucket', () => { describe('platform/bitbucket', () => {
let bitbucket: Platform; let bitbucket: Platform;
let hostRules: jest.Mocked<typeof import('../../util/host-rules')>; let hostRules: jest.Mocked<typeof import('../../util/host-rules')>;
let GitStorage: jest.Mocked<import('../git/storage').Storage> & jest.Mock; let GitStorage: jest.Mocked<import('../git').Storage> & jest.Mock;
let logger: jest.Mocked<typeof _logger>; let logger: jest.Mocked<typeof _logger>;
beforeEach(async () => { beforeEach(async () => {
// reset module // reset module
jest.resetModules(); jest.resetModules();
httpMock.reset(); httpMock.reset();
httpMock.setup(); httpMock.setup();
jest.mock('../git/storage'); jest.mock('../git');
jest.mock('../../util/host-rules'); jest.mock('../../util/host-rules');
jest.mock('../../logger'); jest.mock('../../logger');
hostRules = require('../../util/host-rules'); hostRules = require('../../util/host-rules');
bitbucket = await import('.'); bitbucket = await import('.');
logger = (await import('../../logger')).logger as any; logger = (await import('../../logger')).logger as any;
GitStorage = require('../git/storage').Storage; GitStorage = require('../git').Storage;
GitStorage.mockImplementation(() => ({ GitStorage.mockImplementation(() => ({
initRepo: jest.fn(), initRepo: jest.fn(),
cleanRepo: jest.fn(), cleanRepo: jest.fn(),

View file

@ -29,7 +29,7 @@ import {
RepoParams, RepoParams,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import GitStorage, { StatusResult } from '../git/storage'; import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
import { readOnlyIssueBody } from '../utils/read-only-issue-body'; import { readOnlyIssueBody } from '../utils/read-only-issue-body';
import * as comments from './comments'; import * as comments from './comments';

View file

@ -4,7 +4,7 @@ import { BranchStatus } from '../../types';
import { HttpResponse } from '../../util/http'; import { HttpResponse } from '../../util/http';
import { BitbucketHttp } from '../../util/http/bitbucket'; import { BitbucketHttp } from '../../util/http/bitbucket';
import { Pr } from '../common'; import { Pr } from '../common';
import { Storage } from '../git/storage'; import { Storage } from '../git';
const bitbucketHttp = new BitbucketHttp(); const bitbucketHttp = new BitbucketHttp();

View file

@ -0,0 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`platform/git getBranchCommit(branchName) should throw if branch does not exist 1`] = `[Error: Cannot fetch commit for branch that does not exist: not_found]`;
exports[`platform/git getBranchFiles(branchName, baseBranchName?) detects changed files 1`] = `
Array [
"some-new-file",
]
`;
exports[`platform/git getBranchFiles(branchName, baseBranchName?) detects changed files compared to current base branch 1`] = `
Array [
"some-new-file",
]
`;
exports[`platform/git getCommitMessages() returns commit messages 1`] = `
Array [
"master message",
"past message",
]
`;
exports[`platform/git getFile(filePath, branchName) returns null for 404 1`] = `[Error: repository-changed]`;
exports[`platform/git getFileList() should exclude submodules 1`] = `
Array [
".gitmodules",
"file_to_delete",
"master_file",
"past_file",
]
`;
exports[`platform/git getFileList() should return the correct files 1`] = `
Array [
"file_to_delete",
"master_file",
"past_file",
]
`;
exports[`platform/git initRepo()) should fetch latest 1`] = `
Array [
"master message",
"past message",
]
`;
exports[`platform/git initRepo()) should fetch latest 2`] = `
Array [
"past message2",
"master message",
]
`;
exports[`platform/git isBranchStale() should throw if branch does not exist 1`] = `[Error: Cannot check staleness for branch that does not exist: not_found]`;
exports[`platform/git setBaseBranch(branchName) should throw if branch does not exist 1`] = `[Error: config-validation]`;

View file

@ -1,59 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`platform/git/storage getBranchCommit(branchName) should throw if branch does not exist 1`] = `[Error: Cannot fetch commit for branch that does not exist: not_found]`;
exports[`platform/git/storage getBranchFiles(branchName, baseBranchName?) detects changed files 1`] = `
Array [
"some-new-file",
]
`;
exports[`platform/git/storage getBranchFiles(branchName, baseBranchName?) detects changed files compared to current base branch 1`] = `
Array [
"some-new-file",
]
`;
exports[`platform/git/storage getCommitMessages() returns commit messages 1`] = `
Array [
"master message",
"past message",
]
`;
exports[`platform/git/storage getFile(filePath, branchName) returns null for 404 1`] = `[Error: repository-changed]`;
exports[`platform/git/storage getFileList() should exclude submodules 1`] = `
Array [
".gitmodules",
"file_to_delete",
"master_file",
"past_file",
]
`;
exports[`platform/git/storage getFileList() should return the correct files 1`] = `
Array [
"file_to_delete",
"master_file",
"past_file",
]
`;
exports[`platform/git/storage initRepo()) should fetch latest 1`] = `
Array [
"master message",
"past message",
]
`;
exports[`platform/git/storage initRepo()) should fetch latest 2`] = `
Array [
"past message2",
"master message",
]
`;
exports[`platform/git/storage isBranchStale() should throw if branch does not exist 1`] = `[Error: Cannot check staleness for branch that does not exist: not_found]`;
exports[`platform/git/storage setBaseBranch(branchName) should throw if branch does not exist 1`] = `[Error: config-validation]`;

View file

@ -1,9 +1,9 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import Git from 'simple-git/promise'; import Git from 'simple-git/promise';
import tmp from 'tmp-promise'; import tmp from 'tmp-promise';
import GitStorage from './storage'; import GitStorage from '.';
describe('platform/git/storage', () => { describe('platform/git', () => {
jest.setTimeout(15000); jest.setTimeout(15000);
const git = new GitStorage(); const git = new GitStorage();

View file

@ -25,8 +25,7 @@ describe('platform/gitea', () => {
let gitea: Platform; let gitea: Platform;
let helper: jest.Mocked<typeof import('./gitea-helper')>; let helper: jest.Mocked<typeof import('./gitea-helper')>;
let logger: jest.Mocked<typeof _logger>; let logger: jest.Mocked<typeof _logger>;
let GitStorage: jest.Mocked<typeof import('../git/storage').Storage> & let GitStorage: jest.Mocked<typeof import('../git').Storage> & jest.Mock;
jest.Mock;
const mockCommitHash = '0d9c7726c3d628b7e28af234595cfd20febdbf8e'; const mockCommitHash = '0d9c7726c3d628b7e28af234595cfd20febdbf8e';
@ -174,13 +173,13 @@ describe('platform/gitea', () => {
jest.resetModules(); jest.resetModules();
jest.clearAllMocks(); jest.clearAllMocks();
jest.mock('./gitea-helper'); jest.mock('./gitea-helper');
jest.mock('../git/storage'); jest.mock('../git');
jest.mock('../../logger'); jest.mock('../../logger');
gitea = await import('.'); gitea = await import('.');
helper = (await import('./gitea-helper')) as any; helper = (await import('./gitea-helper')) as any;
logger = (await import('../../logger')).logger as any; logger = (await import('../../logger')).logger as any;
GitStorage = (await import('../git/storage')).Storage as any; GitStorage = (await import('../git')).Storage as any;
GitStorage.mockImplementation(() => ({ GitStorage.mockImplementation(() => ({
initRepo: gsmInitRepo, initRepo: gsmInitRepo,

View file

@ -34,7 +34,7 @@ import {
RepoParams, RepoParams,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import GitStorage, { StatusResult } from '../git/storage'; import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
import * as helper from './gitea-helper'; import * as helper from './gitea-helper';

View file

@ -14,7 +14,7 @@ const githubApiHost = 'https://api.github.com';
describe('platform/github', () => { describe('platform/github', () => {
let github: Platform; let github: Platform;
let hostRules: jest.Mocked<typeof import('../../util/host-rules')>; let hostRules: jest.Mocked<typeof import('../../util/host-rules')>;
let GitStorage: jest.Mock<typeof import('../git/storage')>; let GitStorage: jest.Mock<typeof import('../git')>;
beforeEach(async () => { beforeEach(async () => {
// reset module // reset module
jest.resetModules(); jest.resetModules();
@ -23,8 +23,8 @@ describe('platform/github', () => {
jest.mock('../../util/host-rules'); jest.mock('../../util/host-rules');
github = await import('.'); github = await import('.');
hostRules = mocked(await import('../../util/host-rules')); hostRules = mocked(await import('../../util/host-rules'));
jest.mock('../git/storage'); jest.mock('../git');
GitStorage = (await import('../git/storage')).Storage as any; GitStorage = (await import('../git')).Storage as any;
GitStorage.mockImplementation( GitStorage.mockImplementation(
() => () =>
({ ({

View file

@ -44,7 +44,7 @@ import {
RepoParams, RepoParams,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import GitStorage, { StatusResult } from '../git/storage'; import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
import { import {
BranchProtection, BranchProtection,

View file

@ -1,5 +1,5 @@
import { Pr } from '../common'; import { Pr } from '../common';
import GitStorage from '../git/storage'; import GitStorage from '../git';
// https://developer.github.com/v3/repos/statuses // https://developer.github.com/v3/repos/statuses
// https://developer.github.com/v3/checks/runs/ // https://developer.github.com/v3/checks/runs/

View file

@ -21,7 +21,7 @@ const gitlabApiHost = 'https://gitlab.com';
describe('platform/gitlab', () => { describe('platform/gitlab', () => {
let gitlab: Platform; let gitlab: Platform;
let hostRules: jest.Mocked<typeof _hostRules>; let hostRules: jest.Mocked<typeof _hostRules>;
let GitStorage: jest.Mocked<typeof import('../git/storage')> & jest.Mock; let GitStorage: jest.Mocked<typeof import('../git')> & jest.Mock;
beforeEach(async () => { beforeEach(async () => {
// reset module // reset module
jest.resetModules(); jest.resetModules();
@ -30,8 +30,8 @@ describe('platform/gitlab', () => {
jest.mock('../../util/host-rules'); jest.mock('../../util/host-rules');
jest.mock('delay'); jest.mock('delay');
hostRules = require('../../util/host-rules'); hostRules = require('../../util/host-rules');
jest.mock('../git/storage'); jest.mock('../git');
GitStorage = require('../git/storage').Storage; GitStorage = require('../git').Storage;
GitStorage.mockImplementation(() => ({ GitStorage.mockImplementation(() => ({
initRepo: jest.fn(), initRepo: jest.fn(),
cleanRepo: jest.fn(), cleanRepo: jest.fn(),

View file

@ -38,7 +38,7 @@ import {
RepoParams, RepoParams,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import GitStorage, { StatusResult } from '../git/storage'; import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
const gitlabApi = new GitlabHttp(); const gitlabApi = new GitlabHttp();

View file

@ -11,7 +11,7 @@ import {
} from '../../constants/pull-requests'; } from '../../constants/pull-requests';
import * as _npmPostExtract from '../../manager/npm/post-update'; import * as _npmPostExtract from '../../manager/npm/post-update';
import { File } from '../../platform'; import { File } from '../../platform';
import { StatusResult } from '../../platform/git/storage'; import { StatusResult } from '../../platform/git';
import * as _exec from '../../util/exec'; import * as _exec from '../../util/exec';
import { BranchConfig, PrResult } from '../common'; import { BranchConfig, PrResult } from '../common';
import * as _prWorker from '../pr'; import * as _prWorker from '../pr';