Skip to content

Commit

Permalink
Merge pull request #88 from github/brrygrdn/remove-package-manager-type
Browse files Browse the repository at this point in the history
Remove the PackageManager enum
  • Loading branch information
Barry Gordon authored and GitHub committed Sep 21, 2021
2 parents 10f6585 + 750e512 commit 5f7342f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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')
})
})
10 changes: 5 additions & 5 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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())
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -17,7 +17,7 @@ describe('ProxyBuilder', () => {
'dependency-type': 'all'
}
],
'package-manager': PackageManager.NpmAndYarn
'package-manager': 'npm_and_yarn'
}
const credentials: Credential[] = [
{
Expand Down
4 changes: 2 additions & 2 deletions __tests__/updater-integration.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions __tests__/updater.test.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -13,26 +12,27 @@ describe('Updater', () => {
dependabotApiUrl: 'http://host.docker.internal:3001'
}
}

const mockJobDetails: any = {
id: '1',
'allowed-updates': [
{
'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()
Expand Down
10 changes: 2 additions & 8 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -39,7 +33,7 @@ export type Credential = {
token?: string
}

export class APIClient {
export class ApiClient {
constructor(
private readonly client: AxiosInstance,
readonly params: JobParameters
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function run(context: Context): Promise<void> {
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')
Expand Down Expand Up @@ -86,7 +86,7 @@ export async function run(context: Context): Promise<void> {
}

async function failJob(
apiClient: APIClient,
apiClient: ApiClient,
error: Error,
errorType = DependabotErrorType.Unknown
): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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[]
) {
Expand Down

0 comments on commit 5f7342f

Please sign in to comment.