From 3ae4f936826f5e92a1aeefe8f58f40c6daa5185e Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:40:58 -0500 Subject: [PATCH 1/5] Better handling for no tag found --- index.js | 71 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/index.js b/index.js index cc76123..09aa769 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,10 @@ try { const default_value = core.getInput('default-value'); const tag_position = core.getInput('tag-position'); + var value = default_value; + + var issue_body = null; + // Find the correct body obj if ('issue' in github.context.payload){ var issue_body = github.context.payload.issue.body; @@ -15,46 +19,47 @@ try { else if ('pull_request' in github.context.payload){ var issue_body = github.context.payload.pull_request.body; } - else{ - core.exportVariable(env_variable, default_value); - return; - } - // Remove line breaks - issue_body = issue_body.replace(/(\r\n|\n|\r)/gm, " "); - - // Regex wasn't working, so we have to manually do the look up - const body_words = issue_body.split(" "); - - var i; - var tags_found = 0; - for (i = 0; i < body_words.length; i++){ - if (body_words[i] == tag){ - if ((i + 1) < body_words.length){ - if (tag_position == -1){ - value = body_words[i + 1]; - - // Handle Tables - if (value == "|" && (i + 3) < body_words.length && body_words[i+3] == "|"){ - value = body_words[i + 2]; - } - } - else if (tags_found == tag_position){ - value = body_words[i + 1]; - - // Handle Tables - if (value == "|" && (i + 3) < body_words.length && body_words[i+3] == "|"){ - value = body_words[i + 2]; - } - break; + + if (issue_body != null){ + + // Remove line breaks + issue_body = issue_body.replace(/(\r\n|\n|\r)/gm, " "); + + // Regex wasn't working, so we have to manually do the look up + const body_words = issue_body.split(" "); + + var i; + var tags_found = 0; + for (i = 0; i < body_words.length; i++){ + if (body_words[i] == tag){ + if ((i + 1) < body_words.length){ + if (tag_position == -1){ + value = body_words[i + 1]; + + // Handle Tables + if (value == "|" && (i + 3) < body_words.length && body_words[i+3] == "|"){ + value = body_words[i + 2]; + } + } + else if (tags_found == tag_position){ + value = body_words[i + 1]; + + // Handle Tables + if (value == "|" && (i + 3) < body_words.length && body_words[i+3] == "|"){ + value = body_words[i + 2]; + } + break; + } + tags_found++; } - tags_found++; } - } + } } core.exportVariable(env_variable, value); console.log(`The Tag Value: ${value}`); + } } catch (error) { core.setFailed(error.message); } \ No newline at end of file From fbde4b9f34ac319f8822e203904ff301e3f8073b Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:44:14 -0500 Subject: [PATCH 2/5] Adding logging back in --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 09aa769..a35d2d6 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,9 @@ try { const default_value = core.getInput('default-value'); const tag_position = core.getInput('tag-position'); + var value = default_value; + console.log(`The Default Value: ${value}`); var issue_body = null; From 672f61fe97742784181fb76a5b2148d4ee0c91eb Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:46:29 -0500 Subject: [PATCH 3/5] Adding logging back in --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a35d2d6..cba2488 100644 --- a/index.js +++ b/index.js @@ -9,8 +9,8 @@ try { const tag_position = core.getInput('tag-position'); - var value = default_value; - console.log(`The Default Value: ${value}`); + var output_value = default_value; + console.log(`The Default Value: ${output_value}`); var issue_body = null; @@ -58,9 +58,8 @@ try { } } - core.exportVariable(env_variable, value); - console.log(`The Tag Value: ${value}`); + core.exportVariable(env_variable, value); } } catch (error) { core.setFailed(error.message); From b2a3ebf2847e98753729a5231a1adfcebd451e3a Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:48:56 -0500 Subject: [PATCH 4/5] Adding logging back in --- index.js | 106 ++++++++++++++++++++++++++----------------------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/index.js b/index.js index cba2488..b1d2263 100644 --- a/index.js +++ b/index.js @@ -3,64 +3,60 @@ const github = require('@actions/github'); try { - const tag = core.getInput('tag'); - const env_variable = core.getInput('env-variable'); - const default_value = core.getInput('default-value'); - const tag_position = core.getInput('tag-position'); - - - var output_value = default_value; - console.log(`The Default Value: ${output_value}`); - - var issue_body = null; - - // Find the correct body obj - if ('issue' in github.context.payload){ - var issue_body = github.context.payload.issue.body; - } - else if ('pull_request' in github.context.payload){ - var issue_body = github.context.payload.pull_request.body; - } - - if (issue_body != null){ - - // Remove line breaks - issue_body = issue_body.replace(/(\r\n|\n|\r)/gm, " "); - - // Regex wasn't working, so we have to manually do the look up - const body_words = issue_body.split(" "); - - var i; - var tags_found = 0; - for (i = 0; i < body_words.length; i++){ - if (body_words[i] == tag){ - if ((i + 1) < body_words.length){ - if (tag_position == -1){ - value = body_words[i + 1]; - - // Handle Tables - if (value == "|" && (i + 3) < body_words.length && body_words[i+3] == "|"){ - value = body_words[i + 2]; - } - } - else if (tags_found == tag_position){ - value = body_words[i + 1]; - - // Handle Tables - if (value == "|" && (i + 3) < body_words.length && body_words[i+3] == "|"){ - value = body_words[i + 2]; - } - break; + const tag = core.getInput('tag'); + const env_variable = core.getInput('env-variable'); + const default_value = core.getInput('default-value'); + const tag_position = core.getInput('tag-position'); + + + var value = default_value; + + var issue_body = null; + + // Find the correct body obj + if ('issue' in github.context.payload) { + var issue_body = github.context.payload.issue.body; + } else if ('pull_request' in github.context.payload) { + var issue_body = github.context.payload.pull_request.body; + } + + if (issue_body != null) { + + // Remove line breaks + issue_body = issue_body.replace(/(\r\n|\n|\r)/gm, " "); + + // Regex wasn't working, so we have to manually do the look up + const body_words = issue_body.split(" "); + + var i; + var tags_found = 0; + for (i = 0; i < body_words.length; i++) { + if (body_words[i] == tag) { + if ((i + 1) < body_words.length) { + if (tag_position == -1) { + value = body_words[i + 1]; + + // Handle Tables + if (value == "|" && (i + 3) < body_words.length && body_words[i + 3] == "|") { + value = body_words[i + 2]; + } + } else if (tags_found == tag_position) { + value = body_words[i + 1]; + + // Handle Tables + if (value == "|" && (i + 3) < body_words.length && body_words[i + 3] == "|") { + value = body_words[i + 2]; + } + break; + } + tags_found++; } - tags_found++; } } - } - } + } - console.log(`The Tag Value: ${value}`); - core.exportVariable(env_variable, value); - } + console.log(`The Tag Value: ${value}`); + core.exportVariable(env_variable, value); } catch (error) { - core.setFailed(error.message); + core.setFailed(error.message); } \ No newline at end of file From c70f96f6d5586908fc37cadda41dde6d7a8a7961 Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:50:16 -0500 Subject: [PATCH 5/5] Fixes default behavior --- .github/workflows/example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index 1982302..bf55299 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v2 - name: Run Action - uses: TheBurchLog/body-env-tag-action@3.0 + uses: TheBurchLog/body-env-tag-action@4.0 with: tag: 'body-tag:' env-variable: 'MY_TAG'