feat: adding in all the functions needed for isomorphic git feature
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
"fs-extra": "^9.0.1",
|
||||
"git-url-parse": "^11.4.0",
|
||||
"helmet": "^4.0.0",
|
||||
"isomorphic-git": "^1.8.0",
|
||||
"knex": "^0.21.6",
|
||||
"lodash": "^4.17.15",
|
||||
"logform": "^2.1.1",
|
||||
|
||||
@@ -16,14 +16,19 @@
|
||||
import git from 'isomorphic-git';
|
||||
import http from 'isomorphic-git/http/node';
|
||||
import fs from 'fs-extra';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
class SCM {
|
||||
constructor(
|
||||
private readonly config: { username: string; password: string },
|
||||
private readonly logger: Logger,
|
||||
private readonly config: {
|
||||
username: string;
|
||||
password: string;
|
||||
logger?: Logger;
|
||||
},
|
||||
) {}
|
||||
|
||||
async clone({ url, dir }) {
|
||||
async clone({ url, dir }: { url: string; dir: string }) {
|
||||
this.config.logger?.info(`Cloning repo {dir=${dir},url=${url}}`);
|
||||
return git.clone({
|
||||
fs,
|
||||
http,
|
||||
@@ -35,7 +40,7 @@ class SCM {
|
||||
const total = event.total
|
||||
? `${Math.round((event.loaded / event.total) * 100)}%`
|
||||
: event.loaded;
|
||||
this.logger.info(`status={${event.phase},total={${total}}}`);
|
||||
this.config.logger?.info(`status={${event.phase},total={${total}}}`);
|
||||
},
|
||||
headers: {
|
||||
'user-agent': 'git/@isomorphic-git',
|
||||
@@ -46,6 +51,79 @@ class SCM {
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
async init({ dir }: { dir: string }) {
|
||||
this.config.logger?.info(`Init git repository {dir=${dir}}`);
|
||||
|
||||
return git.init({
|
||||
fs,
|
||||
dir,
|
||||
});
|
||||
}
|
||||
|
||||
async add({ dir, filepath }: { dir: string; filepath: string }) {
|
||||
this.config.logger?.info(`Adding file {dir=${dir},filepath=${filepath}}`);
|
||||
|
||||
return git.add({ fs, dir, filepath });
|
||||
}
|
||||
|
||||
async commit({
|
||||
dir,
|
||||
message,
|
||||
author,
|
||||
committer,
|
||||
}: {
|
||||
dir: string;
|
||||
message: string;
|
||||
author: { name: string; email: string };
|
||||
committer: { name: string; email: string };
|
||||
}) {
|
||||
this.config.logger?.info(
|
||||
`Committing file to repo {dir=${dir},message=${message}}`,
|
||||
);
|
||||
|
||||
return git.commit({ fs, dir, message, author, committer });
|
||||
}
|
||||
|
||||
async addRemote({
|
||||
dir,
|
||||
url,
|
||||
remoteName,
|
||||
}: {
|
||||
dir: string;
|
||||
remoteName: string;
|
||||
url: string;
|
||||
}) {
|
||||
this.config.logger?.info(
|
||||
`Creating new remote {dir=${dir},remoteName=${remoteName},url=${url}}`,
|
||||
);
|
||||
return git.addRemote({ fs, dir, remote: remoteName, url });
|
||||
}
|
||||
|
||||
async push({ dir, remoteName }: { dir: string; remoteName: string }) {
|
||||
this.config.logger?.info(
|
||||
`Pushing directory to remote {dir=${dir},remoteName=${remoteName}}`,
|
||||
);
|
||||
git.push({
|
||||
fs,
|
||||
dir,
|
||||
http,
|
||||
onProgress: event => {
|
||||
const total = event.total
|
||||
? `${Math.round((event.loaded / event.total) * 100)}%`
|
||||
: event.loaded;
|
||||
this.config.logger?.info(`status={${event.phase},total={${total}}}`);
|
||||
},
|
||||
headers: {
|
||||
'user-agent': 'git/@isomorphic-git',
|
||||
},
|
||||
remote: remoteName,
|
||||
onAuth: () => ({
|
||||
username: this.config.username,
|
||||
password: this.config.password,
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const fromAuth = ({
|
||||
@@ -55,7 +133,7 @@ export const fromAuth = ({
|
||||
}: {
|
||||
username: string;
|
||||
password: string;
|
||||
logger: Logger;
|
||||
logger?: Logger;
|
||||
}) => {
|
||||
return new SCM({ username, password });
|
||||
return new SCM({ username, password, logger });
|
||||
};
|
||||
|
||||
@@ -1630,7 +1630,9 @@
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@backstage/catalog-model@^0.2.0":
|
||||
version "0.4.0"
|
||||
version "0.2.0"
|
||||
resolved "https://registry.npmjs.org/@backstage/catalog-model/-/catalog-model-0.2.0.tgz#e3fe2a4ddeb6a9b6ec480c80cb2b9c39cb245576"
|
||||
integrity sha512-Y1ocdRpBlxK/VrJQjHlQd0bgADECd1B2NRjwd8ss46ibT5hwLvMOfD80+Fa7oPLu0ktJrH4lq0pNIIJIml48zA==
|
||||
dependencies:
|
||||
"@backstage/config" "^0.1.1"
|
||||
"@types/json-schema" "^7.0.5"
|
||||
@@ -1641,7 +1643,9 @@
|
||||
yup "^0.29.3"
|
||||
|
||||
"@backstage/catalog-model@^0.3.0":
|
||||
version "0.4.0"
|
||||
version "0.3.1"
|
||||
resolved "https://registry.npmjs.org/@backstage/catalog-model/-/catalog-model-0.3.1.tgz#45d08e2f333c9c566b2bf2629fd707fe989bb404"
|
||||
integrity sha512-9XhV7c4rmVW+Yzj2PiwTQ7DsegWGB3C4ELsDRExuEVZONdqNcC02cyJtrt3fT5F31ZS3tHkB9bMUymFOBLqUSA==
|
||||
dependencies:
|
||||
"@backstage/config" "^0.1.1"
|
||||
"@types/json-schema" "^7.0.5"
|
||||
|
||||
Reference in New Issue
Block a user