From 24be564149de94a70487280c05d5a68a4a87dce1 Mon Sep 17 00:00:00 2001 From: Bono Fox Date: Wed, 4 Dec 2024 23:48:33 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Added=20input=20property=20for?= =?UTF-8?q?=20log-level?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - logging can be disabled - debug-logging can be enabled (verbose-setting) --- README.md | 15 ++++++++------- action.yml | 5 +++++ src/generate-readme.js | 15 ++++++++------- src/index.js | 20 ++++++++++++++++++-- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ef0d07d..015bef1 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,14 @@ It does not require to do `checkout` and it's independent on the Github runner/d Inputs marked as "Required" must be set. -| Name | Type | Required | Default | Description | -| ------------- | ------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------- | -| `name` | String | Yes | | Variable name | -| `value` | String | Yes | | Variable value | -| `repository` | String | Yes | | Repository name, with format `/` i.e `openfoxes/set-github-variable` | -| `token` | String | Yes | | [Repository Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) | -| `logOldValue` | Boolean | No | `true` | Enables/Disables logging of the previous variable value | +| Name | Type | Required | Default | Description | +| ------------- | ------------------------ | -------- | ------- | --------------------------------------------------------------------------------------------------------------- | +| `name` | String | Yes | | Variable name | +| `value` | String | Yes | | Variable value | +| `repository` | String | Yes | | Repository name, with format `/` i.e `openfoxes/set-github-variable` | +| `token` | String | Yes | | [Repository Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) | +| `logLevel` | Enum [NONE/INFO/VERBOSE] | No | `INFO` | Granularity of log messages. `None` disables the logging. | +| `logOldValue` | Boolean | No | `true` | Enables/Disables logging of the previous variable value | The following are to be provided when the value is Org scoped instead of a repository variable: diff --git a/action.yml b/action.yml index 394886d..c646651 100644 --- a/action.yml +++ b/action.yml @@ -23,6 +23,11 @@ inputs: description: Repository access token (Personal Access Token or Organization Token) required: true + logLevel: + description: Granularity of log messages (NONE | INFO | VERBOSE) + required: false + default: INFO + logOldValue: description: Whether to log the previous value on running or not required: false diff --git a/src/generate-readme.js b/src/generate-readme.js index 22c834d..770c892 100644 --- a/src/generate-readme.js +++ b/src/generate-readme.js @@ -109,13 +109,14 @@ const generateCustomizing = () => { Inputs marked as "Required" must be set. -| Name | Type | Required | Default | Description | -| ------------- | ------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------- | -| \`name\` | String | Yes | | Variable name | -| \`value\` | String | Yes | | Variable value | -| \`repository\` | String | Yes | | Repository name, with format \`/\` i.e \`openfoxes/set-github-variable\` | -| \`token\` | String | Yes | | [Repository Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) | -| \`logOldValue\` | Boolean | No | \`true\` | Enables/Disables logging of the previous variable value | +| Name | Type | Required | Default | Description | +| ------------- | ------------------------ | -------- | ------- | --------------------------------------------------------------------------------------------------------------- | +| \`name\` | String | Yes | | Variable name | +| \`value\` | String | Yes | | Variable value | +| \`repository\` | String | Yes | | Repository name, with format \`/\` i.e \`openfoxes/set-github-variable\` | +| \`token\` | String | Yes | | [Repository Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) | +| \`logLevel\` | Enum [NONE/INFO/VERBOSE] | No | \`INFO\` | Granularity of log messages. \`None\` disables the logging. | +| \`logOldValue\` | Boolean | No | \`true\` | Enables/Disables logging of the previous variable value | The following are to be provided when the value is Org scoped instead of a repository variable: diff --git a/src/index.js b/src/index.js index 2baa50f..f1a6871 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ async function run() { value: getInput('value'), repository: getInput('repository'), token: getInput('token'), + logLevel: getInput('logLevel'), logOldValue: getBooleanInput('logOldValue'), org: getInput('org'), base: getInput('org') ? 'orgs' : 'repos', @@ -17,15 +18,30 @@ async function run() { let oldValue; if (parameters.logOldValue) { + if (parameters.logLevel === 'VERBOSE') { + console.log('Extracting old value …'); + } + oldValue = (await getVariable(parameters)).data.value; + + if (parameters.logLevel === 'VERBOSE') { + console.log(`Old value found: ${oldValue}`); + } } + if (parameters.logLevel === 'VERBOSE') { + console.log(`Updating variable ${parameters.name} to ${parameters.value} …`); + } const response = await updateVariable(parameters); if (response.status < 400) { setOutput('data', response.data); setOutput('status', response.status); + if (parameters.logLevel === 'NONE') { + return; + } + if (parameters.logOldValue) { info(`Value of the variable ${parameters.name} changed from ${oldValue} to ${parameters.value}`); } else { @@ -45,7 +61,7 @@ function updateVariable(parameters) { const octokit = new Octokit({ auth: parameters.token, request: { - fetch: fetch + fetch } }); @@ -60,7 +76,7 @@ function getVariable(parameters) { const octokit = new Octokit({ auth: parameters.token, request: { - fetch: fetch + fetch } }); From d2ad93c58d270c610926b32ff81bc4a1c19ba2da Mon Sep 17 00:00:00 2001 From: Bono Fox Date: Wed, 4 Dec 2024 23:52:00 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Run=20c?= =?UTF-8?q?onfiguration=20for=20generating=20the=20README-file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/runConfigurations/Generate_README.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .idea/runConfigurations/Generate_README.xml diff --git a/.idea/runConfigurations/Generate_README.xml b/.idea/runConfigurations/Generate_README.xml new file mode 100644 index 0000000..1440483 --- /dev/null +++ b/.idea/runConfigurations/Generate_README.xml @@ -0,0 +1,13 @@ + + + + + +