diff --git a/CHANGELOG.md b/CHANGELOG.md index b9dbc4f..77238ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,4 @@ - basic image generation based on the while definition file - repository list generation +- exclude functionallity diff --git a/README.md b/README.md index 2fdbbff..89d6245 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,26 @@ It's a tool either to be used as a javascript library, a CLI or a github actions > **_Note:_** It make sense in case this is part of a flow where the files are either archived or stored as a new push to the repository/pull request. +- **exclude** (optional): The list of projects or branches to exclude from project-list generation. For instance: + + > ``` + > exclude: groupx/projectx # it will exclude groupx/projectx from the list + > exclude: | # it will exclude groupx/projectx, groupx/projecty and all the projects where the mapping is master:7.x + > groupx/projectx + > groupx/projecty + > @master:7.x + > ``` + +- **include** (optional): The list of projects or branches to include from project-list generation. For instance: + + > ``` + > include: groupx/projectx # it will include groupx/projectx from the list + > include: | # it will include groupx/projectx, groupx/projecty and all the projects where the mapping is master:7.x + > groupx/projectx + > groupx/projecty + > @master:7.x + > ``` + - **font** (optional): The font size and name to produce the image. For instance: > ``` @@ -53,20 +73,25 @@ It's a tool either to be used as a javascript library, a CLI or a github actions ### Generate Image -Check this example: `build-chain-files-generator -df https://raw.githubusercontent.com/kiegroup/droolsjbpm-build-bootstrap/master/.ci/pull-request-config.yaml -o image.png image` +Check this example: `build-chain-files-generator -df https://raw.githubusercontent.com/kiegroup/droolsjbpm-build-bootstrap/master/.ci/pull-request-config.yaml -o image.png image -font "14px Arial"` where: - `-df`: is the definition file - `-o`: the file path to store the file - `image`: the file type to generate +- `-font` (optional): the font to use ### Generate Repository list file -Check this example: `build-chain-files-generator -df ./pull-request-config.yaml -o file.txt repository-list` +Check this example: + +> `build-chain-files-generator -df ./pull-request-config.yaml -o file.txt repository-list -exclude "groupx/projectX" "@master:main"` > `build-chain-files-generator -df ./pull-request-config.yaml -o file.txt repository-list -include "groupx/projectY" "@main:master"` where: - `-df`: is the definition file - `-o`: the file path to store the file - `image`: the file type to generate +- `-exclude` (optional): the project list or mapping to exclude +- `-include` (optional): the project list or mapping to include diff --git a/action.yml b/action.yml index ff5f16c..5e0679b 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,12 @@ inputs: description: "the font used to generate image, something like `14px Arial`" default: "12px IBM Plex Sans Condensed 2" required: false + exclude: + description: "The list of projects or branches to exclude" + required: false + include: + description: "The list of projects or branches to include" + required: false runs: using: "node12" main: "dist/index.js" diff --git a/bin/arguments/image-arguments.js b/bin/arguments/image-arguments.js index 454456b..662a723 100644 --- a/bin/arguments/image-arguments.js +++ b/bin/arguments/image-arguments.js @@ -3,7 +3,6 @@ function getArguments(subParser) { help: "image generation" }); buildParser.add_argument("-font", { - metavar: "", nargs: 1, required: false, help: diff --git a/bin/arguments/repository-list-arguments.js b/bin/arguments/repository-list-arguments.js index dbb130b..4c4b26e 100644 --- a/bin/arguments/repository-list-arguments.js +++ b/bin/arguments/repository-list-arguments.js @@ -1,7 +1,21 @@ function getArguments(subParser) { - subParser.add_parser("repository-list", { + const buildParser = subParser.add_parser("repository-list", { help: "repository list file generation" }); + + buildParser.add_argument("-exclude", { + nargs: "*", + required: false, + help: + "The list of projects or branches to exclude from project-list generation." + }); + + buildParser.add_argument("-include", { + nargs: "*", + required: false, + help: + "The list of projects or branches to include from project-list generation." + }); } module.exports = { getArguments }; diff --git a/bin/flows/project-list-flow.js b/bin/flows/project-list-flow.js index 789ba44..26e9a32 100644 --- a/bin/flows/project-list-flow.js +++ b/bin/flows/project-list-flow.js @@ -7,15 +7,22 @@ const { const fs = require("fs"); const path = require("path"); -async function generateRepositoryList(definitionFile, outputFilePath) { +async function generateRepositoryList( + definitionFile, + outputFilePath, + options = {} +) { logger.info(`Generating repository list file for ${definitionFile}`); - const orderedList = (await getOrderedListForTree(definitionFile)).map( - e => e.project - ); + const orderedList = (await getOrderedListForTree(definitionFile)) + .filter(node => isIncluded(node, options.include)) + .filter(node => !isExcluded(node, options.exclude)) + .map(e => e.project); const content = orderedList + .map(project => (project ? project.split("/")[1] : project)) .reduce((acc, project) => acc.concat(`${project}\n`), ""); - logger.info(content); + logger.info(` +${content}`); createFileContainer(outputFilePath); fs.writeFileSync(outputFilePath, content); logger.info( @@ -26,4 +33,30 @@ async function generateRepositoryList(definitionFile, outputFilePath) { ); } +function isIncluded(node, include) { + if (include) { + return ( + include.includes(node.project) || + (node.mapping !== undefined && + node.mapping.source !== undefined && + node.mapping.target !== undefined && + include.includes(`@${node.mapping.source}:${node.mapping.target}`)) + ); + } + return true; +} + +function isExcluded(node, exclude) { + if (exclude) { + return ( + exclude.includes(node.project) || + (node.mapping !== undefined && + node.mapping.source !== undefined && + node.mapping.target !== undefined && + exclude.includes(`@${node.mapping.source}:${node.mapping.target}`)) + ); + } + return false; +} + module.exports = { generateRepositoryList }; diff --git a/bin/generator-cli.js b/bin/generator-cli.js index 22aeca3..a6932eb 100755 --- a/bin/generator-cli.js +++ b/bin/generator-cli.js @@ -23,7 +23,10 @@ async function main() { ); } if (args["file-type"] === "repository-list") { - await generateRepositoryList(args.df[0], args.o[0]); + await generateRepositoryList(args.df[0], args.o[0], { + exclude: args.exclude, + include: args.include + }); } } diff --git a/bin/generator-event.js b/bin/generator-event.js index a43a553..4b25729 100755 --- a/bin/generator-event.js +++ b/bin/generator-event.js @@ -7,6 +7,8 @@ const { getDefinitionFile, getFileType, getOutputFilePath, + getExclude, + getInclude, getFont } = require("./utils/action-utils"); require("dotenv").config(); @@ -15,7 +17,10 @@ async function main() { if (getFileType() === "image") { await generateImage(getDefinitionFile(), getOutputFilePath(), getFont()); } else if (getFileType() === "repository-list") { - await generateRepositoryList(getDefinitionFile(), getOutputFilePath()); + await generateRepositoryList(getDefinitionFile(), getOutputFilePath(), { + exclude: getExclude(), + include: getInclude() + }); } else { throw new Error( `file type input value '${getFileType()}' is not supported. Please check documentation.` diff --git a/bin/utils/action-utils.js b/bin/utils/action-utils.js index 8265417..8e02503 100644 --- a/bin/utils/action-utils.js +++ b/bin/utils/action-utils.js @@ -12,6 +12,16 @@ function getOutputFilePath() { return core.getInput("output-file-path"); } +function getExclude() { + const input = core.getInput("exclude"); + return !input || Array.isArray(input) ? input : [input]; +} + +function getInclude() { + const input = core.getInput("include"); + return !input || Array.isArray(input) ? input : [input]; +} + function getFont() { return core.getInput("font"); } @@ -20,5 +30,7 @@ module.exports = { getDefinitionFile, getFileType, getOutputFilePath, + getExclude, + getInclude, getFont }; diff --git a/dist/index.js b/dist/index.js index 37104d8..60deb07 100755 --- a/dist/index.js +++ b/dist/index.js @@ -5152,6 +5152,8 @@ const { getDefinitionFile, getFileType, getOutputFilePath, + getExclude, + getInclude, getFont } = __webpack_require__(755); __webpack_require__(63).config(); @@ -5160,7 +5162,10 @@ async function main() { if (getFileType() === "image") { await generateImage(getDefinitionFile(), getOutputFilePath(), getFont()); } else if (getFileType() === "repository-list") { - await generateRepositoryList(getDefinitionFile(), getOutputFilePath()); + await generateRepositoryList(getDefinitionFile(), getOutputFilePath(), { + exclude: getExclude(), + include: getInclude() + }); } else { throw new Error( `file type input value '${getFileType()}' is not supported. Please check documentation.` @@ -6333,6 +6338,16 @@ function getOutputFilePath() { return core.getInput("output-file-path"); } +function getExclude() { + const input = core.getInput("exclude"); + return !input || Array.isArray(input) ? input : [input]; +} + +function getInclude() { + const input = core.getInput("include"); + return !input || Array.isArray(input) ? input : [input]; +} + function getFont() { return core.getInput("font"); } @@ -6341,6 +6356,8 @@ module.exports = { getDefinitionFile, getFileType, getOutputFilePath, + getExclude, + getInclude, getFont }; @@ -7025,15 +7042,22 @@ const { const fs = __webpack_require__(747); const path = __webpack_require__(622); -async function generateRepositoryList(definitionFile, outputFilePath) { +async function generateRepositoryList( + definitionFile, + outputFilePath, + options = {} +) { logger.info(`Generating repository list file for ${definitionFile}`); - const orderedList = (await getOrderedListForTree(definitionFile)).map( - e => e.project - ); + const orderedList = (await getOrderedListForTree(definitionFile)) + .filter(node => isIncluded(node, options.include)) + .filter(node => !isExcluded(node, options.exclude)) + .map(e => e.project); const content = orderedList + .map(project => (project ? project.split("/")[1] : project)) .reduce((acc, project) => acc.concat(`${project}\n`), ""); - logger.info(content); + logger.info(` +${content}`); createFileContainer(outputFilePath); fs.writeFileSync(outputFilePath, content); logger.info( @@ -7044,6 +7068,32 @@ async function generateRepositoryList(definitionFile, outputFilePath) { ); } +function isIncluded(node, include) { + if (include) { + return ( + include.includes(node.project) || + (node.mapping !== undefined && + node.mapping.source !== undefined && + node.mapping.target !== undefined && + include.includes(`@${node.mapping.source}:${node.mapping.target}`)) + ); + } + return true; +} + +function isExcluded(node, exclude) { + if (exclude) { + return ( + exclude.includes(node.project) || + (node.mapping !== undefined && + node.mapping.source !== undefined && + node.mapping.target !== undefined && + exclude.includes(`@${node.mapping.source}:${node.mapping.target}`)) + ); + } + return false; +} + module.exports = { generateRepositoryList }; @@ -7052,7 +7102,7 @@ module.exports = { generateRepositoryList }; /***/ 896: /***/ (function(module) { -module.exports = {"_args":[["canvas@2.6.1","/home/emingora/development/projects/RedHat/issues/BXMSPROD-1044/build-chain-files-generator"]],"_from":"canvas@2.6.1","_id":"canvas@2.6.1","_inBundle":false,"_integrity":"sha512-S98rKsPcuhfTcYbtF53UIJhcbgIAK533d1kJKMwsMwAIFgfd58MOyxRud3kktlzWiEkFliaJtvyZCBtud/XVEA==","_location":"/canvas","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"canvas@2.6.1","name":"canvas","escapedName":"canvas","rawSpec":"2.6.1","saveSpec":null,"fetchSpec":"2.6.1"},"_requiredBy":["/tree-image-drawer"],"_resolved":"https://registry.npmjs.org/canvas/-/canvas-2.6.1.tgz","_spec":"2.6.1","_where":"/home/emingora/development/projects/RedHat/issues/BXMSPROD-1044/build-chain-files-generator","author":{"name":"TJ Holowaychuk","email":"tj@learnboost.com"},"binary":{"module_name":"canvas","module_path":"build/Release","host":"https://github.com/node-gfx/node-canvas-prebuilt/releases/download/","remote_path":"v{version}","package_name":"{module_name}-v{version}-{node_abi}-{platform}-{libc}-{arch}.tar.gz"},"browser":"browser.js","bugs":{"url":"https://github.com/Automattic/node-canvas/issues"},"contributors":[{"name":"Nathan Rajlich","email":"nathan@tootallnate.net"},{"name":"Rod Vagg","email":"r@va.gg"},{"name":"Juriy Zaytsev","email":"kangax@gmail.com"}],"dependencies":{"nan":"^2.14.0","node-pre-gyp":"^0.11.0","simple-get":"^3.0.3"},"description":"Canvas graphics API backed by Cairo","devDependencies":{"@types/node":"^10.12.18","assert-rejects":"^1.0.0","dtslint":"^0.5.3","express":"^4.16.3","mocha":"^5.2.0","pixelmatch":"^4.0.2","standard":"^12.0.1"},"engines":{"node":">=6"},"files":["binding.gyp","lib/","src/","util/","types/index.d.ts"],"homepage":"https://github.com/Automattic/node-canvas","keywords":["canvas","graphic","graphics","pixman","cairo","image","images","pdf"],"license":"MIT","main":"index.js","name":"canvas","repository":{"type":"git","url":"git://github.com/Automattic/node-canvas.git"},"scripts":{"benchmark":"node benchmarks/run.js","dtslint":"dtslint types","install":"node-pre-gyp install --fallback-to-build","prebenchmark":"node-gyp build","pretest":"standard examples/*.js test/server.js test/public/*.js benchmarks/run.js lib/context2d.js util/has_lib.js browser.js index.js && node-gyp build","pretest-server":"node-gyp build","test":"mocha test/*.test.js","test-server":"node test/server.js"},"types":"types/index.d.ts","version":"2.6.1"}; +module.exports = {"name":"canvas","description":"Canvas graphics API backed by Cairo","version":"2.6.1","author":"TJ Holowaychuk ","main":"index.js","browser":"browser.js","contributors":["Nathan Rajlich ","Rod Vagg ","Juriy Zaytsev "],"keywords":["canvas","graphic","graphics","pixman","cairo","image","images","pdf"],"homepage":"https://github.com/Automattic/node-canvas","repository":"git://github.com/Automattic/node-canvas.git","scripts":{"prebenchmark":"node-gyp build","benchmark":"node benchmarks/run.js","pretest":"standard examples/*.js test/server.js test/public/*.js benchmarks/run.js lib/context2d.js util/has_lib.js browser.js index.js && node-gyp build","test":"mocha test/*.test.js","pretest-server":"node-gyp build","test-server":"node test/server.js","install":"node-pre-gyp install --fallback-to-build","dtslint":"dtslint types"},"binary":{"module_name":"canvas","module_path":"build/Release","host":"https://github.com/node-gfx/node-canvas-prebuilt/releases/download/","remote_path":"v{version}","package_name":"{module_name}-v{version}-{node_abi}-{platform}-{libc}-{arch}.tar.gz"},"files":["binding.gyp","lib/","src/","util/","types/index.d.ts"],"types":"types/index.d.ts","dependencies":{"nan":"^2.14.0","node-pre-gyp":"^0.11.0","simple-get":"^3.0.3"},"devDependencies":{"@types/node":"^10.12.18","assert-rejects":"^1.0.0","dtslint":"^0.5.3","express":"^4.16.3","mocha":"^5.2.0","pixelmatch":"^4.0.2","standard":"^12.0.1"},"engines":{"node":">=6"},"license":"MIT","_resolved":"https://registry.npmjs.org/canvas/-/canvas-2.6.1.tgz","_integrity":"sha512-S98rKsPcuhfTcYbtF53UIJhcbgIAK533d1kJKMwsMwAIFgfd58MOyxRud3kktlzWiEkFliaJtvyZCBtud/XVEA==","_from":"canvas@2.6.1"}; /***/ }), diff --git a/test/bin/flows/project-list-flow.test.js b/test/bin/flows/project-list-flow.test.js index e8c3c6b..ab5db42 100644 --- a/test/bin/flows/project-list-flow.test.js +++ b/test/bin/flows/project-list-flow.test.js @@ -13,6 +13,10 @@ jest.mock("fs"); const { createFileContainer } = require("../../../src/lib/util/fs-util"); jest.mock("../../../src/lib/util/fs-util"); +afterEach(() => { + jest.clearAllMocks(); +}); + test("generateRepositoryList", async () => { // Arrange const definitionFile = "definitionFile"; @@ -47,3 +51,443 @@ projectD ` ); }); + +test("generateRepositoryList exclude project list", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA" + }, + { + project: "groupx/projectB" + }, + { + project: "groupx/projectC" + }, + { + project: "groupx/projectD" + } + ]; + const exclude = ["groupx/projectB", "groupx/projectD"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { exclude }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectA +projectC +` + ); +}); + +test("generateRepositoryList exclude project mapping without coincidenes", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA" + }, + { + project: "groupx/projectB" + }, + { + project: "groupx/projectC" + }, + { + project: "groupx/projectD" + } + ]; + const exclude = ["@master:7.x"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { exclude }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectA +projectB +projectC +projectD +` + ); +}); + +test("generateRepositoryList exclude project mapping wit coincidenes", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA", + mapping: { + source: "master", + target: "7.x" + } + }, + { + project: "groupx/projectB", + mapping: { + source: "7.x", + target: "master" + } + }, + { + project: "groupx/projectC", + mapping: { + source: "master", + target: "master" + } + }, + { + project: "groupx/projectD", + mapping: { + source: "7.x", + target: "7.x" + } + }, + { + project: "groupx/projectE" + }, + { + project: "groupx/projectF", + mapping: { + source: "master", + target: "7.x" + } + } + ]; + const exclude = ["@master:7.x"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { exclude }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectB +projectC +projectD +projectE +` + ); +}); + +test("generateRepositoryList exclude project list and mapping wit coincidenes", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA", + mapping: { + source: "master", + target: "7.x" + } + }, + { + project: "groupx/projectB", + mapping: { + source: "7.x", + target: "master" + } + }, + { + project: "groupx/projectC", + mapping: { + source: "master", + target: "master" + } + }, + { + project: "groupx/projectD", + mapping: { + source: "7.x", + target: "7.x" + } + }, + { + project: "groupx/projectE" + }, + { + project: "groupx/projectF", + mapping: { + source: "master", + target: "7.x" + } + } + ]; + const exclude = ["groupx/projectB", "groupx/projectF", "@master:7.x"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { exclude }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectC +projectD +projectE +` + ); +}); + +test("generateRepositoryList include project list", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA" + }, + { + project: "groupx/projectB" + }, + { + project: "groupx/projectC" + }, + { + project: "groupx/projectD" + } + ]; + const include = ["groupx/projectB", "groupx/projectD"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { include }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectB +projectD +` + ); +}); + +test("generateRepositoryList include project mapping without coincidenes", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA" + }, + { + project: "groupx/projectB" + }, + { + project: "groupx/projectC" + }, + { + project: "groupx/projectD" + } + ]; + const include = ["@master:7.x"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { include }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith(outputFilePath, ""); +}); + +test("generateRepositoryList include project mapping wit coincidenes", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA", + mapping: { + source: "master", + target: "7.x" + } + }, + { + project: "groupx/projectB", + mapping: { + source: "7.x", + target: "master" + } + }, + { + project: "groupx/projectC", + mapping: { + source: "master", + target: "master" + } + }, + { + project: "groupx/projectD", + mapping: { + source: "7.x", + target: "7.x" + } + }, + { + project: "groupx/projectE" + }, + { + project: "groupx/projectF", + mapping: { + source: "master", + target: "7.x" + } + } + ]; + const include = ["@master:7.x"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { include }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectA +projectF +` + ); +}); + +test("generateRepositoryList include project list and mapping wit coincidenes", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA", + mapping: { + source: "master", + target: "7.x" + } + }, + { + project: "groupx/projectB", + mapping: { + source: "7.x", + target: "master" + } + }, + { + project: "groupx/projectC", + mapping: { + source: "master", + target: "master" + } + }, + { + project: "groupx/projectD", + mapping: { + source: "7.x", + target: "7.x" + } + }, + { + project: "groupx/projectE" + }, + { + project: "groupx/projectF", + mapping: { + source: "master", + target: "7.x" + } + } + ]; + const include = ["groupx/projectB", "groupx/projectF", "@master:7.x"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { include }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectA +projectB +projectF +` + ); +}); + +test("generateRepositoryList include and exclude", async () => { + // Arrange + const definitionFile = "definitionFile"; + const outputFilePath = "outputFilePath"; + const tree = [ + { + project: "groupx/projectA", + mapping: { + source: "master", + target: "7.x" + } + }, + { + project: "groupx/projectB", + mapping: { + source: "7.x", + target: "master" + } + }, + { + project: "groupx/projectC", + mapping: { + source: "master", + target: "master" + } + }, + { + project: "groupx/projectD", + mapping: { + source: "7.x", + target: "7.x" + } + }, + { + project: "groupx/projectE" + }, + { + project: "groupx/projectF", + mapping: { + source: "master", + target: "7.x" + } + } + ]; + const include = ["groupx/projectB", "groupx/projectE", "groupx/projectF"]; + const exclude = ["groupx/projectB", "@master:7.x"]; + getOrderedListForTree.mockResolvedValueOnce(tree); + + // Act + await generateRepositoryList(definitionFile, outputFilePath, { + include, + exclude + }); + + // Assert + expect(createFileContainer).toHaveBeenCalledWith(outputFilePath); + expect(writeFileSync).toHaveBeenCalledWith( + outputFilePath, + `projectE +` + ); +}); diff --git a/test/bin/utils/action-utils.test.js b/test/bin/utils/action-utils.test.js index 8a2fbcd..d64e318 100644 --- a/test/bin/utils/action-utils.test.js +++ b/test/bin/utils/action-utils.test.js @@ -2,6 +2,8 @@ const { getDefinitionFile, getFileType, getOutputFilePath, + getExclude, + getInclude, getFont } = require("../../../bin/utils/action-utils"); @@ -51,6 +53,78 @@ test("getOutputFilePath", () => { expect(result).toEqual(expectedResult); }); +test("getExclude string", () => { + // Arrange + const expectedResult = "thevalue"; + getInput.mockImplementationOnce(param => + param === "exclude" ? expectedResult : undefined + ); + // Act + const result = getExclude(); + + // Assert + expect(result).toEqual([expectedResult]); +}); + +test("getExclude array", () => { + // Arrange + const expectedResult = ["element1", "element2"]; + getInput.mockImplementationOnce(param => + param === "exclude" ? expectedResult : undefined + ); + // Act + const result = getExclude(); + + // Assert + expect(result).toEqual(expectedResult); +}); + +test("getExclude undefined", () => { + // Arrange + getInput.mockImplementationOnce(() => undefined); + // Act + const result = getExclude(); + + // Assert + expect(result).toEqual(undefined); +}); + +test("getInclude string", () => { + // Arrange + const expectedResult = "thevalue"; + getInput.mockImplementationOnce(param => + param === "include" ? expectedResult : undefined + ); + // Act + const result = getInclude(); + + // Assert + expect(result).toEqual([expectedResult]); +}); + +test("getInclude array", () => { + // Arrange + const expectedResult = ["element1", "element2"]; + getInput.mockImplementationOnce(param => + param === "include" ? expectedResult : undefined + ); + // Act + const result = getInclude(); + + // Assert + expect(result).toEqual(expectedResult); +}); + +test("getExclude undefined", () => { + // Arrange + getInput.mockImplementationOnce(() => undefined); + // Act + const result = getInclude(); + + // Assert + expect(result).toEqual(undefined); +}); + test("getFont", () => { // Arrange const expectedResult = "whateverfont";