Moving to path instead

This commit is contained in:
Julien Lengrand-Lambert
2023-03-09 17:12:03 +01:00
parent a5572e49cd
commit 0206814206
5 changed files with 25 additions and 33 deletions

View File

@@ -10,15 +10,10 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
fetch-depth: 2 fetch-depth: 2
- name: Get changed files in the test folder
id: changed-files-specific
uses: tj-actions/changed-files@v35
with:
files: samples/*.yml
- name: push-adyen-collections-to-postman-javascript-action - name: push-adyen-collections-to-postman-javascript-action
id: process id: process
uses: jlengrand/push-adyen-collections-to-postman-javascript-action@main uses: jlengrand/push-adyen-collections-to-postman-javascript-action@main
with: with:
postman-key: ${{ secrets.POSTMAN_API_KEY }} postman-key: ${{ secrets.POSTMAN_API_KEY }}
workspace-id: ${{ secrets.POSTMAN_WORKSPACE_ID }} workspace-id: ${{ secrets.POSTMAN_WORKSPACE_ID }}
files-changed: ${{ steps.changed-files-specific.outputs.all_changed_files }} path-to-process: samples/*.yml

View File

@@ -7,8 +7,8 @@ inputs:
workspace-id: workspace-id:
description: 'Postman Workspace ID' description: 'Postman Workspace ID'
required: true required: true
files-changed: path-to-process:
description: 'Files changed' description: 'Path to process'
required: true required: true
runs: runs:
using: 'node16' using: 'node16'

22
dist/index.js vendored
View File

@@ -2996,9 +2996,9 @@ function getNameOfApi(filepath){
* @returns {Promise<Array.<string>>} a promise containing a list of filenames with the given extension * @returns {Promise<Array.<string>>} a promise containing a list of filenames with the given extension
*/ */
async function getFilesInFolder(filepath, extension){ async function getFilesInFolder(filepath, extension){
return fs.promises.readdir(filepath).then((files) => { return external_fs_.promises.readdir(filepath).then((files) => {
return files.filter((file) => { return files.filter((file) => {
return path.extname(file) === extension; return external_path_.extname(file) === extension;
}); });
}); });
} }
@@ -3087,21 +3087,23 @@ function _groupBy(xs, key) {
async function run() { async function run() {
try { try {
const postmanApiKey = core.getInput('postman-key'); const postmanApiKey = core.getInput('postman-key');
const filesChanged = core.getInput('files-changed'); const pathToProcess = core.getInput('path-to-process');
const workspaceId = core.getInput('workspace-id'); const workspaceId = core.getInput('workspace-id');
const time = runParameters(postmanApiKey, workspaceId, filesChanged); runParameters(postmanApiKey, workspaceId, pathToProcess);
core.setOutput("time", time);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }
} }
async function runParameters(postmanApiKey, workspaceId, filesToProcess){ async function runParameters(postmanApiKey, workspaceId, pathToProcess){
const filesToProcessAsList = await getFilesInFolder(pathToProcess, ".json");
const apiFilesWithPath = filesToProcessAsList.map((file) => { return `${pathToProcess}/${file}`; });
console.log(`Path to process : ${pathToProcess}`);
console.log(`Files to process : ${apiFilesWithPath}`);
console.log(`Files to process : ${filesToProcess}`);
console.log(`Getting workspace ${workspaceId}!`); console.log(`Getting workspace ${workspaceId}!`);
console.log("-----"); console.log("-----");
@@ -3110,12 +3112,10 @@ async function runParameters(postmanApiKey, workspaceId, filesToProcess){
console.log(JSON.stringify(workspace)); console.log(JSON.stringify(workspace));
console.log("-----"); console.log("-----");
const collections = workspace.workspace.collections; const collections = workspace.workspace.collections;
const filesToProcessAsList = filesToProcess.split(' '); const apisToProcess = filenamesToSet(apiFilesWithPath);
const apisToProcess = filenamesToSet(filesToProcessAsList);
const apisToProcessStructures = apisToProcess.map((api) => { const apisToProcessStructures = apisToProcess.map((api) => {
console.log(`Processing ${api}`); console.log(`Processing ${api}`);

View File

@@ -5,21 +5,23 @@ import * as utils from "./utils.js";
async function run() { async function run() {
try { try {
const postmanApiKey = core.getInput('postman-key'); const postmanApiKey = core.getInput('postman-key');
const filesChanged = core.getInput('files-changed'); const pathToProcess = core.getInput('path-to-process');
const workspaceId = core.getInput('workspace-id'); const workspaceId = core.getInput('workspace-id');
const time = runParameters(postmanApiKey, workspaceId, filesChanged); runParameters(postmanApiKey, workspaceId, pathToProcess);
core.setOutput("time", time);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }
} }
export async function runParameters(postmanApiKey, workspaceId, filesToProcess){ export async function runParameters(postmanApiKey, workspaceId, pathToProcess){
const filesToProcessAsList = await utils.getFilesInFolder(pathToProcess, ".json");
const apiFilesWithPath = filesToProcessAsList.map((file) => { return `${pathToProcess}/${file}`; });
console.log(`Path to process : ${pathToProcess}`);
console.log(`Files to process : ${apiFilesWithPath}`);
console.log(`Files to process : ${filesToProcess}`);
console.log(`Getting workspace ${workspaceId}!`); console.log(`Getting workspace ${workspaceId}!`);
console.log("-----"); console.log("-----");
@@ -28,12 +30,10 @@ export async function runParameters(postmanApiKey, workspaceId, filesToProcess){
console.log(JSON.stringify(workspace)); console.log(JSON.stringify(workspace));
console.log("-----"); console.log("-----");
const collections = workspace.workspace.collections; const collections = workspace.workspace.collections;
const filesToProcessAsList = filesToProcess.split(' '); const apisToProcess = utils.filenamesToSet(apiFilesWithPath);
const apisToProcess = utils.filenamesToSet(filesToProcessAsList);
const apisToProcessStructures = apisToProcess.map((api) => { const apisToProcessStructures = apisToProcess.map((api) => {
console.log(`Processing ${api}`); console.log(`Processing ${api}`);

View File

@@ -13,15 +13,12 @@ dotenv.config();
* @param {string} path the path to the folder containing the API files to process * @param {string} path the path to the folder containing the API files to process
* @returns {Promise<void>} a promise that resolves when the function is done * @returns {Promise<void>} a promise that resolves when the function is done
*/ */
async function localRun(path) { async function localRun(pathToProcess) {
const apiFiles = await utils.getFilesInFolder(path, ".json");
const apiFilesWithPath = apiFiles.map((file) => { return `${path}/${file}`; });
const apiFilesWithPathAsString = apiFilesWithPath.join(" ");
const POSTMAN_API_KEY = process.env.POSTMAN_API_KEY; const POSTMAN_API_KEY = process.env.POSTMAN_API_KEY;
const POSTMAN_WORKSPACE_ID = process.env.POSTMAN_WORKSPACE_ID; const POSTMAN_WORKSPACE_ID = process.env.POSTMAN_WORKSPACE_ID;
runParameters(POSTMAN_API_KEY, POSTMAN_WORKSPACE_ID, apiFilesWithPathAsString); await runParameters(POSTMAN_API_KEY, POSTMAN_WORKSPACE_ID, pathToProcess);
} }
localRun("../adyen-postman/postman/") localRun("../adyen-postman/postman/")