2023-05-31 06:01:57 -07:00
|
|
|
import type {
|
|
|
|
IRestApiContext,
|
|
|
|
VersionControlAggregatedFile,
|
|
|
|
VersionControlPreferences,
|
|
|
|
VersionControlStatus,
|
|
|
|
} from '@/Interface';
|
2023-04-26 08:52:53 -07:00
|
|
|
import { makeRestApiRequest } from '@/utils';
|
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
|
|
|
|
|
|
|
const versionControlApiRoot = '/version-control';
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
export const pushWorkfolder = async (
|
|
|
|
context: IRestApiContext,
|
|
|
|
data: IDataObject,
|
|
|
|
): Promise<void> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/push-workfolder`, data);
|
2023-04-26 08:52:53 -07:00
|
|
|
};
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
export const pullWorkfolder = async (
|
2023-04-26 08:52:53 -07:00
|
|
|
context: IRestApiContext,
|
2023-05-31 06:01:57 -07:00
|
|
|
data: IDataObject,
|
|
|
|
): Promise<void> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/pull-workfolder`, data);
|
2023-04-26 08:52:53 -07:00
|
|
|
};
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
export const getBranches = async (
|
|
|
|
context: IRestApiContext,
|
|
|
|
): Promise<{ branches: string[]; currentBranch: string }> => {
|
|
|
|
return makeRestApiRequest(context, 'GET', `${versionControlApiRoot}/get-branches`);
|
2023-04-26 08:52:53 -07:00
|
|
|
};
|
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
export const setBranch = async (
|
2023-04-26 08:52:53 -07:00
|
|
|
context: IRestApiContext,
|
2023-05-31 06:01:57 -07:00
|
|
|
branch: string,
|
|
|
|
): Promise<{ branches: string[]; currentBranch: string }> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/set-branch`, { branch });
|
2023-04-26 08:52:53 -07:00
|
|
|
};
|
|
|
|
|
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`);
|
|
|
|
};
|
2023-05-31 06:01:57 -07:00
|
|
|
|
|
|
|
export const getStatus = async (context: IRestApiContext): Promise<VersionControlStatus> => {
|
|
|
|
return makeRestApiRequest(context, 'GET', `${versionControlApiRoot}/status`);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getAggregatedStatus = async (
|
|
|
|
context: IRestApiContext,
|
|
|
|
): Promise<VersionControlAggregatedFile[]> => {
|
|
|
|
return makeRestApiRequest(context, 'GET', `${versionControlApiRoot}/get-status`);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const disconnect = async (
|
|
|
|
context: IRestApiContext,
|
|
|
|
keepKeyPair: boolean,
|
|
|
|
): Promise<string> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/disconnect`, {
|
|
|
|
keepKeyPair,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setBranchReadonly = async (
|
|
|
|
context: IRestApiContext,
|
|
|
|
branchReadOnly: boolean,
|
|
|
|
): Promise<string> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/set-read-only`, {
|
|
|
|
branchReadOnly,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const generateKeyPair = async (context: IRestApiContext): Promise<string> => {
|
|
|
|
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/generate-key-pair`);
|
|
|
|
};
|