mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(core): Only check for folder changes when parentFolderId is present (#14618)
This commit is contained in:
@@ -15,11 +15,28 @@ import {
|
|||||||
getTrackingInformationFromPostPushResult,
|
getTrackingInformationFromPostPushResult,
|
||||||
getTrackingInformationFromPrePushResult,
|
getTrackingInformationFromPrePushResult,
|
||||||
getTrackingInformationFromPullResult,
|
getTrackingInformationFromPullResult,
|
||||||
|
isWorkflowModified,
|
||||||
sourceControlFoldersExistCheck,
|
sourceControlFoldersExistCheck,
|
||||||
} from '@/environments.ee/source-control/source-control-helper.ee';
|
} from '@/environments.ee/source-control/source-control-helper.ee';
|
||||||
import type { SourceControlPreferencesService } from '@/environments.ee/source-control/source-control-preferences.service.ee';
|
import type { SourceControlPreferencesService } from '@/environments.ee/source-control/source-control-preferences.service.ee';
|
||||||
import type { License } from '@/license';
|
import type { License } from '@/license';
|
||||||
|
|
||||||
|
import type { SourceControlWorkflowVersionId } from '../types/source-control-workflow-version-id';
|
||||||
|
|
||||||
|
function createWorkflowVersion(
|
||||||
|
overrides: Partial<SourceControlWorkflowVersionId> = {},
|
||||||
|
): SourceControlWorkflowVersionId {
|
||||||
|
return {
|
||||||
|
id: 'workflow123',
|
||||||
|
versionId: 'version1',
|
||||||
|
filename: 'workflows/workflow123.json',
|
||||||
|
parentFolderId: 'folder1',
|
||||||
|
updatedAt: '2023-07-10T10:10:59.000Z',
|
||||||
|
name: 'Test Workflow',
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const pushResult: SourceControlledFile[] = [
|
const pushResult: SourceControlledFile[] = [
|
||||||
{
|
{
|
||||||
file: 'credential_stubs/kkookWGIeey9K4Kt.json',
|
file: 'credential_stubs/kkookWGIeey9K4Kt.json',
|
||||||
@@ -252,3 +269,47 @@ describe('Source Control', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isWorkflowModified', () => {
|
||||||
|
it('should detect modifications when version IDs differ', () => {
|
||||||
|
const local = createWorkflowVersion();
|
||||||
|
const remote = createWorkflowVersion({ versionId: 'version2' });
|
||||||
|
|
||||||
|
expect(isWorkflowModified(local, remote)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should detect modifications when parent folder IDs differ', () => {
|
||||||
|
const local = createWorkflowVersion();
|
||||||
|
const remote = createWorkflowVersion({ parentFolderId: 'folder2' });
|
||||||
|
|
||||||
|
expect(isWorkflowModified(local, remote)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not detect modifications when version IDs and parent folder IDs are the same', () => {
|
||||||
|
const local = createWorkflowVersion();
|
||||||
|
const remote = createWorkflowVersion();
|
||||||
|
|
||||||
|
expect(isWorkflowModified(local, remote)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not consider it modified when remote parent folder ID is undefined', () => {
|
||||||
|
const local = createWorkflowVersion();
|
||||||
|
const remote = createWorkflowVersion({ parentFolderId: undefined });
|
||||||
|
|
||||||
|
expect(isWorkflowModified(local, remote)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should detect modifications when parent folder IDs differ and remote parent folder ID is defined', () => {
|
||||||
|
const local = createWorkflowVersion({ parentFolderId: null });
|
||||||
|
const remote = createWorkflowVersion();
|
||||||
|
|
||||||
|
expect(isWorkflowModified(local, remote)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle null parent folder IDs correctly', () => {
|
||||||
|
const local = createWorkflowVersion({ parentFolderId: null });
|
||||||
|
const remote = createWorkflowVersion({ parentFolderId: null });
|
||||||
|
|
||||||
|
expect(isWorkflowModified(local, remote)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from './constants';
|
} from './constants';
|
||||||
import type { KeyPair } from './types/key-pair';
|
import type { KeyPair } from './types/key-pair';
|
||||||
import type { KeyPairType } from './types/key-pair-type';
|
import type { KeyPairType } from './types/key-pair-type';
|
||||||
|
import type { SourceControlWorkflowVersionId } from './types/source-control-workflow-version-id';
|
||||||
|
|
||||||
export function stringContainsExpression(testString: string): boolean {
|
export function stringContainsExpression(testString: string): boolean {
|
||||||
return /^=.*\{\{.*\}\}/.test(testString);
|
return /^=.*\{\{.*\}\}/.test(testString);
|
||||||
@@ -204,3 +205,17 @@ export function normalizeAndValidateSourceControlledFilePath(
|
|||||||
|
|
||||||
return normalizedPath;
|
return normalizedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a workflow has been modified by comparing version IDs and parent folder IDs
|
||||||
|
* between local and remote versions
|
||||||
|
*/
|
||||||
|
export function isWorkflowModified(
|
||||||
|
local: SourceControlWorkflowVersionId,
|
||||||
|
remote: SourceControlWorkflowVersionId,
|
||||||
|
): boolean {
|
||||||
|
return (
|
||||||
|
remote.versionId !== local.versionId ||
|
||||||
|
(remote.parentFolderId !== undefined && remote.parentFolderId !== local.parentFolderId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {
|
|||||||
getTrackingInformationFromPrePushResult,
|
getTrackingInformationFromPrePushResult,
|
||||||
getTrackingInformationFromPullResult,
|
getTrackingInformationFromPullResult,
|
||||||
getVariablesPath,
|
getVariablesPath,
|
||||||
|
isWorkflowModified,
|
||||||
normalizeAndValidateSourceControlledFilePath,
|
normalizeAndValidateSourceControlledFilePath,
|
||||||
sourceControlFoldersExistCheck,
|
sourceControlFoldersExistCheck,
|
||||||
} from './source-control-helper.ee';
|
} from './source-control-helper.ee';
|
||||||
@@ -571,25 +572,37 @@ export class SourceControlService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const wfModifiedInEither: SourceControlWorkflowVersionId[] = [];
|
const wfModifiedInEither: SourceControlWorkflowVersionId[] = [];
|
||||||
wfLocalVersionIds.forEach((local) => {
|
|
||||||
const mismatchingIds = wfRemoteVersionIds.find(
|
wfLocalVersionIds.forEach((localWorkflow) => {
|
||||||
(remote) =>
|
const remoteWorkflowWithSameId = wfRemoteVersionIds.find(
|
||||||
remote.id === local.id &&
|
(removeWorkflow) => removeWorkflow.id === localWorkflow.id,
|
||||||
(remote.versionId !== local.versionId || remote.parentFolderId !== local.parentFolderId),
|
|
||||||
);
|
);
|
||||||
let name = (options?.preferLocalVersion ? local?.name : mismatchingIds?.name) ?? 'Workflow';
|
|
||||||
if (local.name && mismatchingIds?.name && local.name !== mismatchingIds.name) {
|
if (!remoteWorkflowWithSameId) {
|
||||||
name = options?.preferLocalVersion
|
return;
|
||||||
? `${local.name} (Remote: ${mismatchingIds.name})`
|
|
||||||
: (name = `${mismatchingIds.name} (Local: ${local.name})`);
|
|
||||||
}
|
}
|
||||||
if (mismatchingIds) {
|
|
||||||
|
if (isWorkflowModified(localWorkflow, remoteWorkflowWithSameId)) {
|
||||||
|
let name =
|
||||||
|
(options?.preferLocalVersion ? localWorkflow?.name : remoteWorkflowWithSameId?.name) ??
|
||||||
|
'Workflow';
|
||||||
|
if (
|
||||||
|
localWorkflow.name &&
|
||||||
|
remoteWorkflowWithSameId?.name &&
|
||||||
|
localWorkflow.name !== remoteWorkflowWithSameId.name
|
||||||
|
) {
|
||||||
|
name = options?.preferLocalVersion
|
||||||
|
? `${localWorkflow.name} (Remote: ${remoteWorkflowWithSameId.name})`
|
||||||
|
: (name = `${remoteWorkflowWithSameId.name} (Local: ${localWorkflow.name})`);
|
||||||
|
}
|
||||||
wfModifiedInEither.push({
|
wfModifiedInEither.push({
|
||||||
...local,
|
...localWorkflow,
|
||||||
name,
|
name,
|
||||||
versionId: options.preferLocalVersion ? local.versionId : mismatchingIds.versionId,
|
versionId: options.preferLocalVersion
|
||||||
localId: local.versionId,
|
? localWorkflow.versionId
|
||||||
remoteId: mismatchingIds.versionId,
|
: remoteWorkflowWithSameId.versionId,
|
||||||
|
localId: localWorkflow.versionId,
|
||||||
|
remoteId: remoteWorkflowWithSameId.versionId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user