Skip to content

Commit

Permalink
Merge pull request #56 from Staffbase/cleanup-code
Browse files Browse the repository at this point in the history
♻️ Cleanup code
  • Loading branch information
jreimone committed Oct 12, 2023
2 parents 5713a44 + d35f316 commit 15c3492
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/TestIOTriggerTestGHA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
Expand All @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions src/retrievePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down

0 comments on commit 15c3492

Please sign in to comment.