Skip to content

Commit

Permalink
sorting responses in requests
Browse files Browse the repository at this point in the history
  • Loading branch information
barduinor committed Sep 13, 2023
1 parent 762168e commit 64811ee
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
58 changes: 28 additions & 30 deletions src/DeployBulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,36 @@ const deployBulk = async (collectionId, localCollection) => {
'Content-Type': 'application/json',
'X-Api-Key': process.env.POSTMAN_API_KEY
}
}
).then(function () {
console.log('EMPTY COLLECTION PUT OK: ', localCollection.info.name)
// then publish the new collection
axios.put(
`https://api.getpostman.com/collections/${collectionId}`,
// JSON.stringify({ collection }),
{ collection: localCollection },
{
headers: {
'Content-Type': 'application/json',
'X-Api-Key': process.env.POSTMAN_API_KEY
}
}
).then(function () {
console.log('FULL COLLECTION PUT OK:', localCollection.info.name)
}
).catch(function (error) {
// console.dir(error.response, { depth: 100 })
})
.then(function () {
console.log('EMPTY COLLECTION PUT OK: ', localCollection.info.name)
// then publish the new collection
axios.put(
`https://api.getpostman.com/collections/${collectionId}`,
// JSON.stringify({ collection }),
{ collection: localCollection },
{
headers: {
'Content-Type': 'application/json',
'X-Api-Key': process.env.POSTMAN_API_KEY
}
})
.then(function () {
console.log('FULL COLLECTION PUT OK:', localCollection.info.name)
}
)
.catch(function (error) {
// console.dir(error.response, { depth: 100 })
logAxiosError(error)
// throw error
})
})
.catch(function (error) {
// console.dir(error.response, { depth: 100 })
logAxiosError(error)
// throw error
}
)
}
).catch(function (error) {
// console.dir(error.response, { depth: 100 })
logAxiosError(error)
// throw error
}
)
// throw error
})
}

function logAxiosError (error) {
if (error.response) {
// The request was made and the server responded with a status code
Expand Down
20 changes: 20 additions & 0 deletions src/DeployIncremental.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ async function mergeFolders (remoteCollection, localCollection) {
}
console.log(' Deploying Folders:')

let hasChanges = false

// create new folders
for (const folder of newFolders) {
const msg = ` Creating new folder [${folder.name}]`
Expand All @@ -55,6 +57,7 @@ async function mergeFolders (remoteCollection, localCollection) {
console.log(msg, '-> FAIL')
handlePostmanAPIError(error)
})
hasChanges = true
}

// delete old folders
Expand All @@ -67,6 +70,23 @@ async function mergeFolders (remoteCollection, localCollection) {
console.log(msg, '-> FAIL')
handlePostmanAPIError(error)
})
hasChanges = true
}

// sort folders
if (hasChanges) {
const tmpRootFolder = await new pmAPI.Folder(remoteCollection.collection.info.uid).create({ name: 'tmpRootFolder' })
// refresh remote collection
remoteCollection = await new pmAPI.Collection(remoteCollection.collection.info.uid).get()
// for each remote folder transfer them to the tmpRootFolder
for (const folder of remoteCollection.collection.item) {
await new pmAPI.Folder(remoteCollection.collection.info.uid)
.update(folder.id, { folder: tmpRootFolder.data.id })
.catch((error) => {
console.log(' Moving folder', folder.name, 'to tmpRootFolder -> FAIL')
handlePostmanAPIError(error)
})
}
}
}

Expand Down

0 comments on commit 64811ee

Please sign in to comment.