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 1 commit
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);
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({

Check warning on line 13 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L13

Added line #L13 was not covered by tests
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([]);

Check warning on line 22 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L22

Added line #L22 was not covered by tests
}

export function initRepo(): Promise<RepoResult> {
return Promise.resolve({

Check warning on line 26 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L26

Added line #L26 was not covered by tests
defaultBranch: '',
isFork: false,
repoFingerprint: '',
viceice marked this conversation as resolved.
Show resolved Hide resolved
});
}

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

Check warning on line 34 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L34

Added line #L34 was not covered by tests
}

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

Check warning on line 38 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L38

Added line #L38 was not covered by tests
}

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

Check warning on line 42 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L42

Added line #L42 was not covered by tests
}

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

Check warning on line 46 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L46

Added line #L46 was not covered by tests
}

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

Check warning on line 50 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L50

Added line #L50 was not covered by tests
}

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

Check warning on line 54 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L54

Added line #L54 was not covered by tests
}

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

Check warning on line 58 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L58

Added line #L58 was not covered by tests
}

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

Check warning on line 62 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L62

Added line #L62 was not covered by tests
}

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

Check warning on line 66 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L66

Added line #L66 was not covered by tests
}

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

Check warning on line 70 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L70

Added line #L70 was not covered by tests
}

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

Check warning on line 74 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L74

Added line #L74 was not covered by tests
}

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

Check warning on line 78 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L78

Added line #L78 was not covered by tests
}

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

Check warning on line 82 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L82

Added line #L82 was not covered by tests
}

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

Check warning on line 86 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L86

Added line #L86 was not covered by tests
}

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

Check warning on line 90 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L90

Added line #L90 was not covered by tests
}

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

Check warning on line 94 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L94

Added line #L94 was not covered by tests
}

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

Check warning on line 98 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L98

Added line #L98 was not covered by tests
}

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

Check warning on line 102 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L102

Added line #L102 was not covered by tests
}

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

Check warning on line 106 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L106

Added line #L106 was not covered by tests
}

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

Check warning on line 110 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L110

Added line #L110 was not covered by tests
}

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

Check warning on line 114 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L114

Added line #L114 was not covered by tests
}

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

Check warning on line 118 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L118

Added line #L118 was not covered by tests
}

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

Check warning on line 122 in lib/modules/platform/local/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/index.ts#L122

Added line #L122 was not covered by tests
}
45 changes: 45 additions & 0 deletions lib/modules/platform/local/scm.ts
@@ -0,0 +1,45 @@
import { glob } from 'glob';
import type { CommitFilesConfig, CommitSha } from '../../../util/git/types';
import type { PlatformScm } from '../types';

let fileList: string[] | undefined;
rarkins marked this conversation as resolved.
Show resolved Hide resolved
export class LocalFs implements PlatformScm {
fileList: string[] | undefined;
JamieMagee marked this conversation as resolved.
Show resolved Hide resolved
rarkins marked this conversation as resolved.
Show resolved Hide resolved

isBranchBehindBase(branchName: string, baseBranch: string): Promise<boolean> {
return Promise.resolve(false);

Check warning on line 10 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L9-L10

Added lines #L9 - L10 were not covered by tests
}
isBranchModified(branchName: string): Promise<boolean> {
return Promise.resolve(false);

Check warning on line 13 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L12-L13

Added lines #L12 - L13 were not covered by tests
}
isBranchConflicted(baseBranch: string, branch: string): Promise<boolean> {
return Promise.resolve(false);

Check warning on line 16 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L15-L16

Added lines #L15 - L16 were not covered by tests
}
branchExists(branchName: string): Promise<boolean> {
return Promise.resolve(true);

Check warning on line 19 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L18-L19

Added lines #L18 - L19 were not covered by tests
}
getBranchCommit(branchName: string): Promise<string | null> {
return Promise.resolve(null);

Check warning on line 22 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L21-L22

Added lines #L21 - L22 were not covered by tests
}
deleteBranch(branchName: string): Promise<void> {
return Promise.resolve();

Check warning on line 25 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L24-L25

Added lines #L24 - L25 were not covered by tests
}
commitAndPush(commitConfig: CommitFilesConfig): Promise<string | null> {
return Promise.resolve(null);

Check warning on line 28 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L27-L28

Added lines #L27 - L28 were not covered by tests
}

async getFileList(): Promise<string[]> {
fileList ??= await glob('**', {

Check warning on line 32 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L31-L32

Added lines #L31 - L32 were not covered by tests
rarkins marked this conversation as resolved.
Show resolved Hide resolved
dot: true,
nodir: true,
ignore: {
childrenIgnored: (p) => p.isNamed('.git') || p.isNamed('node_modules'),

Check warning on line 36 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L36

Added line #L36 was not covered by tests
JamieMagee marked this conversation as resolved.
Show resolved Hide resolved
rarkins marked this conversation as resolved.
Show resolved Hide resolved
},
});
return fileList;

Check warning on line 39 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L39

Added line #L39 was not covered by tests
}

checkoutBranch(branchName: string): Promise<CommitSha> {
return Promise.resolve('');

Check warning on line 43 in lib/modules/platform/local/scm.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/local/scm.ts#L42-L43

Added lines #L42 - L43 were not covered by tests
}
}
2 changes: 2 additions & 0 deletions lib/modules/platform/scm.ts
Expand Up @@ -3,6 +3,7 @@ import type { PlatformId } from '../../constants';
import { PLATFORM_NOT_FOUND } from '../../constants/error-messages';
import { DefaultGitScm } from './default-scm';
import { GithubScm } from './github/scm';
import { LocalFs } from './local/scm';
import type { PlatformScm } from './types';

export const platformScmImpls = new Map<PlatformId, Constructor<PlatformScm>>();
Expand All @@ -13,6 +14,7 @@ platformScmImpls.set('bitbucket-server', DefaultGitScm);
platformScmImpls.set('gitea', DefaultGitScm);
platformScmImpls.set('github', GithubScm);
platformScmImpls.set('gitlab', DefaultGitScm);
platformScmImpls.set('local', LocalFs);

let _scm: PlatformScm | undefined;

Expand Down
5 changes: 5 additions & 0 deletions lib/util/fs/index.spec.ts
Expand Up @@ -134,6 +134,11 @@ describe('util/fs/index', () => {
});

describe('deleteLocalFile', () => {
it('throws if platform is local', async () => {
GlobalConfig.set({ platform: 'local' });
await expect(deleteLocalFile('foo/bar/file.txt')).rejects.toThrow();
});

it('deletes file', async () => {
const filePath = `${localDir}/foo/bar/file.txt`;
await fs.outputFile(filePath, 'foobar');
Expand Down
4 changes: 4 additions & 0 deletions lib/util/fs/index.ts
Expand Up @@ -65,6 +65,10 @@ export async function writeLocalFile(
}

export async function deleteLocalFile(fileName: string): Promise<void> {
// This a failsafe and hopefully will never be triggered
if (GlobalConfig.get('platform') === 'local') {
throw new Error('Cannot delete file when platform=local');
}
const localDir = GlobalConfig.get('localDir');
if (localDir) {
const localFileName = ensureLocalPath(fileName);
Expand Down
4 changes: 4 additions & 0 deletions lib/util/git/index.ts
Expand Up @@ -379,6 +379,10 @@ export async function syncGit(): Promise<void> {
if (gitInitialized) {
return;
}
// istanbul ignore if: failsafe
if (GlobalConfig.get('platform') === 'local') {
throw new Error('Cannot sync git when platform=local');
}
gitInitialized = true;
const localDir = GlobalConfig.get('localDir')!;
logger.debug(`Initializing git repository into ${localDir}`);
Expand Down
9 changes: 9 additions & 0 deletions lib/workers/global/autodiscover.ts
Expand Up @@ -13,6 +13,15 @@
export async function autodiscoverRepositories(
config: AllConfig
): Promise<AllConfig> {
if (config.platform === 'local') {
if (config.repositories?.length) {
logger.warn(

Check warning on line 18 in lib/workers/global/autodiscover.ts

View check run for this annotation

Codecov / codecov/patch

lib/workers/global/autodiscover.ts#L17-L18

Added lines #L17 - L18 were not covered by tests
{ repositories: config.repositories },
'platform=local supports only cwd'
);
}
config.repositories = ['local'];

Check warning on line 23 in lib/workers/global/autodiscover.ts

View check run for this annotation

Codecov / codecov/patch

lib/workers/global/autodiscover.ts#L23

Added line #L23 was not covered by tests
}
rarkins marked this conversation as resolved.
Show resolved Hide resolved
if (!config.autodiscover) {
if (!config.repositories?.length) {
logger.warn(
Expand Down
11 changes: 7 additions & 4 deletions lib/workers/global/index.ts
Expand Up @@ -37,10 +37,13 @@
);
// TODO: types (#7154)
const platform = GlobalConfig.get('platform')!;
repoConfig.localDir = upath.join(
repoConfig.baseDir,
`./repos/${platform}/${repoConfig.repository}`
);
repoConfig.localDir =
platform === 'local'
? process.cwd()

Check warning on line 42 in lib/workers/global/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/workers/global/index.ts#L42

Added line #L42 was not covered by tests
: upath.join(
repoConfig.baseDir,
`./repos/${platform}/${repoConfig.repository}`
);
await fs.ensureDir(repoConfig.localDir);
delete repoConfig.baseDir;
return configParser.filterConfig(repoConfig, 'repository');
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/process/index.ts
Expand Up @@ -108,7 +108,7 @@ export async function extractDependencies(
branchList: [],
packageFiles: null!,
};
if (config.baseBranches?.length) {
if (GlobalConfig.get('platform') !== 'local' && config.baseBranches?.length) {
viceice marked this conversation as resolved.
Show resolved Hide resolved
config.baseBranches = unfoldBaseBranches(config.baseBranches);
logger.debug({ baseBranches: config.baseBranches }, 'baseBranches');
const extracted: Record<string, Record<string, PackageFile[]>> = {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -196,6 +196,7 @@
"global-agent": "3.0.0",
"good-enough-parser": "1.1.22",
"got": "11.8.6",
"glob": "10.2.2",
"graph-data-structure": "3.3.0",
"handlebars": "4.7.7",
"hasha": "5.2.2",
Expand Down Expand Up @@ -307,7 +308,6 @@
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-typescript-enum": "2.1.0",
"expect-more-jest": "5.5.0",
"glob": "10.2.2",
"graphql": "16.6.0",
"husky": "8.0.3",
"jest": "29.5.0",
Expand Down