diff --git a/dist/index.js b/dist/index.js
index 5aa98c2..e083bad 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -119672,6 +119672,9 @@ __webpack_async_result__();
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(27133);
/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__);
+/* harmony import */ var _actions_http_client__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(99855);
+/* harmony import */ var _actions_http_client__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(_actions_http_client__WEBPACK_IMPORTED_MODULE_2__);
+
@@ -119689,10 +119692,12 @@ __webpack_async_result__();
const commentIdentifier = "junit-summary-action";
let comment;
if (result.numberOfFailedTests > 0) {
- comment = `⚠️ ${result.numberOfFailedTests} tests failed.`;
+ const randomGif = await getRandomGif("fail");
+ comment = `
⚠️ ${result.numberOfFailedTests} tests failed
`;
}
else {
- comment = `✅ All ${result.numberOfPassedTests} tests passed`;
+ const randomGif = await getRandomGif("success");
+ comment = `✅ All ${result.numberOfPassedTests} tests passed
`;
}
const commentBody = `**${comment}**\n\n[See summary](${getWorkflowRunSummaryUrl()})\n\n${commentIdentifier}`;
// Retrieve the list of comments on the pull request
@@ -119729,6 +119734,18 @@ __webpack_async_result__();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(`Action failed with error: ${error}`);
}
});
+async function getRandomGif(search) {
+ const httpClient = new _actions_http_client__WEBPACK_IMPORTED_MODULE_2__.HttpClient();
+ const randomNumber = Math.floor(Math.random() * 101);
+ const res = await httpClient.get(`https://api.giphy.com/v1/gifs/search?api_key=PFZ64SqzXhfNwVVWo6iwe1UjZzUomr1j&q=${search}&limit=1&offset=${randomNumber}&rating=g&lang=en&bundle=messaging_non_clips`);
+ const body = await res.readBody();
+ const responseJson = JSON.parse(body);
+ if (responseJson.data.length > 0) {
+ const fixedWidthImage = responseJson.data[0].images.original;
+ return fixedWidthImage.url;
+ }
+ return undefined;
+}
function getWorkflowRunSummaryUrl() {
const { owner, repo } = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo;
const runId = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.runId; // This is provided by the GitHub Actions environment
diff --git a/package-lock.json b/package-lock.json
index fd9b0e3..191d340 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,6 +13,7 @@
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@actions/glob": "^0.4.0",
+ "@actions/http-client": "^2.2.0",
"cd": "^0.3.3",
"dotenv": "^16.3.1",
"eslint": "^8.52.0",
diff --git a/package.json b/package.json
index 8892c03..4c57051 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,7 @@
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@actions/glob": "^0.4.0",
+ "@actions/http-client": "^2.2.0",
"cd": "^0.3.3",
"dotenv": "^16.3.1",
"eslint": "^8.52.0",
diff --git a/src/utils/addCommentToPR.ts b/src/utils/addCommentToPR.ts
index f3bb9e7..36e6d5f 100644
--- a/src/utils/addCommentToPR.ts
+++ b/src/utils/addCommentToPR.ts
@@ -1,6 +1,7 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import { context } from "@actions/github";
+import * as http from "@actions/http-client";
export default async (result: WriteSummaryResult) => {
try {
@@ -19,9 +20,11 @@ export default async (result: WriteSummaryResult) => {
let comment: string;
if (result.numberOfFailedTests > 0) {
- comment = `⚠️ ${result.numberOfFailedTests} tests failed.`;
+ const randomGif = await getRandomGif("fail");
+ comment = `⚠️ ${result.numberOfFailedTests} tests failed
`;
} else {
- comment = `✅ All ${result.numberOfPassedTests} tests passed`;
+ const randomGif = await getRandomGif("success");
+ comment = `✅ All ${result.numberOfPassedTests} tests passed
`;
}
const commentBody = `**${comment}**\n\n[See summary](${getWorkflowRunSummaryUrl()})\n\n${commentIdentifier}`;
@@ -67,8 +70,64 @@ export default async (result: WriteSummaryResult) => {
}
};
+async function getRandomGif(search: string) {
+ const httpClient = new http.HttpClient();
+ const randomNumber = Math.floor(Math.random() * 101);
+ const res = await httpClient.get(
+ `https://api.giphy.com/v1/gifs/search?api_key=PFZ64SqzXhfNwVVWo6iwe1UjZzUomr1j&q=${search}&limit=1&offset=${randomNumber}&rating=g&lang=en&bundle=messaging_non_clips`
+ );
+
+ const body = await res.readBody();
+ const responseJson: GiphyResponse = JSON.parse(body);
+ if (responseJson.data.length > 0) {
+ const fixedWidthImage = responseJson.data[0].images.original;
+ return fixedWidthImage.url;
+ }
+ return undefined;
+}
+
function getWorkflowRunSummaryUrl(): string {
const { owner, repo } = context.repo;
const runId = context.runId; // This is provided by the GitHub Actions environment
return `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
}
+
+// ChatGPT ftw
+interface GiphyResponse {
+ data: GiphyData[];
+ pagination: Pagination;
+ meta: Meta;
+}
+
+interface GiphyData {
+ type: string;
+ id: string;
+ url: string;
+ images: GiphyImages;
+}
+
+interface GiphyImages {
+ original: ImageFormat;
+ fixed_height: ImageFormat;
+ fixed_height_downsampled: ImageFormat;
+ fixed_height_small: ImageFormat;
+ fixed_width: ImageFormat;
+}
+
+interface ImageFormat {
+ height: string;
+ width: string;
+ url: string;
+}
+
+interface Pagination {
+ total_count: number;
+ count: number;
+ offset: number;
+}
+
+interface Meta {
+ status: number;
+ msg: string;
+ response_id: string;
+}