Skip to content

Commit

Permalink
fix(pmp): change fullName to Url in addRepo
Browse files Browse the repository at this point in the history
create util files for name extraction
  • Loading branch information
artix1500 authored and Sikora00 committed Apr 10, 2020
1 parent e500869 commit a7a5267
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 3 deletions.
26 changes: 26 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,32 @@
"styleext": "scss"
}
}
},
"server-shared-util-repository": {
"projectType": "library",
"root": "libs/server/shared/util-repository",
"sourceRoot": "libs/server/shared/util-repository/src",
"prefix": "pimp-my-pr",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"libs/server/shared/util-repository/tsconfig.lib.json",
"libs/server/shared/util-repository/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**", "!libs/server/shared/util-repository/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/server/shared/util-repository/jest.config.js",
"tsConfig": "libs/server/shared/util-repository/tsconfig.spec.json"
}
}
},
"schematics": {}
}
},
"cli": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@pimp-my-pr/server/repository/core/application-services';
import { AddRepositoryDto } from '../dtos/add-repository.dto';
import { RepositoryEntity } from '@pimp-my-pr/server/repository/core/domain';
import { extractFullName } from '@pimp-my-pr/server/shared/util-repository';

@ApiTags('repository')
@Controller('repository')
Expand All @@ -21,7 +22,7 @@ export class RepositoryController {
addRepository(@Body() addRepositoryDto: AddRepositoryDto): Promise<void> {
return this.repositoryFacade.addRepository(
new AddRepositoryCommand(
addRepositoryDto.repositoryName,
extractFullName(addRepositoryDto.repositoryUrl),
addRepositoryDto.maxLines,
addRepositoryDto.maxWaitingTime
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';

export class AddRepositoryDto {
@ApiProperty()
repositoryName: string;
repositoryUrl: string;

@ApiProperty()
maxLines?: number;
Expand Down
7 changes: 7 additions & 0 deletions libs/server/shared/util-repository/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# server-shared-utils

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test server-shared-utils` to execute the unit tests.
9 changes: 9 additions & 0 deletions libs/server/shared/util-repository/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
name: 'server-shared-utils',
preset: '../../../../jest.config.js',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
coverageDirectory: '../../../../coverage/libs/server/shared/utils'
};
1 change: 1 addition & 0 deletions libs/server/shared/util-repository/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/name-extract/repository-name-extract.util';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { URL } from 'url';

const allowedDomains = ['github', 'bitbucket'];

function isHostAllowed(host: string): boolean {
return allowedDomains.reduce((accumulator, currentValue) => {
if (accumulator) return accumulator;
return host.includes(currentValue);
}, false);
}

export function extractFullName(repoUrl: string): string {
const url = new URL(repoUrl);
if (isHostAllowed(url.host)) {
const pathArr = url.pathname.slice(1).split('/');
if (pathArr.length > 1) {
return `${pathArr[0]}/${pathArr[1]}`;
}
}
return '';
}
7 changes: 7 additions & 0 deletions libs/server/shared/util-repository/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": ["**/*.ts"]
}
9 changes: 9 additions & 0 deletions libs/server/shared/util-repository/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../../dist/out-tsc",
"types": []
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"]
}
9 changes: 9 additions & 0 deletions libs/server/shared/util-repository/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js", "**/*.spec.jsx", "**/*.d.ts"]
}
1 change: 1 addition & 0 deletions libs/server/shared/util-repository/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "../../../../tslint.json", "rules": [] }
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
},
"server-repository-core-domain-services": {
"tags": ["platform:server", "scope:repository", "type:domain-services"]
},
"server-shared-util-repository": {
"tags": ["platform:server", "scope:shared", "type:util"]
}
}
}
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
],
"@pimp-my-pr/pmp-web/repository/repository-settings/feature": [
"libs/pmp-web/repository/repository-settings/feature/src/index.ts"
],
"@pimp-my-pr/server/shared/util-repository": [
"libs/server/shared/util-repository/src/index.ts"
]
}
},
Expand Down
7 changes: 6 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@
},
{
"sourceTag": "type:api",
"onlyDependOnLibsWithTags": ["type:application-services", "type:domain", "type:shell"]
"onlyDependOnLibsWithTags": [
"type:application-services",
"type:domain",
"type:shell",
"type:util"
]
},
{
"sourceTag": "type:application",
Expand Down

0 comments on commit a7a5267

Please sign in to comment.