2021-04-05 15:50:55 +00:00
|
|
|
import type { GitCredentials } from './git-vcs';
|
|
|
|
|
2021-04-01 01:36:11 +00:00
|
|
|
export const translateSSHtoHTTP = (url: string) => {
|
|
|
|
// handle "shorter scp-like syntax"
|
|
|
|
url = url.replace(/^git@([^:]+):/, 'https://$1/');
|
|
|
|
// handle proper SSH URLs
|
|
|
|
url = url.replace(/^ssh:\/\//, 'https://');
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2021-04-05 15:50:55 +00:00
|
|
|
export const addDotGit = (url: string): string => (url.endsWith('.git') ? url : `${url}.git`);
|
2021-04-01 01:36:11 +00:00
|
|
|
|
|
|
|
const onMessage = (message: string) => {
|
|
|
|
console.log(`[git-event] ${message}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onAuthFailure = (message: string) => {
|
|
|
|
console.log(`[git-event] Auth Failure: ${message}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onAuthSuccess = (message: string) => {
|
|
|
|
console.log(`[git-event] Auth Success: ${message}`);
|
|
|
|
};
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION this needs to be handled better if credentials is undefined or which union type
|
|
|
|
const onAuth = (credentials?: GitCredentials = {}) => () => ({
|
2021-04-01 01:36:11 +00:00
|
|
|
username: credentials.username,
|
2021-05-27 18:00:32 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION this needs to be handled better if credentials is undefined or which union type
|
2021-04-01 01:36:11 +00:00
|
|
|
password: credentials.password || credentials.token,
|
|
|
|
});
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export const gitCallbacks = (credentials?: GitCredentials | null) => ({
|
2021-04-01 01:36:11 +00:00
|
|
|
onMessage,
|
|
|
|
onAuthFailure,
|
|
|
|
onAuthSuccess,
|
2021-05-12 06:35:00 +00:00
|
|
|
onAuth: onAuth(credentials || undefined),
|
2021-04-01 01:36:11 +00:00
|
|
|
});
|
2021-05-12 06:35:00 +00:00
|
|
|
|
|
|
|
// unfortunately, as of @types/node:v14.14.32 this type is not exported so we have to hackily grab it from here.
|
|
|
|
export type BufferEncoding = NonNullable<Parameters<typeof Buffer.from>[1]>;
|