11import { captureException , cron } from "@sentry/node" ;
22
33import { ContributionRepository } from "src/contribution/repository" ;
4+ import { ContributionRow } from "src/contribution/table" ;
45import { ContributorRepository } from "src/contributor/repository" ;
6+ import { ContributorRow } from "src/contributor/table" ;
57import { CronJob } from "cron" ;
68import { DataService } from "src/data/service" ;
79import { GithubService } from "src/github/service" ;
810import { LoggerService } from "src/logger/service" ;
911import { ProjectRepository } from "src/project/repository" ;
12+ import { ProjectRow } from "src/project/table" ;
1013import { RepositoryRepository } from "src/repository/repository" ;
1114import { SearchService } from "src/search/service" ;
1215import { Service } from "typedi" ;
@@ -70,10 +73,10 @@ export class DigestCron {
7073 const projectsFromDataFolder = await this . dataService . listProjects ( ) ;
7174
7275 for ( const project of projectsFromDataFolder ) {
73- const projectEntity = {
74- ...project ,
76+ const projectEntity : ProjectRow = {
7577 runId,
76- id : project . slug . replace ( / [ . ] / g, "-" ) , // MeiliSearch doesn't allow dots in ids,
78+ id : project . slug . replace ( / [ . ] / g, "-" ) , // NOTE-OB: MeiliSearch doesn't allow dots in ids
79+ name : project . name ,
7780 } ;
7881 const [ { id : projectId } ] =
7982 await this . projectsRepository . upsert ( projectEntity ) ;
@@ -114,7 +117,7 @@ export class DigestCron {
114117
115118 if ( githubUser . type !== "User" ) continue ;
116119
117- const contributorEntity = {
120+ const contributorEntity : ContributorRow = {
118121 name : githubUser . name || githubUser . login ,
119122 username : githubUser . login ,
120123 url : githubUser . html_url ,
@@ -135,7 +138,7 @@ export class DigestCron {
135138 } ) ;
136139
137140 const type = issue . pull_request ? "PULL_REQUEST" : "ISSUE" ;
138- const contributionEntity = {
141+ const contributionEntity : ContributionRow = {
139142 title : issue . title ,
140143 type,
141144 updatedAt : issue . updated_at ,
@@ -170,15 +173,17 @@ export class DigestCron {
170173 const contributor = await this . githubService . getUser ( {
171174 username : repoContributor . login ,
172175 } ) ;
176+ const contributorEntity : ContributorRow = {
177+ name : contributor . name || contributor . login ,
178+ username : contributor . login ,
179+ url : contributor . html_url ,
180+ avatarUrl : contributor . avatar_url ,
181+ runId,
182+ id : `${ provider } -${ contributor . login } ` ,
183+ } ;
173184 const [ { id : contributorId } ] =
174- await this . contributorsRepository . upsert ( {
175- name : contributor . name || contributor . login ,
176- username : contributor . login ,
177- url : contributor . html_url ,
178- avatarUrl : contributor . avatar_url ,
179- runId,
180- id : `${ provider } -${ contributor . login } ` ,
181- } ) ;
185+ await this . contributorsRepository . upsert ( contributorEntity ) ;
186+ await this . searchService . upsert ( "contributor" , contributorEntity ) ;
182187
183188 await this . contributorsRepository . upsertRelationWithRepository ( {
184189 contributorId,
@@ -209,9 +214,11 @@ export class DigestCron {
209214 await this . contributorsRepository . deleteAllButWithRunId ( runId ) ;
210215 await this . repositoriesRepository . deleteAllButWithRunId ( runId ) ;
211216 await this . projectsRepository . deleteAllButWithRunId ( runId ) ;
212- await this . searchService . deleteAllButWithRunId ( "project" , runId ) ;
213- await this . searchService . deleteAllButWithRunId ( "contribution" , runId ) ;
214- await this . searchService . deleteAllButWithRunId ( "contributor" , runId ) ;
217+ await Promise . all ( [
218+ this . searchService . deleteAllButWithRunId ( "project" , runId ) ,
219+ this . searchService . deleteAllButWithRunId ( "contribution" , runId ) ,
220+ this . searchService . deleteAllButWithRunId ( "contributor" , runId ) ,
221+ ] ) ;
215222 } catch ( error ) {
216223 captureException ( error , { tags : { type : "CRON" } } ) ;
217224 }
0 commit comments