Skip to content

Commit

Permalink
feat(config): add github token config
Browse files Browse the repository at this point in the history
we should use a github app authentication, but for now, this is fine while we develop this. Later,
we should have the github app, but that's complicated enough to be it's own pull request
  • Loading branch information
thatkookooguy committed May 6, 2021
1 parent acaa7df commit c339c30
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion env.schema.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"properties":{"port":{"description":"Set server port","type":"number"},"dbUrl":{"description":"DB connection URL. Expects a mongodb db for connections","format":"url","type":"string"},"webhookProxyUrl":{"description":"Used to create a custom repeatable smee webhook url instead of Generating a random one","format":"url","type":"string","pattern":"^https:\\/\\/(?:www\\.)?smee\\.io\\/[a-zA-Z0-9_-]+\\/?"},"webhookDestinationUrl":{"description":"proxy should sent events to this url for achievibit","pattern":"^([\\w]+)?(\\/[\\w-]+)*$","type":"string"},"saveToFile":{"description":"Create a file made out of the internal config. This is mostly for merging command line, environment, and file variables to a single instance","type":"boolean"},"deletePRsHealthId":{"description":"cron job monitoring id","type":"string"}},"type":"object","required":["port","webhookProxyUrl","webhookDestinationUrl","saveToFile"]}
{"properties":{"port":{"description":"Set server port","type":"number"},"dbUrl":{"description":"DB connection URL. Expects a mongodb db for connections","format":"url","type":"string"},"webhookProxyUrl":{"description":"Used to create a custom repeatable smee webhook url instead of Generating a random one","format":"url","type":"string","pattern":"^https:\\/\\/(?:www\\.)?smee\\.io\\/[a-zA-Z0-9_-]+\\/?"},"webhookDestinationUrl":{"description":"proxy should sent events to this url for achievibit","pattern":"^([\\w]+)?(\\/[\\w-]+)*$","type":"string"},"saveToFile":{"description":"Create a file made out of the internal config. This is mostly for merging command line, environment, and file variables to a single instance","type":"boolean"},"deletePRsHealthId":{"description":"cron job monitoring id","type":"string"},"githubAccessToken":{"description":"GitHub Access Token","type":"string"}},"type":"object","required":["port","webhookProxyUrl","webhookDestinationUrl","saveToFile"]}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`ConfigService Forced Singleton and baypass should set default values to
Object {
"dbUrl": undefined,
"deletePRsHealthId": undefined,
"githubAccessToken": undefined,
"nodeEnv": "development",
"port": 10101,
"webhookDestinationUrl": "events",
Expand Down
8 changes: 8 additions & 0 deletions server/src/config/achievibit-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export class AchievibitConfig {
])
deletePRsHealthId;

@Expose()
@IsString()
@IsOptional()
@Validate(JsonSchema, [
'GitHub Access Token'
])
githubAccessToken: string;

constructor(partial: Partial<AchievibitConfig> = {}) {
Object.assign(this, partial);
}
Expand Down
20 changes: 5 additions & 15 deletions server/src/config/config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
} from './achievibit-config.model';
import { ConfigService } from './config.service';

// not a jest component so testing it as a node module
// TODO@Thatkookooguy: #354 manual mock this to test events when created
jest.mock('smee-client');

// testing it as a node module and not as a nestjs component
describe('ConfigService', () => {

describe('Forced Singleton and baypass', () => {
Expand All @@ -21,10 +24,6 @@ describe('ConfigService', () => {
});
});

afterEach(() => {
configService.closeEvents();
});

it('should be defined', () => {
expect(configService).toBeDefined();
});
Expand Down Expand Up @@ -52,8 +51,6 @@ describe('ConfigService', () => {

expect(productionService.smee).toBeUndefined();
expect(productionService.events).toBeUndefined();

productionService.closeEvents();
});

it('should initial smee and events on development', () => {
Expand All @@ -62,9 +59,7 @@ describe('ConfigService', () => {
});

expect(productionService.smee).toBeDefined();
expect(productionService.events).toBeDefined();

productionService.closeEvents();
expect(productionService.smee.start).toHaveBeenCalledTimes(1);
});
});

Expand All @@ -81,8 +76,6 @@ describe('ConfigService', () => {
const serviceWrapper = () => new ConfigService({ nodeEnv });

expect(serviceWrapper().toPlainObject).toBeDefined();

serviceWrapper().closeEvents();
});
})
.value();
Expand Down Expand Up @@ -133,8 +126,6 @@ describe('ConfigService', () => {
const service = new ConfigService({ dbUrl: undefined });

expect(service.dbUrl).toBeUndefined();

service.closeEvents();
});

it('should ACCEPT localhost mongodb URL', () => {
Expand Down Expand Up @@ -178,7 +169,6 @@ describe('ConfigService', () => {
webhookProxyUrl: smeeProtocolUrl
}))
.forEach((configService, smeeProtocolUrl) => {
configService.closeEvents();
expect(configService.webhookProxyUrl).toBe(smeeProtocolUrl);
})
.value();
Expand Down
4 changes: 3 additions & 1 deletion server/src/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const appRoot = findRoot(__dirname, (dir) => {
const environment = get(process, 'env.NODE_ENV', 'development');
const eventLogger: Logger = new Logger('SmeeEvents');
(eventLogger as any).info = eventLogger.log;
const defaultConfigFilePath = join(appRoot, 'defaults.env.json');
const configFilePath = join(appRoot, `${ environment }.env.json`);

const packageDetails = new ApiInfo(readJSONSync(join(appRoot, 'package.json')));
Expand All @@ -49,7 +50,8 @@ nconf
parseValues: true,
transform: transformToLowerCase
})
.file({ file: configFilePath });
.file('defaults', { file: defaultConfigFilePath })
.file('environment', { file: configFilePath });

let smee: SmeeClient;
let events: any;
Expand Down

0 comments on commit c339c30

Please sign in to comment.