diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.test.ts index 0b3057f97e..b836a592ee 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.test.ts @@ -60,6 +60,30 @@ describe('GithubReaderProcessor', () => { }); it('should return request options', () => { - // todo + const tests = [ + { + token: '0123456789', + expect: { + headers: { + Accept: 'application/vnd.github.v3.raw', + Authorization: 'token 0123456789', + }, + }, + }, + { + token: '', + expect: { + headers: { + Accept: 'application/vnd.github.v3.raw', + }, + }, + }, + ]; + + for (const test of tests) { + process.env.GITHUB_PRIVATE_TOKEN = test.token; + const processor = new GithubReaderProcessor(); + expect(processor.getRequestOptions()).toEqual(test.expect); + } }); }); diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts index 11610234bd..a0e089aaae 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts @@ -19,15 +19,16 @@ import fetch, { RequestInit, HeadersInit } from 'node-fetch'; import * as result from './results'; import { LocationProcessor, LocationProcessorEmit } from './types'; -const privateToken: string = process.env.GITHUB_PRIVATE_TOKEN || ''; - export class GithubReaderProcessor implements LocationProcessor { + private privateToken: string = process.env.GITHUB_PRIVATE_TOKEN || ''; + getRequestOptions(): RequestInit { const headers: HeadersInit = { Accept: 'application/vnd.github.v3.raw', }; - if (privateToken) { - headers.Authorization = `token ${privateToken}`; + + if (this.privateToken !== '') { + headers.Authorization = `token ${this.privateToken}`; } const requestOptions: RequestInit = {