Skip to content
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

feat: oso implementation for projects #2028

Merged
merged 6 commits into from
Dec 20, 2024
Merged
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
3 changes: 2 additions & 1 deletion apps/web-api/prisma/fixtures/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const ProjectFactory = Factory.define<Omit<Project, 'id'>>(
}],
createdAt: faker.date.past(),
updatedAt: faker.date.recent(),
isDeleted: false
isDeleted: false,
osoProjectName: faker.random.word(),
};
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Project" ADD COLUMN "osoProjectName" TEXT;
176 changes: 176 additions & 0 deletions apps/web-api/prisma/oso-schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
generator client {
provider = "prisma-client-js"
output= "../../../node_modules/.prisma/oso-client"
}

datasource db {
provider = "postgresql"
url = env("OSO_DATABASE_URL")
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model artifacts_v1 {
artifact_id String?
artifact_name String?
artifact_namespace String?
artifact_source String?
artifact_source_id String?
artifact_url String?
created_at DateTime @default(now()) @db.Timestamp(6)

@@ignore
}

model code_metrics_by_project_v1 {
active_developer_count_6_months Float?
closed_issue_count_6_months Float?
commit_count_6_months Float?
contributor_count Float?
contributor_count_6_months Float?
display_name String?
event_source String?
first_commit_date String?
fork_count Int?
fulltime_developer_average_6_months Float?
last_commit_date String?
merged_pull_request_count_6_months Float?
new_contributor_count_6_months Float?
opened_issue_count_6_months Float?
opened_pull_request_count_6_months Float?
project_id String @id
project_name String?
project_namespace String?
project_source String?
repository_count Int?
star_count Int?
created_at DateTime @default(now()) @db.Timestamp(6)
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model collections_v1 {
collection_id String?
collection_name String?
collection_namespace String?
collection_source String?
description String?
display_name String?
created_at DateTime @default(now()) @db.Timestamp(6)

@@ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model oso_artifactsV1 {
artifactId String?
artifactName String?
artifactNamespace String?
artifactSource String?
artifactSourceId String?
artifactUrl String?

@@ignore
}

model oso_codeMetricsByProjectV1 {
activeDeveloperCount6Months Int?
closedIssueCount6Months Int?
commitCount6Months Int?
contributorCount Int?
contributorCount6Months Int?
displayName String?
eventSource String?
firstCommitDate String?
forkCount String?
fulltimeDeveloperAverage6Months Float?
lastCommitDate String?
mergedPullRequestCount6Months Int?
newContributorCount6Months Int?
openedIssueCount6Months Int?
openedPullRequestCount6Months Int?
projectId String @id(map: "oso_codemetricsbyprojectv1_pkey")
projectName String?
projectNamespace String?
projectSource String?
repositoryCount String?
starCount String?
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model oso_collectionsV1 {
collectionId String?
collectionName String?
collectionNamespace String?
collectionSource String?
description String?
displayName String?

@@ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model oso_projectsByCollectionV1 {
collectionId String?
collectionName String?
collectionNamespace String?
collectionSource String?
projectId String?
projectName String?
projectNamespace String?
projectSource String?

@@ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model oso_projectsV1 {
description String?
displayName String?
projectId String?
projectName String?
projectNamespace String?
projectSource String?

@@ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model projects_by_collection_v1 {
collection_id String?
collection_name String?
collection_namespace String?
collection_source String?
project_id String?
project_name String?
project_namespace String?
project_source String?
created_at DateTime @default(now()) @db.Timestamp(6)

@@ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model projects_v1 {
description String?
display_name String?
project_id String?
project_name String?
project_namespace String?
project_source String?
created_at DateTime @default(now()) @db.Timestamp(6)

@@ignore
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model users_v1 {
bio String?
display_name String?
profile_picture_url String?
url String?
user_id String?
user_source String?
user_source_id String?
created_at DateTime @default(now()) @db.Timestamp(6)

@@ignore
}
1 change: 1 addition & 0 deletions apps/web-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ model Project {
updatedAt DateTime @updatedAt
isDeleted Boolean @default(false)
isFeatured Boolean? @default(false)
osoProjectName String?
projectFocusAreas ProjectFocusArea[]
contributions ProjectContribution[]
relatedQuestions DiscoveryQuestion[] @relation("ProjectRelatedDiscoveryQuestions")
Expand Down
4 changes: 3 additions & 1 deletion apps/web-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { MemberFeedbacksModule } from './member-feedbacks/member-feedbacks.modul
import { HuskyModule } from './husky/husky.module';
import { HomeModule } from './home/home.module';
import { InternalsModule } from './internals/internals.module';
import { OsoMetricsModule } from './oso-metrics/oso-metrics.module';

@Module({
controllers: [AppController],
Expand Down Expand Up @@ -96,7 +97,8 @@ import { InternalsModule } from './internals/internals.module';
MemberFeedbacksModule,
HuskyModule,
HomeModule,
InternalsModule
InternalsModule,
OsoMetricsModule,
],
providers: [
{
Expand Down
20 changes: 20 additions & 0 deletions apps/web-api/src/oso-metrics/oso-metrics.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { OsoCodeMetricsByProjectV1Controller } from './oso-metrics.controller';
import { OsoCodeMetricsByProjectV1Service } from './oso-metrics.service';

describe('OsoCodeMetricsByProjectV1Controller', () => {
let controller: OsoCodeMetricsByProjectV1Controller;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [OsoCodeMetricsByProjectV1Controller],
providers: [OsoCodeMetricsByProjectV1Service],
}).compile();

controller = module.get<OsoCodeMetricsByProjectV1Controller>(OsoCodeMetricsByProjectV1Controller);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
17 changes: 17 additions & 0 deletions apps/web-api/src/oso-metrics/oso-metrics.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Controller, Get, Param } from '@nestjs/common';
import { OsoMetricsService } from './oso-metrics.service';

@Controller('v1/oso-metrics')
export class OsoMetricsController {
constructor(private readonly osoMetricsService: OsoMetricsService) {}

@Get()
findAll() {
return this.osoMetricsService.findAll();
}

@Get(':name')
findOne(@Param('name') name: string) {
return this.osoMetricsService.findOne(name);
}
}
10 changes: 10 additions & 0 deletions apps/web-api/src/oso-metrics/oso-metrics.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { OsoMetricsService } from './oso-metrics.service';
import { OsoMetricsController } from './oso-metrics.controller';

@Module({
controllers: [OsoMetricsController],
providers: [OsoMetricsService],
exports: [OsoMetricsService],
})
export class OsoMetricsModule {}
18 changes: 18 additions & 0 deletions apps/web-api/src/oso-metrics/oso-metrics.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { OsoMetricsService } from './oso-metrics.service';

describe('OsoMetricsService', () => {
let service: OsoMetricsService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [OsoMetricsService],
}).compile();

service = module.get<OsoMetricsService>(OsoMetricsService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
37 changes: 37 additions & 0 deletions apps/web-api/src/oso-metrics/oso-metrics.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
BadRequestException,
ConflictException,
Injectable,
InternalServerErrorException,
NotFoundException,
} from '@nestjs/common';
import { OsoPrismaService } from '../shared/oso-prisma.service';
import { LogService } from '../shared/log.service';
import { Prisma } from '@prisma/client';

@Injectable()
export class OsoMetricsService {
constructor(private prisma: OsoPrismaService, private logger: LogService) {}

findAll() {
try {
return this.prisma.oso_codeMetricsByProjectV1.findMany();
} catch (error) {
throw new InternalServerErrorException(`Error occured while retrieving project metrics data: ${error.message}`);
}
}

async findOne(displayName: string) {
try {
const metric = await this.prisma.oso_codeMetricsByProjectV1.findFirst({
where: { displayName },
});
if (!metric) {
throw new NotFoundException(`Metric with display name "${displayName}" not found.`);
}
return metric;
} catch (error) {
throw new InternalServerErrorException(`Error occured while retrieving project metrics data: ${error.message}`);
}
}
}
19 changes: 19 additions & 0 deletions apps/web-api/src/shared/oso-prisma.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '.prisma/oso-client';

@Injectable()
export class OsoPrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
try {
await this.$connect();
} catch (error) {
throw error;
}
}

async enableShutdownHooks(app: INestApplication) {
this.$on('beforeExit', async () => {
await app.close();
});
}
}
3 changes: 3 additions & 0 deletions apps/web-api/src/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Global, Logger, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
import { OsoPrismaService } from './oso-prisma.service';
import { LogService } from './log.service';
import { ForestAdminService } from '../utils/forest-admin/forest-admin.service';
import { AwsService } from '../utils/aws/aws.service';
Expand All @@ -16,6 +17,7 @@ import { CacheService } from '../utils/cache/cache.service';
@Module({
providers: [
PrismaService,
OsoPrismaService,
LogService,
Logger,
ForestAdminService,
Expand All @@ -31,6 +33,7 @@ import { CacheService } from '../utils/cache/cache.service';
],
exports: [
PrismaService,
OsoPrismaService,
LogService,
ForestAdminService,
AwsService,
Expand Down
3 changes: 2 additions & 1 deletion libs/contracts/src/schema/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const ProjectSchema = z.object({
title: z.string()
}).array().optional(),
contributions: ContributionSchema.array().optional(),
isDeleted: z.boolean().default(false)
isDeleted: z.boolean().default(false),
osoProjectName: z.string().optional(),
});

export const ResponseProjectSchema = ProjectSchema.omit({ id: true }).strict();
Expand Down
Loading