Skip to content

Commit

Permalink
refactor: git/storage -> git/index
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jun 29, 2020
1 parent 93130c5 commit 7611e63
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 92 deletions.
2 changes: 1 addition & 1 deletion lib/manager/composer/artifacts.spec.ts
Expand Up @@ -2,7 +2,7 @@ import { exec as _exec } from 'child_process';
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../test/execUtil';
import { mocked, platform } from '../../../test/util';
import { StatusResult } from '../../platform/git/storage';
import { StatusResult } from '../../platform/git';
import { setUtilConfig } from '../../util';
import { BinarySource } from '../../util/exec/common';
import * as docker from '../../util/exec/docker';
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/gomod/artifacts.spec.ts
Expand Up @@ -3,7 +3,7 @@ import _fs from 'fs-extra';
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../test/execUtil';
import { mocked, platform } from '../../../test/util';
import { StatusResult } from '../../platform/git/storage';
import { StatusResult } from '../../platform/git';
import { setUtilConfig } from '../../util';
import { BinarySource } from '../../util/exec/common';
import * as docker from '../../util/exec/docker';
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/pipenv/artifacts.spec.ts
Expand Up @@ -3,7 +3,7 @@ import _fs from 'fs-extra';
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../test/execUtil';
import { mocked, platform } from '../../../test/util';
import { StatusResult } from '../../platform/git/storage';
import { StatusResult } from '../../platform/git';
import { setUtilConfig } from '../../util';
import { BinarySource } from '../../util/exec/common';
import * as docker from '../../util/exec/docker';
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/azure/index.spec.ts
Expand Up @@ -15,14 +15,14 @@ describe('platform/azure', () => {
jest.resetModules();
jest.mock('./azure-got-wrapper');
jest.mock('./azure-helper');
jest.mock('../git/storage');
jest.mock('../git');
jest.mock('../../util/host-rules');
hostRules = require('../../util/host-rules');
require('../../util/sanitize').sanitize = jest.fn((input) => input);
azure = await import('.');
azureApi = require('./azure-got-wrapper');
azureHelper = require('./azure-helper');
GitStorage = require('../git/storage').Storage;
GitStorage = require('../git').Storage;
GitStorage.mockImplementation(() => ({
initRepo: jest.fn(),
cleanRepo: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/azure/index.ts
Expand Up @@ -31,7 +31,7 @@ import {
RepoParams,
VulnerabilityAlert,
} from '../common';
import GitStorage, { StatusResult } from '../git/storage';
import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body';
import * as azureApi from './azure-got-wrapper';
import * as azureHelper from './azure-helper';
Expand Down
6 changes: 3 additions & 3 deletions lib/platform/bitbucket-server/index.spec.ts
Expand Up @@ -8,7 +8,7 @@ import {
import { PR_STATE_CLOSED, PR_STATE_OPEN } from '../../constants/pull-requests';
import { BranchStatus } from '../../types';
import { Platform } from '../common';
import { Storage } from '../git/storage';
import { Storage } from '../git';

function repoMock(
endpoint: URL | string,
Expand Down Expand Up @@ -174,11 +174,11 @@ describe('platform/bitbucket-server', () => {
httpMock.reset();
httpMock.setup();
jest.mock('delay');
jest.mock('../git/storage');
jest.mock('../git');
jest.mock('../../util/host-rules');
hostRules = require('../../util/host-rules');
bitbucket = await import('.');
GitStorage = require('../git/storage').Storage;
GitStorage = require('../git').Storage;
GitStorage.mockImplementation(
() =>
({
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/bitbucket-server/index.ts
Expand Up @@ -34,7 +34,7 @@ import {
RepoParams,
VulnerabilityAlert,
} from '../common';
import GitStorage, { StatusResult } from '../git/storage';
import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body';
import { BbbsRestPr, BbsConfig, BbsPr, BbsRestUserRef } from './types';
import * as utils from './utils';
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/bitbucket-server/types.ts
@@ -1,5 +1,5 @@
import { Pr } from '../common';
import GitStorage from '../git/storage';
import GitStorage from '../git';

export interface BbsConfig {
baseBranch: string;
Expand Down
6 changes: 3 additions & 3 deletions lib/platform/bitbucket/index.spec.ts
Expand Up @@ -47,20 +47,20 @@ const commits = {
describe('platform/bitbucket', () => {
let bitbucket: Platform;
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>;
beforeEach(async () => {
// reset module
jest.resetModules();
httpMock.reset();
httpMock.setup();
jest.mock('../git/storage');
jest.mock('../git');
jest.mock('../../util/host-rules');
jest.mock('../../logger');
hostRules = require('../../util/host-rules');
bitbucket = await import('.');
logger = (await import('../../logger')).logger as any;
GitStorage = require('../git/storage').Storage;
GitStorage = require('../git').Storage;
GitStorage.mockImplementation(() => ({
initRepo: jest.fn(),
cleanRepo: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/bitbucket/index.ts
Expand Up @@ -29,7 +29,7 @@ import {
RepoParams,
VulnerabilityAlert,
} from '../common';
import GitStorage, { StatusResult } from '../git/storage';
import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body';
import { readOnlyIssueBody } from '../utils/read-only-issue-body';
import * as comments from './comments';
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/bitbucket/utils.ts
Expand Up @@ -4,7 +4,7 @@ import { BranchStatus } from '../../types';
import { HttpResponse } from '../../util/http';
import { BitbucketHttp } from '../../util/http/bitbucket';
import { Pr } from '../common';
import { Storage } from '../git/storage';
import { Storage } from '../git';

const bitbucketHttp = new BitbucketHttp();

Expand Down
59 changes: 59 additions & 0 deletions lib/platform/git/__snapshots__/index.spec.ts.snap
@@ -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]`;
59 changes: 0 additions & 59 deletions lib/platform/git/__snapshots__/storage.spec.ts.snap

This file was deleted.

@@ -1,9 +1,9 @@
import fs from 'fs-extra';
import Git from 'simple-git/promise';
import tmp from 'tmp-promise';
import GitStorage from './storage';
import GitStorage from '.';

describe('platform/git/storage', () => {
describe('platform/git', () => {
jest.setTimeout(15000);

const git = new GitStorage();
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions lib/platform/gitea/index.spec.ts
Expand Up @@ -25,8 +25,7 @@ describe('platform/gitea', () => {
let gitea: Platform;
let helper: jest.Mocked<typeof import('./gitea-helper')>;
let logger: jest.Mocked<typeof _logger>;
let GitStorage: jest.Mocked<typeof import('../git/storage').Storage> &
jest.Mock;
let GitStorage: jest.Mocked<typeof import('../git').Storage> & jest.Mock;

const mockCommitHash = '0d9c7726c3d628b7e28af234595cfd20febdbf8e';

Expand Down Expand Up @@ -174,13 +173,13 @@ describe('platform/gitea', () => {
jest.resetModules();
jest.clearAllMocks();
jest.mock('./gitea-helper');
jest.mock('../git/storage');
jest.mock('../git');
jest.mock('../../logger');

gitea = await import('.');
helper = (await import('./gitea-helper')) 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(() => ({
initRepo: gsmInitRepo,
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/gitea/index.ts
Expand Up @@ -34,7 +34,7 @@ import {
RepoParams,
VulnerabilityAlert,
} from '../common';
import GitStorage, { StatusResult } from '../git/storage';
import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body';
import * as helper from './gitea-helper';

Expand Down
6 changes: 3 additions & 3 deletions lib/platform/github/index.spec.ts
Expand Up @@ -14,7 +14,7 @@ const githubApiHost = 'https://api.github.com';
describe('platform/github', () => {
let github: Platform;
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 () => {
// reset module
jest.resetModules();
Expand All @@ -23,8 +23,8 @@ describe('platform/github', () => {
jest.mock('../../util/host-rules');
github = await import('.');
hostRules = mocked(await import('../../util/host-rules'));
jest.mock('../git/storage');
GitStorage = (await import('../git/storage')).Storage as any;
jest.mock('../git');
GitStorage = (await import('../git')).Storage as any;
GitStorage.mockImplementation(
() =>
({
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/github/index.ts
Expand Up @@ -44,7 +44,7 @@ import {
RepoParams,
VulnerabilityAlert,
} from '../common';
import GitStorage, { StatusResult } from '../git/storage';
import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body';
import {
BranchProtection,
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/github/types.ts
@@ -1,5 +1,5 @@
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/checks/runs/
Expand Down
6 changes: 3 additions & 3 deletions lib/platform/gitlab/index.spec.ts
Expand Up @@ -21,7 +21,7 @@ const gitlabApiHost = 'https://gitlab.com';
describe('platform/gitlab', () => {
let gitlab: Platform;
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 () => {
// reset module
jest.resetModules();
Expand All @@ -30,8 +30,8 @@ describe('platform/gitlab', () => {
jest.mock('../../util/host-rules');
jest.mock('delay');
hostRules = require('../../util/host-rules');
jest.mock('../git/storage');
GitStorage = require('../git/storage').Storage;
jest.mock('../git');
GitStorage = require('../git').Storage;
GitStorage.mockImplementation(() => ({
initRepo: jest.fn(),
cleanRepo: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/gitlab/index.ts
Expand Up @@ -38,7 +38,7 @@ import {
RepoParams,
VulnerabilityAlert,
} from '../common';
import GitStorage, { StatusResult } from '../git/storage';
import GitStorage, { StatusResult } from '../git';
import { smartTruncate } from '../utils/pr-body';

const gitlabApi = new GitlabHttp();
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/branch/index.spec.ts
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../constants/pull-requests';
import * as _npmPostExtract from '../../manager/npm/post-update';
import { File } from '../../platform';
import { StatusResult } from '../../platform/git/storage';
import { StatusResult } from '../../platform/git';
import * as _exec from '../../util/exec';
import { BranchConfig, PrResult } from '../common';
import * as _prWorker from '../pr';
Expand Down

0 comments on commit 7611e63

Please sign in to comment.