Skip to content

Commit

Permalink
Merge pull request #17 from TheBurchLog/pr-tester
Browse files Browse the repository at this point in the history
Pr tester
  • Loading branch information
TheBurchLog authored Feb 22, 2021
2 parents 3712081 + c70f96f commit 2e297fb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
100 changes: 51 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +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');

// 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;
}
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;
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++;
}
}
}

core.exportVariable(env_variable, value);

console.log(`The Tag Value: ${value}`);
console.log(`The Tag Value: ${value}`);
core.exportVariable(env_variable, value);
} catch (error) {
core.setFailed(error.message);
core.setFailed(error.message);
}

0 comments on commit 2e297fb

Please sign in to comment.