Skip to content

Add new command to collect data on mainline #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"typescript": "^4.1.2"
},
"dependencies": {
"@codecoach/api-client": "^1.0.45",
"@octokit/core": "^3.2.4",
"@octokit/rest": "^18.12.0",
"js-yaml": "^4.1.0",
Expand Down
11 changes: 11 additions & 0 deletions sample/config/data-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repo:
url: https://github.com/codeleague/codecoach
runId: 40
headCommit: 123qwe123qwe123qwe123qwe123qwe123qwe123q
branch: main
buildLogFiles:
- type: tslint
path: /path/to/log.json
cwd: /repo/src
output: ./output.json
apiServer: https://localhost:3000
16 changes: 16 additions & 0 deletions src/Api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import axios from 'axios';

import { RunApi } from '@codecoach/api-client';

export class Api {
private readonly axiosInstance;
constructor(private readonly apiServer: string) {
this.axiosInstance = axios.create({
baseURL: this.apiServer,
});
}

get runClient(): RunApi {
return new RunApi(undefined, '', this.axiosInstance);
}
}
4 changes: 4 additions & 0 deletions src/Config/@enums/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum COMMAND {
DEFAULT = 'default',
COLLECT = 'collect',
}
1 change: 1 addition & 0 deletions src/Config/@enums/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { ProjectType } from './projectType';
export { COMMAND } from './command';
3 changes: 3 additions & 0 deletions src/Config/@types/appConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { COMMAND } from '../@enums';
import { BuildLogFile } from './buildLogFile';

export type AppConfig = {
command: COMMAND;
logFilePath: string;
buildLogFiles: BuildLogFile[];
apiServer: string;
};
21 changes: 17 additions & 4 deletions src/Config/@types/configArgument.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { BuildLogFile } from './buildLogFile';

export type ConfigArgument = {
type BaseConfigArgument = {
url: string;
pr: number;
buildLogFile: BuildLogFile[];
output: string;
token: string;
removeOldComment: boolean;
config: string;
};

export type PrConfigArgument = {
pr: number;
removeOldComment: boolean;
token: string;
apiServer: never;
} & BaseConfigArgument;

export type DataConfigArgument = {
headCommit: string;
runId: number;
branch: string;
apiServer: string;
} & BaseConfigArgument;

export type ConfigArgument = PrConfigArgument | DataConfigArgument;
25 changes: 21 additions & 4 deletions src/Config/@types/configYAML.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { BuildLogFile } from './buildLogFile';

export type ConfigYAML = {
type BaseConfigYAML = {
repo: {
url: string;
pr: number;
token: string;
userAgent: string;
timeZone: string;
removeOldComment: boolean;
};
buildLogFiles: BuildLogFile[];
output: string;
};

export type PrConfigYAML = {
repo: {
token: string;
pr: number;
removeOldComment: boolean;
};
apiServer: never;
} & BaseConfigYAML;

export type DataConfigYAML = {
repo: {
headCommit: string;
runId: number;
branch: string;
};
apiServer: string;
} & BaseConfigYAML;

export type ConfigYAML = PrConfigYAML | DataConfigYAML;
5 changes: 3 additions & 2 deletions src/Config/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { AppConfig } from './appConfig';
export { ConfigObject } from './configObject';
export { ProviderConfig } from './providerConfig';
export { ConfigArgument } from './configArgument';
export * from './providerConfig';
export * from './configArgument';
export * from './configYAML';
export { BuildLogFile } from './buildLogFile';
17 changes: 14 additions & 3 deletions src/Config/@types/providerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
export type ProviderConfig = {
token: string;
type BaseProviderConfig = {
repoUrl: string;
};

export type PrProviderConfig = {
token: string;
prId: number;
removeOldComment: boolean;
};
} & BaseProviderConfig;

export type DataProviderConfig = {
runId: number;
headCommit: string;
branch: string;
} & BaseProviderConfig;

export type ProviderConfig = PrProviderConfig | DataProviderConfig;
93 changes: 85 additions & 8 deletions src/Config/Config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DataProviderConfig, PrProviderConfig } from '.';
import { Config } from './Config';

const MOCK_ARGS = [
const PR_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'--url=https://github.com/codeleague/codecoach.git',
Expand All @@ -11,13 +12,25 @@ const MOCK_ARGS = [
'-o=./tmp/out.json',
];

const MOCK_ARGS_W_CONFIG_YAML = [
const PR_MOCK_ARGS_W_COMMAND = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'comment',
'--url=https://github.com/codeleague/codecoach.git',
'--removeOldComment',
'--token=placeyourtokenhere',
'--pr=15',
'-f=dotnetbuild;./sample/dotnetbuild/build.content;/repo/src',
'-o=./tmp/out.json',
];

const PR_MOCK_ARGS_W_CONFIG_YAML = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'--config=sample/config/config.yaml',
];

export const EXPECTED_MOCK_ARGS = [
export const PR_EXPECTED_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'https://github.com/codeleague/codecoach.git',
Expand All @@ -28,23 +41,87 @@ export const EXPECTED_MOCK_ARGS = [
'./tmp/out.json',
];

describe('Config Test', () => {
const DATA_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'collect',
'--url=https://github.com/codeleague/codecoach.git',
'-r=3',
'-b=main',
'-c=headCommitsha',
'-f=dotnetbuild;./sample/dotnetbuild/build.content;/repo/src',
'-o=./tmp/out.json',
'--api=https://localhost:3000',
];

const DATA_MOCK_ARGS_W_CONFIG_YAML = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'collect',
'--config=sample/config/data-config.yaml',
];

export const DATA_EXPECTED_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'https://github.com/codeleague/codecoach.git',
3,
'main',
'headCommitsha',
'dotnetbuild;./sample/dotnetbuild/build.content;/repo/src',
'./tmp/out.json',
'https://localhost:3000',
];

describe('PR config Test', () => {
let config: typeof Config;

beforeEach(() => {
jest.resetModules();
});

it('Should able to parse this args and run without throwing error', async () => {
process.argv = MOCK_ARGS;
process.argv = PR_MOCK_ARGS;
config = (await import('./Config')).Config;
let fullfillConfig = (await config).provider as PrProviderConfig;
expect(fullfillConfig.repoUrl).toBe(PR_EXPECTED_MOCK_ARGS[2]);
expect(fullfillConfig.removeOldComment).toBe(PR_EXPECTED_MOCK_ARGS[3]);

process.argv = PR_MOCK_ARGS_W_COMMAND;
config = (await import('./Config')).Config;
fullfillConfig = (await config).provider as PrProviderConfig;
expect(fullfillConfig.repoUrl).toBe(PR_EXPECTED_MOCK_ARGS[2]);
expect(fullfillConfig.removeOldComment).toBe(PR_EXPECTED_MOCK_ARGS[3]);
});

it('Should able to use a config file without passing other args', async () => {
process.argv = PR_MOCK_ARGS_W_CONFIG_YAML;
config = (await import('./Config')).Config;
const fullfillConfig = await config;
expect(fullfillConfig.provider.repoUrl).toBe(EXPECTED_MOCK_ARGS[2]);
expect(fullfillConfig.provider.removeOldComment).toBe(EXPECTED_MOCK_ARGS[3]);
expect(fullfillConfig.app.buildLogFiles[0].type).toBe('tslint');
});
});

describe('Data config Test', () => {
let config: typeof Config;

beforeEach(() => {
jest.resetModules();
});

it('Should able to parse this args and run without throwing error', async () => {
process.argv = DATA_MOCK_ARGS;
config = (await import('./Config')).Config;
const providerConfig = (await config).provider as DataProviderConfig;
expect(providerConfig.repoUrl).toBe(DATA_EXPECTED_MOCK_ARGS[2]);
expect(providerConfig.runId).toBe(DATA_EXPECTED_MOCK_ARGS[3]);
expect(providerConfig.branch).toBe(DATA_EXPECTED_MOCK_ARGS[4]);
expect(providerConfig.headCommit).toBe(DATA_EXPECTED_MOCK_ARGS[5]);
expect((await config).app.apiServer).toBe(DATA_EXPECTED_MOCK_ARGS[8]);
});

it('Should able to use a config file without passing other args', async () => {
process.argv = MOCK_ARGS_W_CONFIG_YAML;
process.argv = DATA_MOCK_ARGS_W_CONFIG_YAML;
config = (await import('./Config')).Config;
const fullfillConfig = await config;
expect(fullfillConfig.app.buildLogFiles[0].type).toBe('tslint');
Expand Down
Loading