Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: platform=local #22010

Merged
merged 9 commits into from May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/config/presets/local/index.ts
Expand Up @@ -24,6 +24,7 @@ const resolvers = {
gitea,
github,
gitlab,
local: null,
viceice marked this conversation as resolved.
Show resolved Hide resolved
} satisfies Record<PlatformId, Resolver | null>;

export function getPreset({
Expand Down
3 changes: 2 additions & 1 deletion lib/constants/platforms.ts
Expand Up @@ -5,7 +5,8 @@ export type PlatformId =
| 'bitbucket-server'
| 'gitea'
| 'github'
| 'gitlab';
| 'gitlab'
| 'local';

export const GITHUB_API_USING_HOST_TYPES = [
'github',
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/api.ts
Expand Up @@ -6,6 +6,7 @@ import * as codecommit from './codecommit';
import * as gitea from './gitea';
import * as github from './github';
import * as gitlab from './gitlab';
import * as local from './local';
import type { Platform } from './types';

const api = new Map<PlatformId, Platform>();
Expand All @@ -18,3 +19,4 @@ api.set(codecommit.id, codecommit);
api.set(gitea.id, gitea);
api.set(github.id, github);
api.set(gitlab.id, gitlab);
api.set(local.id, local);
128 changes: 128 additions & 0 deletions lib/modules/platform/local/index.spec.ts
@@ -0,0 +1,128 @@
import * as platform from './index';

describe('modules/platform/local/index', () => {
describe('initPlatform', () => {
it('returns input', async () => {
expect(await platform.initPlatform({})).toMatchInlineSnapshot(`
{
"dryRun": "lookup",
"endpoint": "local",
"persistRepoData": true,
"requireConfig": "optional",
}
`);
});
});

describe('getRepos', () => {
it('returns empty array', async () => {
expect(await platform.getRepos()).toEqual([]);
});
});

describe('initRepo', () => {
it('returns object', async () => {
expect(await platform.initRepo()).toMatchInlineSnapshot(`
{
"defaultBranch": "",
"isFork": false,
"repoFingerprint": "",
}
`);
});
});

describe('dummy functions', () => {
it('getRepoForceRebase', async () => {
expect(await platform.getRepoForceRebase()).toBe(false);
});

it('findIssue', async () => {
expect(await platform.findIssue()).toBeNull();
});

it('getIssueList', async () => {
expect(await platform.getIssueList()).toEqual([]);
});

it('getRawFile', async () => {
expect(await platform.getRawFile()).toBeNull();
});

it('getJsonFile', async () => {
expect(await platform.getJsonFile()).toBeNull();
});

it('getPrList', async () => {
expect(await platform.getPrList()).toEqual([]);
});

it('ensureIssueClosing', async () => {
expect(await platform.ensureIssueClosing()).toBeUndefined();
});

it('ensureIssue', async () => {
expect(await platform.ensureIssue()).toBeNull();
});

it('massageMarkdown', () => {
expect(platform.massageMarkdown('foo')).toBe('foo');
});

it('updatePr', async () => {
expect(await platform.updatePr()).toBeUndefined();
});

it('mergePr', async () => {
expect(await platform.mergePr()).toBe(false);
});

it('addReviewers', async () => {
expect(await platform.addReviewers()).toBeUndefined();
});

it('addAssignees', async () => {
expect(await platform.addAssignees()).toBeUndefined();
});

it('createPr', async () => {
expect(await platform.createPr()).toBeNull();
});

it('deleteLabel', async () => {
expect(await platform.deleteLabel()).toBeUndefined();
});

it('setBranchStatus', async () => {
expect(await platform.setBranchStatus()).toBeUndefined();
});

it('getBranchStatus', async () => {
expect(await platform.getBranchStatus()).toBe('red');
});

it('getBranchStatusCheck', async () => {
expect(await platform.getBranchStatusCheck()).toBeNull();
});

it('ensureCommentRemoval', async () => {
expect(await platform.ensureCommentRemoval()).toBeUndefined();
});

it('ensureComment', async () => {
expect(await platform.ensureComment()).toBeFalse();
});

it('getPr', async () => {
expect(await platform.getPr()).toBeNull();
});

it('findPr', async () => {
expect(await platform.findPr()).toBeNull();
});

it('getBranchPr', async () => {
expect(await platform.getBranchPr()).toBeNull();
});
});
});
123 changes: 123 additions & 0 deletions lib/modules/platform/local/index.ts
viceice marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,123 @@
import type { BranchStatus } from '../../../types';
import type {
Issue,
PlatformParams,
PlatformResult,
Pr,
RepoResult,
} from '../types';

export const id = 'local';

export function initPlatform(params: PlatformParams): Promise<PlatformResult> {
return Promise.resolve({
dryRun: 'lookup',
viceice marked this conversation as resolved.
Show resolved Hide resolved
endpoint: 'local',
persistRepoData: true,
viceice marked this conversation as resolved.
Show resolved Hide resolved
requireConfig: 'optional',
viceice marked this conversation as resolved.
Show resolved Hide resolved
});
}

export function getRepos(): Promise<string[]> {
return Promise.resolve([]);
}

export function initRepo(): Promise<RepoResult> {
return Promise.resolve({
defaultBranch: '',
isFork: false,
repoFingerprint: '',
viceice marked this conversation as resolved.
Show resolved Hide resolved
});
}

export function getRepoForceRebase(): Promise<boolean> {
return Promise.resolve(false);
}

export function findIssue(): Promise<null> {
return Promise.resolve(null);
}

export function getIssueList(): Promise<Issue[]> {
return Promise.resolve([]);
}

export function getRawFile(): Promise<string | null> {
return Promise.resolve(null);
}

export function getJsonFile(): Promise<Record<string, unknown> | null> {
return Promise.resolve(null);
}

export function getPrList(): Promise<Pr[]> {
return Promise.resolve([]);
}

export function ensureIssueClosing(): Promise<void> {
return Promise.resolve();
}

export function ensureIssue(): Promise<null> {
return Promise.resolve(null);
}

export function massageMarkdown(input: string): string {
return input;
}

export function updatePr(): Promise<void> {
return Promise.resolve();
}

export function mergePr(): Promise<boolean> {
return Promise.resolve(false);
}

export function addReviewers(): Promise<void> {
return Promise.resolve();
}

export function addAssignees(): Promise<void> {
return Promise.resolve();
}

export function createPr(): Promise<null> {
return Promise.resolve(null);
}

export function deleteLabel(): Promise<void> {
return Promise.resolve();
}

export function setBranchStatus(): Promise<void> {
return Promise.resolve();
}

export function getBranchStatus(): Promise<BranchStatus> {
return Promise.resolve('red');
}

export function getBranchStatusCheck(): Promise<null> {
return Promise.resolve(null);
}

export function ensureCommentRemoval(): Promise<void> {
return Promise.resolve();
}

export function ensureComment(): Promise<boolean> {
return Promise.resolve(false);
}

export function getPr(): Promise<null> {
return Promise.resolve(null);
}

export function findPr(): Promise<null> {
return Promise.resolve(null);
}

export function getBranchPr(): Promise<null> {
return Promise.resolve(null);
}
68 changes: 68 additions & 0 deletions lib/modules/platform/local/scm.spec.ts
@@ -0,0 +1,68 @@
import { execSync as _execSync } from 'node:child_process';
import { mockedFunction } from '../../../../test/util';
import { LocalFs } from './scm';

jest.mock('node:child_process');
const execSync = mockedFunction(_execSync);

describe('modules/platform/local/scm', () => {
let localFs: LocalFs;

beforeEach(() => {
localFs = new LocalFs();
});

describe('dummy functions', () => {
it('behindBaseBranch', async () => {
expect(await localFs.isBranchBehindBase('', '')).toBe(false);
});

it('isBranchModified', async () => {
expect(await localFs.isBranchModified('')).toBe(false);
});

it('isBranchConflicted', async () => {
expect(await localFs.isBranchConflicted('', '')).toBe(false);
});

it('branchExists', async () => {
expect(await localFs.branchExists('')).toBe(true);
});

it('getBranchCommit', async () => {
expect(await localFs.getBranchCommit('')).toBeNull();
});

it('deleteBranch', async () => {
expect(await localFs.deleteBranch('')).toBeUndefined();
});

it('commitAndPush', async () => {
expect(await localFs.commitAndPush({} as any)).toBeNull();
});

it('checkoutBranch', async () => {
expect(await localFs.checkoutBranch('')).toBe('');
});
});

describe('getFileList', () => {
it('should return file list using git', async () => {
execSync.mockReturnValueOnce('file1\nfile2');
expect(await localFs.getFileList()).toHaveLength(2);
});

it('should return file list using glob', async () => {
execSync.mockImplementationOnce(() => {
throw new Error();
});
jest.mock('glob', () => ({
glob: jest
.fn()
.mockImplementation(() => Promise.resolve(['file1', 'file2'])),
}));

expect(await localFs.getFileList()).toHaveLength(2);
});
});
});