2023-04-26 08:52:53 -07:00
|
|
|
import type { IRestApiContext, VersionControlPreferences } from '@/Interface';
|
|
|
|
import { makeRestApiRequest } from '@/utils';
|
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
|
|
|
|
|
|
|
const versionControlApiRoot = '/version-control';
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
export const initSsh = async (context: IRestApiContext, data: IDataObject): Promise<string> => {
|
2023-04-26 08:52:53 -07:00
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/init-ssh`, data);
|
|
|
|
};
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
export const initRepository = async (
|
2023-04-26 08:52:53 -07:00
|
|
|
context: IRestApiContext,
|
|
|
|
): Promise<{ branches: string[]; currentBranch: string }> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/init-repository`);
|
|
|
|
};
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
export const sync = async (context: IRestApiContext, data: IDataObject): Promise<void> => {
|
2023-04-26 08:52:53 -07:00
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/push`, data);
|
|
|
|
};
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
export const getConfig = async (
|
2023-04-26 08:52:53 -07:00
|
|
|
context: IRestApiContext,
|
|
|
|
): Promise<{ remoteRepository: string; name: string; email: string; currentBranch: string }> => {
|
|
|
|
return makeRestApiRequest(context, 'GET', `${versionControlApiRoot}/config`);
|
|
|
|
};
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
export const setPreferences = async (
|
2023-04-26 08:52:53 -07:00
|
|
|
context: IRestApiContext,
|
|
|
|
preferences: Partial<VersionControlPreferences>,
|
|
|
|
): Promise<VersionControlPreferences> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/preferences`, preferences);
|
|
|
|
};
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
export const getPreferences = async (
|
|
|
|
context: IRestApiContext,
|
|
|
|
): Promise<VersionControlPreferences> => {
|
2023-04-26 08:52:53 -07:00
|
|
|
return makeRestApiRequest(context, 'GET', `${versionControlApiRoot}/preferences`);
|
|
|
|
};
|