Skip to content

Commit

Permalink
WIP: added get workspace method
Browse files Browse the repository at this point in the history
  • Loading branch information
barduinor committed Sep 21, 2023
1 parent 27f29e2 commit 53b2ffc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/CollectionAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CollectionAdvanced extends Collection {
// TODO: Add proper description
const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, 'Utility scripts for Postman Collection')
folderCreateEnvironments.auth = this.authAPIKey()
folderCreateEnvironments.item.push(this.endPointGetWorkspaces(folderCreateEnvironments.id))
localCollection.item.splice(1, 0, folderCreateEnvironments)

// insert test environment into Utils folder
Expand Down Expand Up @@ -197,6 +198,34 @@ class CollectionAdvanced extends Collection {
script.script.id = Utils.GenID(hash) // RB: to big for uuidv5
return script
}

// utilities end points from JSON file

endPointGetWorkspaces (folderParentId) {
const endPoint = {
folder: folderParentId,
name: 'Get Workspaces',
description: "Gets all [workspaces](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/creating-workspaces/). The response includes your workspaces and any workspaces that you have access to.\n\n**Note:**\n\nThis endpoint's response contains the `visibility` field. [Visibility](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/managing-workspaces/#changing-workspace-visibility) determines who can access the workspace:\n\n- `personal` — Only you can access the workspace.\n- `team` — All team members can access the workspace.\n- `private` — Only invited team members can access the workspace ([Professional and Enterprise plans only](https://www.postman.com/pricing)).\n- `public` — Everyone can access the workspace.\n- `partner` — Only invited team members and [partners](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/partner-workspaces/) can access the workspace ([Enterprise Ultimate plans](https://www.postman.com/pricing) only).",
method: 'GET',
url: 'https://api.getpostman.com/workspaces',
queryParams: [
{
key: 'type',
value: '<string>',
description: 'The type of workspace to filter the response by:\n\n* `personal`\n* `team`\n* `private`\n* `public`\n* `partner`',
enabled: false
},
{
key: 'include',
value: '<string>',
description: "Include the following information in the endpoint's response:\n- `mocks:deactivated` — Include all deactivated mock servers in the response.",
enabled: false
}
]
}
endPoint.id = Utils.GenID(JSON.stringify(endPoint))
return endPoint
}
}

module.exports = CollectionAdvanced
18 changes: 16 additions & 2 deletions src/DeployIncremental.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const checkFolderSortChanges = (remoteCollection, localCollection) => {
const remoteFolders = remoteCollection.collection.item
.map(folder => ({ id: folder.id }))
const localFolders = localCollection.item
.filter(folder => !folder.folder)
.map(folder => ({ id: folder.id }))

const remoteFoldersHash = GenID(JSON.stringify(remoteFolders))
Expand Down Expand Up @@ -200,6 +201,8 @@ async function mergeFolders (remoteCollection, localCollection) {
const localFolders = localCollection.item

const newFolders = localFolders.filter(localFolder => !remoteFolders.find(remoteFolder => remoteFolder.id === localFolder.id))

// TODO: RB: need a method to return all remot folders independent where they are in the collection
const oldFolders = remoteFolders.filter(remoteFolder => !localFolders.find(localFolder => localFolder.id === remoteFolder.id))

let hasChanges = newFolders.length > 0 || oldFolders.length > 0
Expand Down Expand Up @@ -273,13 +276,18 @@ async function mergeRequests (remoteCollection, localCollection) {
//
// 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)))
let 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) {
// try locating inside the first level items
remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.item.id === localFolder.item.id)))
}

if (!remoteRemoteFolder) {
continue
}
Expand Down Expand Up @@ -308,7 +316,13 @@ async function mergeRequests (remoteCollection, localCollection) {

// create new requests
for (const request of newRequests) {
const pmRequest = pmConvert.requestFromLocal(request)
// check request format and convert if necessary
let pmRequest = null
if (!request.request) { // => Postman Format
pmRequest = request
} else { // => OpenAPI Format
pmRequest = pmConvert.requestFromLocal(request)
}
const msg = ` Creating new request [${request.name}]`

await new pmAPI.Request(remoteCollection.collection.info.uid)
Expand Down

0 comments on commit 53b2ffc

Please sign in to comment.