From 359f0699538bf5ef333c4c81d24ca97654048aad Mon Sep 17 00:00:00 2001 From: Enrique Mingorance Cano <emingora@redhat.com> Date: Thu, 26 Nov 2020 11:42:46 +0100 Subject: [PATCH] token not mandatory (#119) * token not mandatory * pull_request_template.md added * pull_request_template.md added * pull_request_template.md added --- .github/pull_request_template.md | 11 +++++++++++ CHANGELOG.md | 1 + bin/arguments/arguments-constructor.js | 1 + bin/bin-utils.js | 16 ++++++++++------ bin/build-chain-cli.js | 2 +- bin/build-chain-event.js | 2 +- dist/index.js | 18 +++++++++++------- package-lock.json | 2 +- package.json | 2 +- 9 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..46e560b7 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,11 @@ +**Thank you for submitting this pull request** + +fix _(please add the issue ID if it exists)_ + +**referenced Pull Requests**: _(please edit the URLs of referenced pullrequests if they exist)_ + +* paste the link(s) from GitHub here +* link 2 +* link 3 etc. + +> **_Note:_** Please, do not check `dist/index.js` changes. It is automatically generated. diff --git a/CHANGELOG.md b/CHANGELOG.md index 0afcee14..4d4e570c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `starting-project` input added - env variables treated from commands - export command treated +- token not mandatory ## Bugs: diff --git a/bin/arguments/arguments-constructor.js b/bin/arguments/arguments-constructor.js index d937c2a1..c1a18f7d 100644 --- a/bin/arguments/arguments-constructor.js +++ b/bin/arguments/arguments-constructor.js @@ -23,6 +23,7 @@ function getArguments() { }); parser.add_argument("-token", "--token", { nargs: 1, + required: false, help: "The GITHUB_TOKEN. It can be set throw environment variable instead" }); parser.add_argument("-d", "--debug", { diff --git a/bin/bin-utils.js b/bin/bin-utils.js index 7aefd546..527d23df 100644 --- a/bin/bin-utils.js +++ b/bin/bin-utils.js @@ -9,9 +9,9 @@ require("dotenv").config(); * Gets an environment variable value * @param {String} name the environment variable name */ -function getProcessEnvVariable(name) { +function getProcessEnvVariable(name, mandatory = true) { const val = process.env[name]; - if (!val || !val.length) { + if (mandatory && (!val || !val.length)) { throw new ClientError(`environment variable ${name} not set!`); } return val; @@ -48,10 +48,14 @@ function getDefaultRootFolder() { } function createOctokitInstance(token) { - return new Octokit({ - auth: `token ${token}`, - userAgent: "kiegroup/github-build-chain-action" - }); + return token + ? new Octokit({ + auth: `token ${token}`, + userAgent: "kiegroup/github-build-chain-action" + }) + : new Octokit({ + userAgent: "kiegroup/github-build-chain-action" + }); } module.exports = { diff --git a/bin/build-chain-cli.js b/bin/build-chain-cli.js index 18225318..42e93169 100755 --- a/bin/build-chain-cli.js +++ b/bin/build-chain-cli.js @@ -22,7 +22,7 @@ async function main() { if (args.token) { process.env["GITHUB_TOKEN"] = args.token[0]; } - const token = getProcessEnvVariable("GITHUB_TOKEN"); + const token = getProcessEnvVariable("GITHUB_TOKEN", false); const octokit = createOctokitInstance(token); addLocalExecutionVariables({ diff --git a/bin/build-chain-event.js b/bin/build-chain-event.js index fd0b4761..e7f4ecb0 100755 --- a/bin/build-chain-event.js +++ b/bin/build-chain-event.js @@ -20,7 +20,7 @@ const { createOctokitInstance, getProcessEnvVariable } = require("./bin-utils"); require("dotenv").config(); async function main() { - const token = getProcessEnvVariable("GITHUB_TOKEN"); + const token = getProcessEnvVariable("GITHUB_TOKEN", false); const octokit = createOctokitInstance(token); if (isPullRequestFlowType()) { await pullRequestEventFlow(token, octokit, process.env); diff --git a/dist/index.js b/dist/index.js index 49a3a7fe..1daed860 100755 --- a/dist/index.js +++ b/dist/index.js @@ -2061,7 +2061,7 @@ const { createOctokitInstance, getProcessEnvVariable } = __webpack_require__(867 __webpack_require__(63).config(); async function main() { - const token = getProcessEnvVariable("GITHUB_TOKEN"); + const token = getProcessEnvVariable("GITHUB_TOKEN", false); const octokit = createOctokitInstance(token); if (isPullRequestFlowType()) { await pullRequestEventFlow(token, octokit, process.env); @@ -26207,9 +26207,9 @@ __webpack_require__(63).config(); * Gets an environment variable value * @param {String} name the environment variable name */ -function getProcessEnvVariable(name) { +function getProcessEnvVariable(name, mandatory = true) { const val = process.env[name]; - if (!val || !val.length) { + if (mandatory && (!val || !val.length)) { throw new ClientError(`environment variable ${name} not set!`); } return val; @@ -26246,10 +26246,14 @@ function getDefaultRootFolder() { } function createOctokitInstance(token) { - return new Octokit({ - auth: `token ${token}`, - userAgent: "kiegroup/github-build-chain-action" - }); + return token + ? new Octokit({ + auth: `token ${token}`, + userAgent: "kiegroup/github-build-chain-action" + }) + : new Octokit({ + userAgent: "kiegroup/github-build-chain-action" + }); } module.exports = { diff --git a/package-lock.json b/package-lock.json index 4535654a..a2a6e088 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@kie/build-chain-action", - "version": "2.2.5", + "version": "2.2.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5592a1e8..aac7c9f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kie/build-chain-action", - "version": "2.2.9", + "version": "2.2.10", "description": "GitHub action to define action chains", "main": "dist/build-chain-cli.js", "author": "Enrique Mingorance Cano <emingora@redhat.com>",