From 1e8f0ae37553c3808f07ce07f3026eb0c3832a63 Mon Sep 17 00:00:00 2001 From: Fedor Dikarev Date: Thu, 23 Jan 2025 17:07:51 +0100 Subject: [PATCH] fix cases: kebab for action, camelCase for TS Signed-off-by: Fedor Dikarev --- __tests__/retries_fail.test.ts | 20 ++++++++++---------- __tests__/retries_success.test.ts | 20 ++++++++++---------- src/context.ts | 12 ++++++------ src/docker.ts | 20 ++++++++++---------- src/main.ts | 2 +- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/__tests__/retries_fail.test.ts b/__tests__/retries_fail.test.ts index 3c0fa2b..aca2f6c 100644 --- a/__tests__/retries_fail.test.ts +++ b/__tests__/retries_fail.test.ts @@ -6,15 +6,15 @@ import {login} from '../src/docker'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; test('login retries function', async () => { - let stderr_strings: string[] = []; - let call_count: number = -1; + let stderrStrings: string[] = []; + let callCount: number = -1; // using spyOn() here isn't enough, as we alter the logic // so use `jest.fn()` here for the `Docker.getExecOutput` Docker.getExecOutput = jest.fn(async () => { - call_count++; - console.log(`Mock: ${call_count}, ${stderr_strings}`); - if (call_count >= stderr_strings.length) { + callCount++; + console.log(`Mock: ${callCount}, ${stderrStrings}`); + if (callCount >= stderrStrings.length) { return { exitCode: 0, stdout: 'Mock success', @@ -24,7 +24,7 @@ test('login retries function', async () => { return { exitCode: 1, stdout: '', - stderr: stderr_strings[call_count % stderr_strings.length] + stderr: stderrStrings[callCount % stderrStrings.length] }; }); @@ -32,15 +32,15 @@ test('login retries function', async () => { const password = 'groundcontrol'; const registry = 'https://ghcr.io'; - stderr_strings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; - call_count = -1; + stderrStrings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; + callCount = -1; await expect(async () => { await login(registry, username, password, 'false', ['408', '400'], 5, 0.1); }).rejects.toThrow('mock error, failed with status: 502 Request Timeout'); expect(Docker.getExecOutput).toHaveBeenCalledTimes(2); - stderr_strings = ['not matching error', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; - call_count = -1; + stderrStrings = ['not matching error', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; + callCount = -1; await expect(async () => { await login(registry, username, password, 'false', ['408', '400'], 5, 0.1); }).rejects.toThrow('not matching error'); diff --git a/__tests__/retries_success.test.ts b/__tests__/retries_success.test.ts index 9e42c66..a5e9fde 100644 --- a/__tests__/retries_success.test.ts +++ b/__tests__/retries_success.test.ts @@ -4,15 +4,15 @@ import {login} from '../src/docker'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; test('login retries success function', async () => { - let stderr_strings: string[] = []; - let call_count: number = -1; + let stderrStrings: string[] = []; + let callCount: number = -1; // using spyOn() here isn't enough, as we alter the logic // so use `jest.fn()` here for the `Docker.getExecOutput` Docker.getExecOutput = jest.fn(async () => { - call_count++; - console.log(`Mock: ${call_count}, ${stderr_strings}`); - if (call_count >= stderr_strings.length) { + callCount++; + console.log(`Mock: ${callCount}, ${stderrStrings}`); + if (callCount >= stderrStrings.length) { return { exitCode: 0, stdout: 'Mock success', @@ -22,7 +22,7 @@ test('login retries success function', async () => { return { exitCode: 1, stdout: '', - stderr: stderr_strings[call_count % stderr_strings.length] + stderr: stderrStrings[callCount % stderrStrings.length] }; }); @@ -30,13 +30,13 @@ test('login retries success function', async () => { const password = 'groundcontrol'; const registry = 'https://ghcr.io'; - stderr_strings = []; - call_count = -1; + stderrStrings = []; + callCount = -1; await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1); expect(Docker.getExecOutput).toHaveBeenCalledTimes(1); - stderr_strings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; - call_count = -1; + stderrStrings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout']; + callCount = -1; await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1); expect(Docker.getExecOutput).toHaveBeenCalledTimes(1 + 4); }); diff --git a/src/context.ts b/src/context.ts index ff95067..2ad6c48 100644 --- a/src/context.ts +++ b/src/context.ts @@ -6,9 +6,9 @@ export interface Inputs { password: string; ecr: string; logout: boolean; - http_codes_to_retry: string[]; - max_attempts: number; - retry_timeout: number; + httpCodesToRetry: string[]; + maxAttempts: number; + retryTimeout: number; } export function getInputs(): Inputs { @@ -18,8 +18,8 @@ export function getInputs(): Inputs { password: core.getInput('password'), ecr: core.getInput('ecr'), logout: core.getBooleanInput('logout'), - http_codes_to_retry: core.getInput('http_codes_to_retry').split(','), - max_attempts: Number.parseInt(core.getInput('max_attempts')), - retry_timeout: Number.parseInt(core.getInput('retry_timeout')) + httpCodesToRetry: core.getInput('http-codes-to-retry').split(','), + maxAttempts: Number.parseInt(core.getInput('max-attempts')), + retryTimeout: Number.parseInt(core.getInput('retry-timeout')) }; } diff --git a/src/docker.ts b/src/docker.ts index b5745ad..8a1c4dd 100644 --- a/src/docker.ts +++ b/src/docker.ts @@ -3,9 +3,9 @@ import * as core from '@actions/core'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; -export async function login(registry: string, username: string, password: string, ecr: string, http_codes_to_retry: string[], max_attempts: number, retry_timeout: number): Promise { +export async function login(registry: string, username: string, password: string, ecr: string, httpCodesToRetry: string[], maxAttempts: number, retryTimeout: number): Promise { let succeeded: boolean = false; - for (let attempt = 1; attempt <= max_attempts && !succeeded; attempt++) { + for (let attempt = 1; attempt <= maxAttempts && !succeeded; attempt++) { try { if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) { await loginECR(registry, username, password); @@ -14,9 +14,9 @@ export async function login(registry: string, username: string, password: string } succeeded = true; } catch (error) { - if (attempt < max_attempts && isRetriableError(error.message, http_codes_to_retry)) { - core.info(`Attempt ${attempt} out of ${max_attempts} failed, retrying after ${retry_timeout} seconds`); - await new Promise(r => setTimeout(r, retry_timeout * 1000)); + if (attempt < maxAttempts && isRetriableError(error.message, httpCodesToRetry)) { + core.info(`Attempt ${attempt} out of ${maxAttempts} failed, retrying after ${retryTimeout} seconds`); + await new Promise(r => setTimeout(r, retryTimeout * 1000)); } else { throw error; } @@ -34,14 +34,14 @@ export async function logout(registry: string): Promise { }); } -function isRetriableError(error_message: string, http_codes_to_retry: string[]): boolean { - for (const err_code of http_codes_to_retry) { - if (error_message.includes('failed with status: ' + err_code)) { - core.info(`Retryable match found in ${error_message} for retryable code: ${err_code}`); +function isRetriableError(errorMessage: string, httpCodesToRetry: string[]): boolean { + for (const errCode of httpCodesToRetry) { + if (errorMessage.includes('failed with status: ' + errCode)) { + core.info(`Retryable match found in ${errorMessage} for retryable code: ${errCode}`); return true; } } - core.info(`No matches in ${error_message} when lookging for retryable codes: ${http_codes_to_retry}`); + core.info(`No matches in ${errorMessage} when lookging for retryable codes: ${httpCodesToRetry}`); return false; } diff --git a/src/main.ts b/src/main.ts index 6c816ed..785cb68 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ export async function main(): Promise { const input: context.Inputs = context.getInputs(); stateHelper.setRegistry(input.registry); stateHelper.setLogout(input.logout); - await docker.login(input.registry, input.username, input.password, input.ecr, input.http_codes_to_retry, input.max_attempts, input.retry_timeout); + await docker.login(input.registry, input.username, input.password, input.ecr, input.httpCodesToRetry, input.maxAttempts, input.retryTimeout); } async function post(): Promise {