Skip to content

Commit

Permalink
Merge pull request #7 from Staffbase/bug-fixing
Browse files Browse the repository at this point in the history
🐛 Provide bug fixes
  • Loading branch information
jreimone authored Jul 5, 2023
2 parents ebc2e84 + 26bd02f commit cfc238b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ runs:
- name: TestIO - Init global environment
shell: bash
run: |-
echo "TESTIO_SCRIPTS_DIR=${{github.action_path}}" >> $GITHUB_ENV
echo "TESTIO_ERROR_MSG_FILE=errorToComment.msg" >> $GITHUB_ENV
- name: TestIO - Set up Node
Expand All @@ -41,7 +42,9 @@ runs:

- name: TestIO - Install Dependencies
shell: bash
run: npm install
run: |-
cd ${{github.action_path}}
npm install
- name: TestIO - Add PR comment for requesting required input
id: prepare
Expand Down
2 changes: 1 addition & 1 deletion src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Util {
}

public static throwErrorAndPrepareErrorMessage(errorMessage: string, errorMessageFileName: string) {
const errorMessageFilePath = `resources/${errorMessageFileName}`;
const errorMessageFilePath = `${process.env.TESTIO_SCRIPTS_DIR}/resources/${errorMessageFileName}`;
fs.writeFileSync(errorMessageFilePath, errorMessage);
console.error(errorMessage);
throw new Error(errorMessage);
Expand Down
4 changes: 2 additions & 2 deletions src/addPRcomment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as fs from "fs";
import {Octokit} from "@octokit/rest";

async function addComment() {
const commentPrepareTemplateFile = 'resources/exploratory_test_comment_prepare_template.md';
const commentPrepareTemplateFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/exploratory_test_comment_prepare_template.md`;
const commentTemplate = fs.readFileSync(commentPrepareTemplateFile, 'utf8');

const commentPrepareJsonFile = 'resources/exploratory_test_comment_prepare.json';
const commentPrepareJsonFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/exploratory_test_comment_prepare.json`;
const jsonString = fs.readFileSync(commentPrepareJsonFile, 'utf8');

const createCommentUrl = `${process.env.TESTIO_CREATE_COMMENT_URL}`;
Expand Down
2 changes: 1 addition & 1 deletion src/reportFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Octokit} from "@octokit/rest";

async function reportFailure() {
const errorFileName = `${process.env.TESTIO_ERROR_MSG_FILE}`;
const errorMessageFilePath = `resources/${errorFileName}`;
const errorMessageFilePath = `${process.env.TESTIO_SCRIPTS_DIR}/resources/${errorFileName}`;
const createCommentUrl = `${process.env.TESTIO_CREATE_COMMENT_URL}`;

let commentFailureBody = "";
Expand Down
8 changes: 4 additions & 4 deletions src/reportSuccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ async function reportSuccess() {
const testURL = "https://" + testioSlug + ".test.io/products/" + testioProductId + "/test_cycles/" + testioCreatedTestId;
const createCommentUrl = `${process.env.TESTIO_CREATE_COMMENT_URL}`;

const payloadFile = 'resources/testio_payload.json';
const payload = JSON.parse(fs.readFileSync(payloadFile, 'utf8'));
const payloadFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/testio_payload.json`;
const payloadString = JSON.stringify(JSON.parse(fs.readFileSync(payloadFile, 'utf8')), null, 2);

const commentSuccessTemplateFile = 'resources/exploratory_test_comment_success_template.md';
const commentSuccessTemplateFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/exploratory_test_comment_success_template.md`;
const commentSuccessTemplate = fs.readFileSync(commentSuccessTemplateFile, 'utf8');
const testioTestUrlPlaceholder = "$$TESTIO_TEST_URL$$";
const sentPayloadPlaceholder = "$$SENT_PAYLOAD$$";
const createCommentUrlPlaceholder = "$$CREATE_COMMENT_URL$$";
const successCommentBody = commentSuccessTemplate.replace(testioTestUrlPlaceholder, testURL).replace(sentPayloadPlaceholder, payload).replace(createCommentUrlPlaceholder, createCommentUrl);
const successCommentBody = commentSuccessTemplate.replace(testioTestUrlPlaceholder, testURL).replace(sentPayloadPlaceholder, payloadString).replace(createCommentUrlPlaceholder, createCommentUrl);

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
Expand Down
4 changes: 2 additions & 2 deletions src/retrievePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function createPayload() {
Util.throwErrorAndPrepareErrorMessage(JSON.stringify(error), errorFileName);
}

const prepareTestSchemaFile = 'resources/exploratory_test_comment_prepare_schema.json';
const prepareTestSchemaFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/exploratory_test_comment_prepare_schema.json`;
const {valid, validation} = Util.validateObjectAgainstSchema(preparation, prepareTestSchemaFile);
if (!valid) {
if (validation.errors) {
Expand All @@ -52,7 +52,7 @@ async function createPayload() {
const testIOPayload = Util.convertPrepareObjectToTestIOPayload(preparation, github.context.repo.repo, github.context.repo.owner, github.context.issue.number);
console.log("Converted payload:");
console.log(testIOPayload);
const payloadFile = 'resources/testio_payload.json';
const payloadFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/testio_payload.json`;
await fs.writeFile(payloadFile, JSON.stringify(testIOPayload), (err) => {
if (err) Util.throwErrorAndPrepareErrorMessage(err.message, errorFileName);
console.log(`The payload file ${payloadFile} has been saved successfully`);
Expand Down
2 changes: 1 addition & 1 deletion src/triggerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Util} from "./Util";
import * as core from "@actions/core";

async function triggerTest() {
const payloadFile = 'resources/testio_payload.json';
const payloadFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/testio_payload.json`;
const errorFileName = `${process.env.TESTIO_ERROR_MSG_FILE}`;
const testioProductId = `${process.env.TESTIO_PRODUCT_ID}`;
const testioToken = `${process.env.TESTIO_TOKEN}`;
Expand Down

0 comments on commit cfc238b

Please sign in to comment.