Skip to content

Commit

Permalink
exclude include options added (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginxo authored Nov 26, 2020
1 parent 2f96bf2 commit fb668f4
Show file tree
Hide file tree
Showing 12 changed files with 684 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

- basic image generation based on the while definition file
- repository list generation
- exclude functionallity
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
> ```
Expand All @@ -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
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion bin/arguments/image-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function getArguments(subParser) {
help: "image generation"
});
buildParser.add_argument("-font", {
metavar: "<URL>",
nargs: 1,
required: false,
help:
Expand Down
16 changes: 15 additions & 1 deletion bin/arguments/repository-list-arguments.js
Original file line number Diff line number Diff line change
@@ -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 };
43 changes: 38 additions & 5 deletions bin/flows/project-list-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 };
5 changes: 4 additions & 1 deletion bin/generator-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}

Expand Down
7 changes: 6 additions & 1 deletion bin/generator-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const {
getDefinitionFile,
getFileType,
getOutputFilePath,
getExclude,
getInclude,
getFont
} = require("./utils/action-utils");
require("dotenv").config();
Expand All @@ -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.`
Expand Down
12 changes: 12 additions & 0 deletions bin/utils/action-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -20,5 +30,7 @@ module.exports = {
getDefinitionFile,
getFileType,
getOutputFilePath,
getExclude,
getInclude,
getFont
};
64 changes: 57 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5152,6 +5152,8 @@ const {
getDefinitionFile,
getFileType,
getOutputFilePath,
getExclude,
getInclude,
getFont
} = __webpack_require__(755);
__webpack_require__(63).config();
Expand All @@ -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.`
Expand Down Expand Up @@ -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");
}
Expand All @@ -6341,6 +6356,8 @@ module.exports = {
getDefinitionFile,
getFileType,
getOutputFilePath,
getExclude,
getInclude,
getFont
};

Expand Down Expand Up @@ -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(
Expand All @@ -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 };


Expand All @@ -7052,7 +7102,7 @@ module.exports = { generateRepositoryList };
/***/ 896:
/***/ (function(module) {

module.exports = {"_args":[["[email protected]","/home/emingora/development/projects/RedHat/issues/BXMSPROD-1044/build-chain-files-generator"]],"_from":"[email protected]","_id":"[email protected]","_inBundle":false,"_integrity":"sha512-S98rKsPcuhfTcYbtF53UIJhcbgIAK533d1kJKMwsMwAIFgfd58MOyxRud3kktlzWiEkFliaJtvyZCBtud/XVEA==","_location":"/canvas","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"[email protected]","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":"[email protected]"},"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":"[email protected]"},{"name":"Rod Vagg","email":"[email protected]"},{"name":"Juriy Zaytsev","email":"[email protected]"}],"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 <[email protected]>","main":"index.js","browser":"browser.js","contributors":["Nathan Rajlich <[email protected]>","Rod Vagg <[email protected]>","Juriy Zaytsev <[email protected]>"],"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":"[email protected]"};

/***/ }),

Expand Down
Loading

0 comments on commit fb668f4

Please sign in to comment.