Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #1001

Merged
merged 50 commits into from
Aug 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9671e4e
Modified workflows to use the latest version of the github actions
cs-raj Jul 13, 2023
c8fe0b0
Resolved the error in yaml
cs-raj Jul 13, 2023
dbe8694
update merge flow
Jul 17, 2023
8aba058
Merge branch 'development' into feat/CS-39612
cs-raj Jul 25, 2023
344f876
Merge branch 'development' into feat/CS-39612
cs-raj Jul 25, 2023
ec1e5ae
Removed secrets-scan
cs-raj Jul 25, 2023
63d93de
update migration scripts with reference logic
Jul 28, 2023
da5dbb9
Merge branch 'development' into feat/CS-37813-entry-exp-updates
Jul 28, 2023
e611efc
Merge branch 'development' into feat/CS-37812-entry-exp-updates
netrajpatel Aug 1, 2023
8b39cc0
fix: migration command(undefined reading length) issue
aman19K Aug 4, 2023
7fb43f3
Merge branch 'development' into feat/CS-37812-entry-exp-updates
netrajpatel Aug 7, 2023
955c988
Added the publish time in the publish_details colum, Version Bump, au…
cs-raj Aug 7, 2023
1dde369
Minor Version Update
cs-raj Aug 7, 2023
32bf4a9
Removed stray console.log
cs-raj Aug 7, 2023
7ffadd7
Merge branch 'development' into feat/CS-37812-entry-exp-updates
aman19K Aug 17, 2023
3690091
Merge pull request #916 from contentstack/feat/CS-37812-entry-exp-upd…
aman19K Aug 17, 2023
8c2688d
Fix: Workflow stage UID remains same after export and import of stack
antonyagustine Aug 17, 2023
b6177bd
Merge branch 'development' into bugfix/CS-40537
antonyagustine Aug 17, 2023
e8484db
Fix: Update next available stages uid on workflow
antonyagustine Aug 18, 2023
f15c4be
Merge branch 'bugfix/CS-40537' of https://github.com/contentstack/cli…
antonyagustine Aug 18, 2023
bcf97af
Merge branch 'development' into feat/CS-40466
cs-raj Aug 18, 2023
0015e29
Merged development and correct minor version update
cs-raj Aug 18, 2023
1bb0f45
feat: asset migration script
aman19K Aug 18, 2023
398fb77
Fix: Workflows typescript type definition fixes
antonyagustine Aug 18, 2023
23af231
Merge pull request #968 from contentstack/feat/CS-40466
cs-raj Aug 18, 2023
1f45c3b
Merge branch 'development' into bugfix/CS-40537
abhinav-from-contentstack Aug 18, 2023
3a3d04b
Merge pull request #986 from contentstack/bugfix/CS-40537
antonyagustine Aug 18, 2023
84ac315
Merge branch 'development' into 40719
netrajpatel Aug 21, 2023
26566f1
Merge branch 'development' into feat/CS-39612
cs-raj Aug 22, 2023
58cd850
Merge pull request #970 from contentstack/40719
cs-raj Aug 22, 2023
2b34d2d
Merge branch 'development' into feat/CS-39612
cs-raj Aug 22, 2023
5f42153
Merge pull request #913 from contentstack/feat/CS-39612
cs-raj Aug 22, 2023
3f8fc66
fix: entries modified script
aman19K Aug 22, 2023
d52ffc1
fix: asset fetch is not a function issue
aman19K Aug 22, 2023
82398fc
fix: entry valid file upload issue
aman19K Aug 23, 2023
8175914
fix: json rte field
aman19K Aug 23, 2023
2dfda62
fix: global field reference issue
aman19K Aug 23, 2023
73ca7b6
fix: json rte ref issue
aman19K Aug 23, 2023
ed433e4
Merge branch 'development' into feat/CS-39927
aman19K Aug 24, 2023
d5a4127
Merge pull request #996 from contentstack/staging
abhinav-from-contentstack Aug 24, 2023
67287c2
fix: ctSchema is not iterable
aman19K Aug 24, 2023
2ed217c
Merge branch 'staging' into merge/CS-40858
abhinav-from-contentstack Aug 24, 2023
0fe862c
Merge branch 'main' into merge/CS-40858
abhinav-from-contentstack Aug 24, 2023
175f365
Merge pull request #1000 from contentstack/merge/CS-40858
abhinav-from-contentstack Aug 24, 2023
2f702cf
Merge branch 'development' into feat/CS-39927
aman19K Aug 24, 2023
7902522
Merge pull request #987 from contentstack/feat/CS-39927
aman19K Aug 24, 2023
9b653d0
refactor: version bump
aman19K Aug 24, 2023
2e54fdb
fix: changed ^ to ~
abhinav-from-contentstack Aug 24, 2023
5e12e97
updated lock files and READMEs
abhinav-from-contentstack Aug 24, 2023
fe686de
Merge pull request #1002 from contentstack/refactor/CS-40857-version-…
abhinav-from-contentstack Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix: Update next available stages uid on workflow
antonyagustine committed Aug 18, 2023
commit e8484db3c77cde152036743c31386b35204c31a9
48 changes: 44 additions & 4 deletions packages/contentstack-import/src/import/modules-js/workflows.js
Original file line number Diff line number Diff line change
@@ -4,12 +4,13 @@
* MIT Licensed
*/

const mkdirp = require('mkdirp');
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const chalk = require('chalk');
const { isEmpty, merge } = require('lodash');
const mkdirp = require('mkdirp');
const Promise = require('bluebird');
const { isEmpty, merge, filter, map, cloneDeep, find } = require('lodash');

let { default: config } = require('../../config');
const { fileHelper, log, formatError } = require('../../utils');

@@ -58,6 +59,7 @@ module.exports = class importWorkflows {
if (!self.workflowUidMapper.hasOwnProperty(workflowUid)) {
const roleNameMap = {};
const workflowStages = workflow.workflow_stages;
const oldWorkflowStages = cloneDeep(workflow.workflow_stages);
const roles = await self.stackAPIClient.role().fetchAll();

for (const role of roles.items) {
@@ -67,6 +69,10 @@ module.exports = class importWorkflows {
for (const stage of workflowStages) {
delete stage.uid;

if (!isEmpty(stage.next_available_stages)) {
stage.next_available_stages = ['$all'];
}

if (stage.SYS_ACL.users.uids.length && stage.SYS_ACL.users.uids[0] !== '$all') {
stage.SYS_ACL.users.uids = ['$all'];
}
@@ -112,7 +118,20 @@ module.exports = class importWorkflows {
return self.stackAPIClient
.workflow()
.create({ workflow })
.then(function (response) {
.then(async function (response) {
if (
!isEmpty(filter(oldWorkflowStages, ({ next_available_stages }) => !isEmpty(next_available_stages)))
) {
let updateRresponse = await self
.updateNextAvailableStagesUid(response, response.workflow_stages, oldWorkflowStages)
.catch((error) => {
log(self.config, `Workflow '${workflow.name}' update failed.`, 'error');
log(self.config, error, 'error');
});

if (updateRresponse) response = updateRresponse;
}

self.workflowUidMapper[workflowUid] = response;
fileHelper.writeFileSync(workflowUidMapperPath, self.workflowUidMapper);
})
@@ -154,4 +173,25 @@ module.exports = class importWorkflows {
});
});
}

updateNextAvailableStagesUid(workflow, newWorkflowStages, oldWorkflowStages) {
newWorkflowStages = map(newWorkflowStages, (newStage, index) => {
const oldStage = oldWorkflowStages[index];
if (!isEmpty(oldStage.next_available_stages)) {
newStage.next_available_stages = map(oldStage.next_available_stages, (stageUid) => {
if (stageUid === '$all') return stageUid;
const stageName = find(oldWorkflowStages, { uid: stageUid })?.name;
return find(newWorkflowStages, { name: stageName })?.uid;
}).filter((val) => val);
}

return newStage;
});

workflow.workflow_stages = newWorkflowStages;

const updateWorkflow = this.stackAPIClient.workflow(workflow.uid);
Object.assign(updateWorkflow, workflow);
return updateWorkflow.update();
}
};
Original file line number Diff line number Diff line change
@@ -54,8 +54,8 @@ export type ApiOptions = {
url?: string;
entity: ApiModuleType;
apiData?: Record<any, any> | any;
resolve: (value: any) => void;
reject: (error: any) => void;
resolve: (value: any) => Promise<void> | void;
reject: (error: any) => Promise<void> | void;
additionalInfo?: Record<any, any>;
includeParamOnCompletion?: boolean;
serializeData?: (input: ApiOptions) => any;
64 changes: 56 additions & 8 deletions packages/contentstack-import/src/import/modules/workflows.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import chalk from 'chalk';
import isEmpty from 'lodash/isEmpty';
import values from 'lodash/values';
import map from 'lodash/map';
import find from 'lodash/find';
import { join } from 'node:path';
import values from 'lodash/values';
import filter from 'lodash/filter';
import isEmpty from 'lodash/isEmpty';
import cloneDeep from 'lodash/cloneDeep';
import findIndex from 'lodash/findIndex';
import { join, resolve } from 'node:path';

import config from '../../config';
import BaseClass, { ApiOptions } from './base-class';
@@ -47,7 +50,10 @@ export default class ImportWorkflows extends BaseClass {

//Step1 check folder exists or not
if (fileHelper.fileExistsSync(this.workflowsFolderPath)) {
this.workflows = fsUtil.readFile(join(this.workflowsFolderPath, this.workflowsConfig.fileName), true) as Record<string, unknown>;
this.workflows = fsUtil.readFile(join(this.workflowsFolderPath, this.workflowsConfig.fileName), true) as Record<
string,
unknown
>;
} else {
log(this.importConfig, `No such file or directory - '${this.workflowsFolderPath}'`, 'error');
return;
@@ -86,13 +92,14 @@ export default class ImportWorkflows extends BaseClass {
.then((data: any) => data)
.catch((err: any) => log(this.importConfig, `Failed to fetch roles. ${formatError(err)}`, 'error'));

for (const role of roles?.items) {
for (const role of roles?.items || []) {
this.roleNameMap[role.name] = role.uid;
}
}

async importWorkflows() {
const apiContent = values(this.workflows);
const oldWorkflows = cloneDeep(values(this.workflows));

//check and create custom roles if not exists
for (const workflow of values(this.workflows)) {
@@ -101,7 +108,21 @@ export default class ImportWorkflows extends BaseClass {
}
}

const onSuccess = ({ response, apiData: { uid, name } = { uid: null, name: '' } }: any) => {
const onSuccess = async ({ response, apiData: { uid, name } = { uid: null, name: '' } }: any) => {
const oldWorkflowStages = find(oldWorkflows, { uid })?.workflow_stages;
if (!isEmpty(filter(oldWorkflowStages, ({ next_available_stages }) => !isEmpty(next_available_stages)))) {
let updateRresponse = await this.updateNextAvailableStagesUid(
response,
response.workflow_stages,
oldWorkflowStages,
).catch((error) => {
log(this.importConfig, `Workflow '${name}' update failed.`, 'error');
log(this.importConfig, error, 'error');
});

if (updateRresponse) response = updateRresponse;
}

this.createdWorkflows.push(response);
this.workflowUidMapper[uid] = response.uid;
log(this.importConfig, `Workflow '${name}' imported successfully`, 'success');
@@ -145,6 +166,27 @@ export default class ImportWorkflows extends BaseClass {
);
}

updateNextAvailableStagesUid(workflow, newWorkflowStages, oldWorkflowStages) {
newWorkflowStages = map(newWorkflowStages, (newStage, index) => {
const oldStage = oldWorkflowStages[index];
if (!isEmpty(oldStage.next_available_stages)) {
newStage.next_available_stages = map(oldStage.next_available_stages, (stageUid) => {
if (stageUid === '$all') return stageUid;
const stageName = find(oldWorkflowStages, { uid: stageUid })?.name;
return find(newWorkflowStages, { name: stageName })?.uid;
}).filter((val) => val);
}

return newStage;
});

workflow.workflow_stages = newWorkflowStages;

const updateWorkflow = this.stack.workflow(workflow.uid);
Object.assign(updateWorkflow, workflow);
return updateWorkflow.update();
}

/**
* @method serializeWorkflows
* @param {ApiOptions} apiOptions ApiOptions
@@ -165,6 +207,14 @@ export default class ImportWorkflows extends BaseClass {
if (!workflow.branches) {
workflow.branches = ['main'];
}
for (const stage of workflow.workflow_stages) {
delete stage.uid;

if (!isEmpty(stage.next_available_stages)) {
stage.next_available_stages = ['$all'];
}
}

apiOptions.apiData = workflow;
}
return apiOptions;
@@ -184,8 +234,6 @@ export default class ImportWorkflows extends BaseClass {
const workflowStages = workflow.workflow_stages;
let stageIndex = 0;
for (const stage of workflowStages) {
delete stage.uid;

if (stage?.SYS_ACL?.users?.uids?.length && stage?.SYS_ACL?.users?.uids[0] !== '$all') {
stage.SYS_ACL.users.uids = ['$all'];
}