Skip to content

Commit 60d6757

Browse files
committed
#291 : update type and implement score poc
1 parent 4002017 commit 60d6757

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

api/src/core/adapters/dbApi/kysely/createPgSoftwareRepository.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ParentSoftwareExternalData } from "../../../ports/GetSoftwareExternalDa
66
import { Software } from "../../../usecases/readWriteSillData";
77
import { Database } from "./kysely.database";
88
import { stripNullOrUndefinedValues, jsonBuildObject } from "./kysely.utils";
9+
import { SILL } from "../../../../types/SILL";
910

1011
const dateParser = (str: string | Date | undefined | null) => {
1112
if (str && typeof str === "string") {
@@ -17,6 +18,19 @@ const dateParser = (str: string | Date | undefined | null) => {
1718
}
1819
};
1920

21+
const computeRepoMetadata = (repoMetadata: SILL.RepoMetadata | undefined | null): SILL.RepoMetadata | undefined => {
22+
const newMedata = repoMetadata;
23+
if (!newMedata || !newMedata.healthCheck) return undefined;
24+
25+
let score = 0;
26+
if (repoMetadata.healthCheck?.lastClosedIssue) score += 1;
27+
if (repoMetadata.healthCheck?.lastClosedIssuePullRequest) score += 1;
28+
if (repoMetadata.healthCheck?.lastCommit) score += 1;
29+
newMedata.healthCheck.score = score / 3;
30+
31+
return newMedata;
32+
};
33+
2034
export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareRepository => {
2135
const getBySoftwareId = makeGetSoftwareById(db);
2236
return {
@@ -189,7 +203,7 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
189203
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
190204
referencePublications: softwareExternalData?.referencePublications,
191205
identifiers: softwareExternalData?.identifiers,
192-
repoMetadata: softwareExternalData?.repoMetadata,
206+
repoMetadata: computeRepoMetadata(softwareExternalData?.repoMetadata),
193207
applicationCategories: software.categories.concat(
194208
softwareExternalData?.applicationCategories ?? []
195209
),
@@ -294,7 +308,7 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
294308
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
295309
referencePublications: softwareExternalData?.referencePublications,
296310
identifiers: softwareExternalData?.identifiers,
297-
repoMetadata: softwareExternalData?.repoMetadata
311+
repoMetadata: computeRepoMetadata(softwareExternalData?.repoMetadata)
298312
});
299313
}
300314
);
@@ -564,7 +578,7 @@ const makeGetSoftwareById =
564578
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
565579
referencePublications: softwareExternalData?.referencePublications,
566580
identifiers: softwareExternalData?.identifiers,
567-
repoMetadata: softwareExternalData?.repoMetadata,
581+
repoMetadata: computeRepoMetadata(softwareExternalData?.repoMetadata),
568582
applicationCategories: filterDuplicate(
569583
software.categories.concat(softwareExternalData?.applicationCategories ?? [])
570584
),

api/src/core/adapters/dbApi/kysely/kysely.database.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,7 @@ type SoftwareExternalDatasTable = {
9797
referencePublications: JSONColumnType<SILL.ScholarlyArticle[]> | null;
9898
publicationTime: Date | null;
9999
identifiers: JSONColumnType<SILL.Identification[]> | null;
100-
repoMetadata: JSONColumnType<{
101-
healthCheck?: {
102-
lastCommit?: number;
103-
lastClosedIssue?: number;
104-
lastClosedIssuePullRequest?: number;
105-
};
106-
}> | null;
100+
repoMetadata: JSONColumnType<SILL.RepoMetadata> | null;
107101
};
108102

109103
type SoftwareType =

api/src/core/adapters/hal/getHalSoftwareExternalData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
228228
const lastMergeRequest = await apiProject.mergeRequests.getLast();
229229
return {
230230
healthCheck: {
231-
lastCommit: lastCommit ? new Date(lastCommit.created_at) : undefined,
231+
lastCommit: lastCommit ? new Date(lastCommit.created_at).valueOf() : undefined,
232232
lastClosedIssue:
233-
lastIssue && lastIssue.closed_at ? new Date(lastIssue.closed_at) : undefined,
233+
lastIssue && lastIssue.closed_at ? new Date(lastIssue.closed_at).valueOf() : undefined,
234234
lastClosedIssuePullRequest: lastMergeRequest
235-
? new Date(lastMergeRequest.updated_at)
235+
? new Date(lastMergeRequest.updated_at).valueOf()
236236
: undefined
237237
}
238238
};

api/src/core/ports/GetSoftwareExternalData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export type SoftwareExternalData = {
3535
identifiers: SILL.Identification[];
3636
repoMetadata?: {
3737
healthCheck?: {
38-
lastCommit?: Date;
39-
lastClosedIssue?: Date;
40-
lastClosedIssuePullRequest?: Date;
38+
lastCommit?: number;
39+
lastClosedIssue?: number;
40+
lastClosedIssuePullRequest?: number;
4141
};
4242
};
4343
}>;

api/src/core/usecases/readWriteSillData/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export type Software = {
6161
programmingLanguages: string[];
6262
referencePublications?: SILL.ScholarlyArticle[];
6363
identifiers?: SILL.Identification[];
64+
repoMetadata?: SILL.RepoMetadata;
6465
};
6566

6667
export namespace Software {

api/src/types/SILL.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,14 @@ export namespace SILL {
6060
url?: string;
6161
affiliations?: Organization[];
6262
};
63+
64+
// Created from nowhere
65+
export type RepoMetadata = {
66+
healthCheck?: {
67+
score?: number;
68+
lastCommit?: number;
69+
lastClosedIssue?: number;
70+
lastClosedIssuePullRequest?: number;
71+
};
72+
};
6373
}

0 commit comments

Comments
 (0)