diff --git a/__tests__/dependabot-api.test.ts b/__tests__/api_client.test.ts similarity index 80% rename from __tests__/dependabot-api.test.ts rename to __tests__/api_client.test.ts index 99b816f..bf5a4e7 100644 --- a/__tests__/dependabot-api.test.ts +++ b/__tests__/api_client.test.ts @@ -1,10 +1,10 @@ -import {APIClient, PackageManager} from '../src/api-client' +import {ApiClient} from '../src/api-client' -describe('APIClient', () => { +describe('ApiClient', () => { const mockAxios: any = { get: jest.fn() } - const api = new APIClient(mockAxios, { + const api = new ApiClient(mockAxios, { jobId: 1, jobToken: 'xxx', credentialsToken: 'yyy', @@ -34,6 +34,6 @@ describe('APIClient', () => { const jobDetails = await api.getJobDetails() expect(jobDetails['allowed-updates'].length).toBe(1) - expect(jobDetails['package-manager']).toBe(PackageManager.NpmAndYarn) + expect(jobDetails['package-manager']).toBe('npm_and_yarn') }) }) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 8e467da..b9ef95e 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import {Context} from '@actions/github/lib/context' -import {APIClient} from '../src/api-client' +import {ApiClient} from '../src/api-client' import {Updater} from '../src/updater' import {ImageService} from '../src/image-service' import * as inputs from '../src/inputs' @@ -21,10 +21,10 @@ describe('run', () => { beforeEach(async () => { markJobAsProcessedSpy = jest.spyOn( - APIClient.prototype, + ApiClient.prototype, 'markJobAsProcessed' ) - reportJobErrorSpy = jest.spyOn(APIClient.prototype, 'reportJobError') + reportJobErrorSpy = jest.spyOn(ApiClient.prototype, 'reportJobError') jest.spyOn(core, 'info').mockImplementation(jest.fn()) jest.spyOn(core, 'setFailed').mockImplementation(jest.fn()) @@ -114,7 +114,7 @@ describe('run', () => { describe('when there is an error retrieving job details from DependabotAPI', () => { beforeEach(() => { jest - .spyOn(APIClient.prototype, 'getJobDetails') + .spyOn(ApiClient.prototype, 'getJobDetails') .mockImplementationOnce( jest.fn(async () => Promise.reject(new Error('error getting job details')) @@ -148,7 +148,7 @@ describe('run', () => { describe('when there is an error retrieving job credentials from DependabotAPI', () => { beforeEach(() => { jest - .spyOn(APIClient.prototype, 'getCredentials') + .spyOn(ApiClient.prototype, 'getCredentials') .mockImplementationOnce( jest.fn(async () => Promise.reject(new Error('error getting credentials')) diff --git a/__tests__/proxy-integration.test.ts b/__tests__/proxy-integration.test.ts index d6f9c62..e08b194 100644 --- a/__tests__/proxy-integration.test.ts +++ b/__tests__/proxy-integration.test.ts @@ -1,5 +1,5 @@ import Docker from 'dockerode' -import {Credential, JobDetails, PackageManager} from '../src/api-client' +import {Credential, JobDetails} from '../src/api-client' import {ImageService} from '../src/image-service' import {PROXY_IMAGE_NAME} from '../src/main' import {ProxyBuilder} from '../src/proxy' @@ -17,7 +17,7 @@ describe('ProxyBuilder', () => { 'dependency-type': 'all' } ], - 'package-manager': PackageManager.NpmAndYarn + 'package-manager': 'npm_and_yarn' } const credentials: Credential[] = [ { diff --git a/__tests__/updater-integration.test.ts b/__tests__/updater-integration.test.ts index 7ad1b77..def0627 100644 --- a/__tests__/updater-integration.test.ts +++ b/__tests__/updater-integration.test.ts @@ -1,6 +1,6 @@ import axios from 'axios' -import {APIClient, JobParameters} from '../src/api-client' +import {ApiClient, JobParameters} from '../src/api-client' import {ImageService} from '../src/image-service' import {UPDATER_IMAGE_NAME, PROXY_IMAGE_NAME} from '../src/main' import {Updater} from '../src/updater' @@ -27,7 +27,7 @@ describe('Updater', () => { ) const client = axios.create({baseURL: dependabotApiUrl}) - const apiClient = new APIClient(client, params) + const apiClient = new ApiClient(client, params) beforeAll(async () => { // Skip the test when we haven't preloaded the updater image diff --git a/__tests__/updater.test.ts b/__tests__/updater.test.ts index caa02f0..591e312 100644 --- a/__tests__/updater.test.ts +++ b/__tests__/updater.test.ts @@ -1,9 +1,8 @@ import {UPDATER_IMAGE_NAME, PROXY_IMAGE_NAME} from '../src/main' import {Updater} from '../src/updater' -import {PackageManager} from '../src/api-client' describe('Updater', () => { - const mockAPIClient: any = { + const mockApiClient: any = { getJobDetails: jest.fn(), getCredentials: jest.fn(), params: { @@ -13,6 +12,7 @@ describe('Updater', () => { dependabotApiUrl: 'http://host.docker.internal:3001' } } + const mockJobDetails: any = { id: '1', 'allowed-updates': [ @@ -20,19 +20,19 @@ describe('Updater', () => { 'dependency-type': 'all' } ], - 'package-manage': PackageManager.NpmAndYarn + 'package-manager': 'npm-and-yarn' } const updater = new Updater( UPDATER_IMAGE_NAME, PROXY_IMAGE_NAME, - mockAPIClient, + mockApiClient, mockJobDetails, [] ) it('should fetch job details', async () => { - mockAPIClient.getJobDetails.mockImplementation(() => { + mockApiClient.getJobDetails.mockImplementation(() => { throw new Error('kaboom') }) updater.runUpdater() diff --git a/src/api-client.ts b/src/api-client.ts index 7b969b0..9f1186d 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -11,19 +11,13 @@ export class JobParameters { ) {} } -// TODO: Populate with enabled values -// TODO: Rescue unsupported values -export enum PackageManager { - NpmAndYarn = 'npm_and_yarn' -} - // JobDetails are information about the repository and dependencies to be updated export type JobDetails = { 'allowed-updates': { 'dependency-type': string }[] id: string - 'package-manager': PackageManager + 'package-manager': string } export type JobError = { @@ -39,7 +33,7 @@ export type Credential = { token?: string } -export class APIClient { +export class ApiClient { constructor( private readonly client: AxiosInstance, readonly params: JobParameters diff --git a/src/main.ts b/src/main.ts index 2a83d24..62e6693 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,7 +4,7 @@ import {Context} from '@actions/github/lib/context' import {getJobParameters} from './inputs' import {ImageService} from './image-service' import {Updater} from './updater' -import {APIClient} from './api-client' +import {ApiClient} from './api-client' import axios from 'axios' export const UPDATER_IMAGE_NAME = @@ -34,7 +34,7 @@ export async function run(context: Context): Promise { core.setSecret(params.credentialsToken) const client = axios.create({baseURL: params.dependabotApiUrl}) - const apiClient = new APIClient(client, params) + const apiClient = new ApiClient(client, params) try { core.info('Fetching job details') @@ -86,7 +86,7 @@ export async function run(context: Context): Promise { } async function failJob( - apiClient: APIClient, + apiClient: ApiClient, error: Error, errorType = DependabotErrorType.Unknown ): Promise { diff --git a/src/updater.ts b/src/updater.ts index ebfcc04..ec40007 100644 --- a/src/updater.ts +++ b/src/updater.ts @@ -2,7 +2,7 @@ import * as core from '@actions/core' import Docker, {Container} from 'dockerode' import path from 'path' import fs from 'fs' -import {JobDetails, APIClient, Credential} from './api-client' +import {JobDetails, ApiClient, Credential} from './api-client' import {ContainerService} from './container-service' import {base64DecodeDependencyFile} from './utils' import {DependencyFile, FetchedFiles, FileUpdaterInput} from './config-types' @@ -22,7 +22,7 @@ export class Updater { constructor( private readonly updaterImage: string, private readonly proxyImage: string, - private readonly apiClient: APIClient, + private readonly apiClient: ApiClient, private readonly details: JobDetails, private readonly credentials: Credential[] ) {