Skip to content

Commit

Permalink
token not mandatory (#119)
Browse files Browse the repository at this point in the history
* token not mandatory

* pull_request_template.md added

* pull_request_template.md added

* pull_request_template.md added
  • Loading branch information
Ginxo authored Nov 26, 2020
1 parent aa90d13 commit 359f069
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `starting-project` input added
- env variables treated from commands
- export command treated
- token not mandatory

## Bugs:

Expand Down
1 change: 1 addition & 0 deletions bin/arguments/arguments-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
16 changes: 10 additions & 6 deletions bin/bin-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion bin/build-chain-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion bin/build-chain-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down

0 comments on commit 359f069

Please sign in to comment.