chore: reworking the API exports and fixing the logging to be a little less verbose

This commit is contained in:
blam
2020-12-29 11:46:36 +01:00
parent 7f9fc7f99d
commit ba6f2b8a40
3 changed files with 35 additions and 31 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ jest.mock('isomorphic-git/http/node');
jest.mock('fs-extra');
import * as isomorphic from 'isomorphic-git';
import * as Git from './git';
import { Git } from './git';
import http from 'isomorphic-git/http/node';
import fs from 'fs-extra';
+33 -28
View File
@@ -19,17 +19,17 @@ import fs from 'fs-extra';
import { Logger } from 'winston';
/*
provider username password
provider username password
GitHub token 'x-oauth-basic'
GitHub App token 'x-access-token'
BitBucket 'x-token-auth' token
GitLab 'oauth2' token
GitHub App token 'x-access-token'
BitBucket 'x-token-auth' token
GitLab 'oauth2' token
From : https://isomorphic-git.org/docs/en/onAuth
Azure 'notempty' token
*/
class SCM {
constructor(
export class Git {
private constructor(
private readonly config: {
username?: string;
password?: string;
@@ -85,7 +85,7 @@ class SCM {
dir,
singleBranch: true,
depth: 1,
onProgress: this.onProgressHandler,
onProgress: this.onProgressHandler(),
headers: {
'user-agent': 'git/@isomorphic-git',
},
@@ -110,7 +110,7 @@ class SCM {
http,
dir,
remote: remoteValue,
onProgress: this.onProgressHandler,
onProgress: this.onProgressHandler(),
headers: {
'user-agent': 'git/@isomorphic-git',
},
@@ -163,7 +163,7 @@ class SCM {
fs,
dir,
http,
onProgress: this.onProgressHandler,
onProgress: this.onProgressHandler(),
headers: {
'user-agent': 'git/@isomorphic-git',
},
@@ -187,23 +187,28 @@ class SCM {
password: this.config.password,
});
private onProgressHandler: ProgressCallback = event => {
const total = event.total
? `${Math.round((event.loaded / event.total) * 100)}%`
: event.loaded;
this.config.logger?.info(`status={${event.phase},total={${total}}}`);
};
}
private onProgressHandler = (): ProgressCallback => {
let currentPhase = '';
// TODO(blam): This could potentially become something like for URL
// and use the integrations config for URLReading instead.
// But for now, I don't want to do all that in this PR.
export const fromAuth = ({
username,
password,
logger,
}: {
username?: string;
password?: string;
logger?: Logger;
}) => new SCM({ username, password, logger });
return event => {
if (currentPhase !== event.phase) {
currentPhase = event.phase;
this.config.logger?.info(event.phase);
}
const total = event.total
? `${Math.round((event.loaded / event.total) * 100)}%`
: event.loaded;
this.config.logger?.debug(`status={${event.phase},total={${total}}}`);
};
};
static fromAuth = ({
username,
password,
logger,
}: {
username?: string;
password?: string;
logger?: Logger;
}) => new Git({ username, password, logger });
}
+1 -2
View File
@@ -13,6 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as Git from './git';
export { Git };
export { Git } from './git';