From b3b1e7dcb9c400174cabe03de342898a3b2f66f3 Mon Sep 17 00:00:00 2001 From: Jan Reimann Date: Thu, 12 Oct 2023 08:03:45 +0200 Subject: [PATCH 1/2] fix: address smells in Util.ts --- src/Util.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Util.ts b/src/Util.ts index b85b92c..5d8b440 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -78,7 +78,7 @@ export class Util { console.log("Successfully received response from request"); return result; } - return Promise.reject("Deserializing the data from the response wasn't successful"); + return Promise.reject(new Error("Deserializing the data from the response wasn't successful")); } else { const error = new Error((await response.json()).error); return Promise.reject(error) @@ -102,7 +102,7 @@ export class Util { } static getUrlFromComment(comment: string): string | undefined { - const urlRegex = /.*```json\s.*\s```\s.*\[.+]\(([^\)]+)\)*/sm; + const urlRegex = /.*```json\s.*\s```\s.*\[.+]\(([^)]+)\)*/sm; const matches = urlRegex.exec(comment); if (!matches) { console.log("Couldn't find a URL in the comment"); @@ -119,7 +119,7 @@ export class Util { return string.slice(0, maxLength - suffix.length) + suffix; } - public static retrievePrepareObjectFromComment(comment: string): any | undefined { + public static retrievePrepareObjectFromComment(comment: string): any { const jsonRegex = /.*```json\s(.+)\s```.*/sm; // everything between ```json and ``` so that we can parse it let preparation: any; preparation = Util.getJsonObjectFromComment(jsonRegex, comment, 1); From d35f3162588129b5af047f2a7265cbf2fb568ea9 Mon Sep 17 00:00:00 2001 From: Jan Reimann Date: Thu, 12 Oct 2023 08:12:12 +0200 Subject: [PATCH 2/2] fix: address smells in retrievePayload.ts --- src/TestIOTriggerTestGHA.ts | 8 ++++++++ src/retrievePayload.ts | 12 ------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/TestIOTriggerTestGHA.ts b/src/TestIOTriggerTestGHA.ts index bd97a5c..5541873 100644 --- a/src/TestIOTriggerTestGHA.ts +++ b/src/TestIOTriggerTestGHA.ts @@ -177,6 +177,14 @@ export class TestIOTriggerTestGHA { const commentContents = `${retrievedComment.data.body}`; if (!commentContents) Util.prepareErrorMessageAndOptionallyThrow(`Comment ${submitCommentUrl} seems to be empty`, this.errorFile); + + const triggerCommentUrl = Util.getUrlFromComment(commentContents); + if (triggerCommentUrl != undefined) { + core.setOutput("testio-create-comment-url", triggerCommentUrl); + } else { + core.setOutput("testio-create-comment-url", ""); + } + return commentContents; } diff --git a/src/retrievePayload.ts b/src/retrievePayload.ts index 3ad3930..f04a4f8 100644 --- a/src/retrievePayload.ts +++ b/src/retrievePayload.ts @@ -15,9 +15,6 @@ */ import * as github from "@actions/github"; -import * as core from "@actions/core"; -import {Util} from "./Util"; -import * as fs from "fs"; import {TestIOTriggerTestGHA} from "./TestIOTriggerTestGHA"; async function createPayload() { @@ -34,15 +31,6 @@ async function createPayload() { errorFileName ); const commentContents = await gha.retrieveCommentContent(submitCommentID, submitCommentUrl); - - // TODO move this part into gha.retrieveCommentConent - const triggerCommentUrl = Util.getUrlFromComment(commentContents); - if (triggerCommentUrl != undefined) { - core.setOutput("testio-create-comment-url", triggerCommentUrl); - } else { - core.setOutput("testio-create-comment-url", ""); - } - const prepareObject = gha.retrieveValidPrepareObjectFromComment(commentContents); const prTitle: string = await gha.retrievePrTitle(); await gha.createAndPersistTestIoPayload(prepareObject, prTitle);