From 82be9fe7b0550d2470b8658e7448d11075d172d1 Mon Sep 17 00:00:00 2001 From: delarea Date: Sun, 15 Dec 2024 16:19:02 +0200 Subject: [PATCH 1/8] fix isheaderping accessiable --- src/utils.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index c5907a8c..ad708c95 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,6 +13,7 @@ import { OctokitResponse } from '@octokit/types/dist-types/OctokitResponse'; import * as github from '@actions/github'; import { gzip } from 'zlib'; import { promisify } from 'util'; +import { RequestOptions } from '@actions/http-client/lib/interfaces'; export class Utils { // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -800,18 +801,27 @@ export class Utils { return '\n\n # \n\n The above Job Summary was generated by the Setup JFrog CLI GitHub Action '; } + /** + * Checks if the header image is accessible via the internet. + * saves the result in a static variable to avoid multiple checks. + * @private + */ private static async isHeaderPngAccessible(): Promise { - const url: string = this.MARKDOWN_HEADER_PNG_URL; + // const url: string = this.MARKDOWN_HEADER_PNG_URL; const httpClient: HttpClient = new HttpClient(); try { - const response: HttpClientResponse = await httpClient.head(url); - return response.message.statusCode === 200; + const requestOptions: OutgoingHttpHeaders = { + socketTimeout: 5000, // Set timeout to 5 seconds + }; + const response: HttpClientResponse = await httpClient.head('https://some-not-a-real-url-for-test.com', requestOptions); + this.isSummaryHeaderAccessible = response.message.statusCode === 200; } catch (error) { core.warning('No internet access to the header image, using the text header instead.'); - return false; + this.isSummaryHeaderAccessible = false; } finally { httpClient.dispose(); } + return this.isSummaryHeaderAccessible; } private static getTempDirectory(): string { From 04b34e16c63442fe5d89da4ba9a0c9a3ee8167ca Mon Sep 17 00:00:00 2001 From: delarea Date: Sun, 15 Dec 2024 16:19:29 +0200 Subject: [PATCH 2/8] fix isheaderping accessiable --- src/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index ad708c95..afd31a1b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,7 +13,6 @@ import { OctokitResponse } from '@octokit/types/dist-types/OctokitResponse'; import * as github from '@actions/github'; import { gzip } from 'zlib'; import { promisify } from 'util'; -import { RequestOptions } from '@actions/http-client/lib/interfaces'; export class Utils { // eslint-disable-next-line @typescript-eslint/no-var-requires From bf1a4428cc61dfacae161c97f0a3138fe5897058 Mon Sep 17 00:00:00 2001 From: delarea Date: Sun, 15 Dec 2024 16:54:54 +0200 Subject: [PATCH 3/8] Change bool to possible undefined --- src/utils.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index afd31a1b..6df10824 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -70,7 +70,8 @@ export class Utils { // It cannot be linked to the repository, as GitHub serves the image from a CDN, // which gets blocked by the browser, resulting in an empty image. private static MARKDOWN_HEADER_PNG_URL: string = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg'; - private static isSummaryHeaderAccessible: boolean; + // Flag to indicate if the summary header is accessible, can be undefined if not checked yet. + private static isSummaryHeaderAccessible: boolean | undefined = undefined; /** * Retrieves server credentials for accessing JFrog's server @@ -806,13 +807,16 @@ export class Utils { * @private */ private static async isHeaderPngAccessible(): Promise { - // const url: string = this.MARKDOWN_HEADER_PNG_URL; + if (this.isSummaryHeaderAccessible != undefined) { + return this.isSummaryHeaderAccessible; + } + const url: string = this.MARKDOWN_HEADER_PNG_URL; const httpClient: HttpClient = new HttpClient(); try { const requestOptions: OutgoingHttpHeaders = { socketTimeout: 5000, // Set timeout to 5 seconds }; - const response: HttpClientResponse = await httpClient.head('https://some-not-a-real-url-for-test.com', requestOptions); + const response: HttpClientResponse = await httpClient.head(url, requestOptions); this.isSummaryHeaderAccessible = response.message.statusCode === 200; } catch (error) { core.warning('No internet access to the header image, using the text header instead.'); From 3a28b7f461a19339d34b5ff126b828b2ce5a909e Mon Sep 17 00:00:00 2001 From: delarea Date: Sun, 15 Dec 2024 16:55:18 +0200 Subject: [PATCH 4/8] Change bool to possible undefined --- lib/utils.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 02548588..e8589338 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -728,21 +728,33 @@ class Utils { static getMarkdownFooter() { return '\n\n # \n\n The above Job Summary was generated by the Setup JFrog CLI GitHub Action '; } + /** + * Checks if the header image is accessible via the internet. + * saves the result in a static variable to avoid multiple checks. + * @private + */ static isHeaderPngAccessible() { return __awaiter(this, void 0, void 0, function* () { + if (this.isSummaryHeaderAccessible != undefined) { + return this.isSummaryHeaderAccessible; + } const url = this.MARKDOWN_HEADER_PNG_URL; const httpClient = new http_client_1.HttpClient(); try { - const response = yield httpClient.head(url); - return response.message.statusCode === 200; + const requestOptions = { + socketTimeout: 5000, // Set timeout to 5 seconds + }; + const response = yield httpClient.head(url, requestOptions); + this.isSummaryHeaderAccessible = response.message.statusCode === 200; } catch (error) { core.warning('No internet access to the header image, using the text header instead.'); - return false; + this.isSummaryHeaderAccessible = false; } finally { httpClient.dispose(); } + return this.isSummaryHeaderAccessible; }); } static getTempDirectory() { @@ -809,3 +821,5 @@ Utils.CUSTOM_SERVER_ID = 'custom-server-id'; // It cannot be linked to the repository, as GitHub serves the image from a CDN, // which gets blocked by the browser, resulting in an empty image. Utils.MARKDOWN_HEADER_PNG_URL = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg'; +// Flag to indicate if the summary header is accessible, can be undefined if not checked yet. +Utils.isSummaryHeaderAccessible = undefined; From ad061fca647d247d040ed7dfb4d1382e59ce2427 Mon Sep 17 00:00:00 2001 From: delarea Date: Mon, 16 Dec 2024 14:01:26 +0200 Subject: [PATCH 5/8] format --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index e8589338..7aa48a64 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -767,7 +767,6 @@ class Utils { return tempDir; } } -exports.Utils = Utils; // eslint-disable-next-line @typescript-eslint/no-var-requires Utils.USER_AGENT = 'setup-jfrog-cli-github-action/' + require('../package.json').version; // Default artifactory URL and repository for downloading JFrog CLI @@ -823,3 +822,4 @@ Utils.CUSTOM_SERVER_ID = 'custom-server-id'; Utils.MARKDOWN_HEADER_PNG_URL = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg'; // Flag to indicate if the summary header is accessible, can be undefined if not checked yet. Utils.isSummaryHeaderAccessible = undefined; +exports.Utils = Utils; From e6e125c8747eadbe166c0da2c56115a741c95427 Mon Sep 17 00:00:00 2001 From: delarea Date: Mon, 16 Dec 2024 14:02:02 +0200 Subject: [PATCH 6/8] format --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 7aa48a64..e8589338 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -767,6 +767,7 @@ class Utils { return tempDir; } } +exports.Utils = Utils; // eslint-disable-next-line @typescript-eslint/no-var-requires Utils.USER_AGENT = 'setup-jfrog-cli-github-action/' + require('../package.json').version; // Default artifactory URL and repository for downloading JFrog CLI @@ -822,4 +823,3 @@ Utils.CUSTOM_SERVER_ID = 'custom-server-id'; Utils.MARKDOWN_HEADER_PNG_URL = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg'; // Flag to indicate if the summary header is accessible, can be undefined if not checked yet. Utils.isSummaryHeaderAccessible = undefined; -exports.Utils = Utils; From c2e8aee4e21095eb105f4e3b150f68947436ec86 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 26 Dec 2024 09:57:29 +0200 Subject: [PATCH 7/8] CR --- lib/utils.js | 7 ++++--- src/utils.ts | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 6552f128..2d5282aa 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -828,7 +828,7 @@ class Utils { } /** * Checks if the header image is accessible via the internet. - * saves the result in a static variable to avoid multiple checks. + * Saves the result in a static variable to avoid multiple checks. * @private */ static isHeaderPngAccessible() { @@ -839,8 +839,9 @@ class Utils { const url = this.MARKDOWN_HEADER_PNG_URL; const httpClient = new http_client_1.HttpClient(); try { + // Set timeout to 5 seconds const requestOptions = { - socketTimeout: 5000, // Set timeout to 5 seconds + socketTimeout: 5000, }; const response = yield httpClient.head(url, requestOptions); this.isSummaryHeaderAccessible = response.message.statusCode === 200; @@ -865,7 +866,6 @@ class Utils { return tempDir; } } -exports.Utils = Utils; // eslint-disable-next-line @typescript-eslint/no-var-requires Utils.USER_AGENT = 'setup-jfrog-cli-github-action/' + require('../package.json').version; // Default artifactory URL and repository for downloading JFrog CLI @@ -931,3 +931,4 @@ Utils.CUSTOM_SERVER_ID = 'custom-server-id'; Utils.MARKDOWN_HEADER_PNG_URL = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg'; // Flag to indicate if the summary header is accessible, can be undefined if not checked yet. Utils.isSummaryHeaderAccessible = undefined; +exports.Utils = Utils; diff --git a/src/utils.ts b/src/utils.ts index 2fc2b0f0..dce4533b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -916,7 +916,7 @@ export class Utils { /** * Checks if the header image is accessible via the internet. - * saves the result in a static variable to avoid multiple checks. + * Saves the result in a static variable to avoid multiple checks. * @private */ private static async isHeaderPngAccessible(): Promise { @@ -926,8 +926,9 @@ export class Utils { const url: string = this.MARKDOWN_HEADER_PNG_URL; const httpClient: HttpClient = new HttpClient(); try { + // Set timeout to 5 seconds const requestOptions: OutgoingHttpHeaders = { - socketTimeout: 5000, // Set timeout to 5 seconds + socketTimeout: 5000, }; const response: HttpClientResponse = await httpClient.head(url, requestOptions); this.isSummaryHeaderAccessible = response.message.statusCode === 200; From 6e26b1a66138bffa87a3adf1e4d0e4e73f0cfa70 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 26 Dec 2024 09:57:48 +0200 Subject: [PATCH 8/8] CR --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 2d5282aa..089873f1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -866,6 +866,7 @@ class Utils { return tempDir; } } +exports.Utils = Utils; // eslint-disable-next-line @typescript-eslint/no-var-requires Utils.USER_AGENT = 'setup-jfrog-cli-github-action/' + require('../package.json').version; // Default artifactory URL and repository for downloading JFrog CLI @@ -931,4 +932,3 @@ Utils.CUSTOM_SERVER_ID = 'custom-server-id'; Utils.MARKDOWN_HEADER_PNG_URL = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg'; // Flag to indicate if the summary header is accessible, can be undefined if not checked yet. Utils.isSummaryHeaderAccessible = undefined; -exports.Utils = Utils;