Skip to content

Commit

Permalink
WIP: implemented deploymen of utilities folder and sub folders
Browse files Browse the repository at this point in the history
  • Loading branch information
barduinor committed Sep 21, 2023
1 parent 8aebea8 commit c2c4277
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,13 @@ class Collection {
}

// create a folder object
createFolder (folderName) {
createFolder (folderName, folderParentId = null, description = null) {
const folder = {
name: folderName,
folder: folderParentId,
description: description,
item: []

}
const folderId = Utils.GenID(JSON.stringify(folder))
folder.id = folderId
Expand Down
27 changes: 26 additions & 1 deletion src/CollectionAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,42 @@ class CollectionAdvanced extends Collection {
*/
// RB: override
process () {
return {
const localCollection = {
info: this.getInfo(),
item: this.getItems(),
event: [this.collectionPreRequest()],
variable: this.getVariables(),
auth: this.defaultAuth()
}

// RB: inject utilities
this.injectUtilities(localCollection)

return localCollection
}

// PRIVATE

injectUtilities (localCollection) {
// insert Utils folder at top level item
const folderUtilities = this.createFolder('(Utilities)', null, 'Utility scripts for Postman Collection')
localCollection.item.unshift(folderUtilities)

// insert create environment into Utils folder
const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, 'Utility scripts for Postman Collection')
localCollection.item.splice(1, 0, folderCreateEnvironments)

// insert test environment into Utils folder
const folderTestEnvironments = this.createFolder('Test Environments', folderUtilities.id, 'Utility scripts for Postman Collection')
localCollection.item.splice(2, 0, folderTestEnvironments)

// insert Authorixe OAuth Box App Helper into Utils folder
const folderAuthorizeOAuthBoxAppHelper = this.createFolder('Authorize OAuth Box App Helper', folderUtilities.id, 'Utility scripts for Postman Collection')
localCollection.item.splice(3, 0, folderAuthorizeOAuthBoxAppHelper)

return localCollection
}

authForEndPoint (endpoint) {
// RB: All endpoints inherit from the collection
return null
Expand Down
2 changes: 1 addition & 1 deletion src/CollectionAdvancedUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Utils = require('./Utils')

const injectUtils = (localCollection) => {
// insert Utils folder at top level item
localCollection.item.unshift(genFolder('(Utils)', 'Utility scripts for Postman Collection'))
localCollection.item.unshift(genFolder('(Utilities)', 'Utility scripts for Postman Collection'))

return localCollection
}
Expand Down
60 changes: 50 additions & 10 deletions src/DeployIncremental.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@

const pmConvert = require('./PostmanCovertions')
const pmAPI = require('./postmanAPI')
const injectUtils = require('./CollectionAdvancedUtils').injectUtils
const { GenID } = require('./Utils')

const deployIncremental = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId, withUtils = true) => {
// inject extra Postman objects
if (withUtils) {
localCollection = injectUtils(localCollection)
}

const deployIncremental = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId) => {
let remoteCollection = await refreshRemoteCollection(privateRemoteCollectionId)

console.log('Incremental deployment of collection ', localCollection.info.name)
Expand Down Expand Up @@ -273,10 +267,34 @@ async function mergeRequests (remoteCollection, localCollection) {

// loop folders
for (const localFolder of localFoldersRequest) {
const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item
// original code
// const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item
// const localRequests = localFolder.item
//
// need to handle the case where the folder is empty
// in that case the item property is undefined
const remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id)))

// subfolders exist in the local collection as root folders
// but in the remote collection they are in the parent folder
// so we need to handle the case where the subfolder
// exists as a root element in the local collection
// but not in the remote collection
if (!remoteRemoteFolder) {
continue
}

// handle undifined items
remoteRemoteFolder.item = remoteRemoteFolder.item || []

// filter out anything that is not a request
remoteRemoteFolder.item = remoteRemoteFolder.item.filter(request => request.request)

const remoteRequests = remoteRemoteFolder.item

const localRequests = localFolder.item

// create new requests
// Identify old and new requests
const newRequests = localRequests.filter(localRequest => !remoteRequests.find(remoteRequest => remoteRequest.id === localRequest.id))
const oldRequests = remoteRequests.filter(remoteRequest => !localRequests.find(localRequest => localRequest.id === remoteRequest.id))

Expand Down Expand Up @@ -350,8 +368,30 @@ async function mergeResponses (remoteCollection, localCollection) {
let anyResponseHasChanged = false
// loop folders
for (const localFolder of localFoldersRequest) {
const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item
// const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item
// need to handle the case where the folder is empty
// in that case the item property is undefined
const remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id)))

// subfolders exist in the local collection as root folders
// but in the remote collection they are in the parent folder
// so we need to handle the case where the subfolder
// exists as a root element in the local collection
// but not in the remote collection
if (!remoteRemoteFolder) {
continue
}

// handle undifined items
remoteRemoteFolder.item = remoteRemoteFolder.item || []

// filter out anything that is not a request
remoteRemoteFolder.item = remoteRemoteFolder.item.filter(request => request.request)

const remoteRequests = remoteRemoteFolder.item

const localRequests = localFolder.item

console.log(' In Folder: ', localFolder.name)
// loop requests
for (const localRequest of localRequests) {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/releaseAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const release = async (locale = process.argv[1]) => {
const localCollection = JSON.parse(fs.readFileSync(`${OUTPUT_FOLDER}/collection.advanced.${locale}.json`).toString())
const privateRemoteCollectionId = process.env[`PRIVATE_${locale.toUpperCase()}_POSTMAN_COLLECTION_ADVANCED_ID`]
const publicRemoteCollectionId = process.env[`PUBLIC_${locale.toUpperCase()}_POSTMAN_COLLECTION_ADVANCED_ID`]
await deployIncremental(privateRemoteCollectionId, localCollection, publicRemoteCollectionId, false)
await deployIncremental(privateRemoteCollectionId, localCollection, publicRemoteCollectionId)
}

const releaseAll = async () => {
Expand Down

0 comments on commit c2c4277

Please sign in to comment.