Skip to content

Commit

Permalink
feat(alert-cli): ajout du support des fiche-sp au niveau des contribu…
Browse files Browse the repository at this point in the history
…tions (#1205)

* one

* one

* one

* one

* one

* one

* Update targets/frontend/src/components/changes/ChangesFicheSp.tsx

Co-authored-by: Caroline <[email protected]>

* Update targets/frontend/src/components/changes/ChangesFicheSp.tsx

Co-authored-by: Caroline <[email protected]>

* one

* one

* one

* feat: add tu

* fix: conv

---------

Co-authored-by: Caroline <[email protected]>
  • Loading branch information
maxgfr and carolineBda authored Dec 22, 2023
1 parent aa428d7 commit add9832
Show file tree
Hide file tree
Showing 81 changed files with 728 additions and 301 deletions.
14 changes: 9 additions & 5 deletions shared/types/contributions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { FicheServicePublicDoc } from "./index";
import { Document } from "./documents";

export type ContributionsAnswers = {
id: string;
content: string | null;
Expand All @@ -6,7 +9,7 @@ export type ContributionsAnswers = {
kali_references: ContributionKaliReferences[];
legi_references: ContributionLegiReferences[];
other_references: ContributionOtherReferences[];
cdtn_references: ContributionCdtnReferences[];
cdtn_references: Partial<ContributionCdtnReferences>[];
content_fiche_sp: ContributionContentFicheSp | null;
message_block_generic_no_CDT: string | null;
agreement: ContributionAgreement;
Expand Down Expand Up @@ -42,14 +45,15 @@ export type ContributionAgreement = {
};

export type ContributionCdtnReferences = {
document: {
cdtn_id: string;
};
cdtn_id: string;
answer: ContributionsAnswers;
answer_id: string;
document: Partial<Document<any>>;
};

export type ContributionContentFicheSp = {
initial_id: string;
document: Record<string, any>;
document: FicheServicePublicDoc;
};

export type ContributionLegiReferences = {
Expand Down
1 change: 1 addition & 0 deletions shared/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export type DocumentInfo = Pick<HasuraDocument, "source" | "title"> & {
};
export type DocumentInfoWithCdtnRef = DocumentInfo & {
ref: Pick<DocumentInfo, "id" | "title">;
url?: string;
};

/** Fiche travail alert changes */
Expand Down
52 changes: 0 additions & 52 deletions targets/alert-cli/src/ccn-list.ts

This file was deleted.

4 changes: 2 additions & 2 deletions targets/alert-cli/src/diff/dila/CompareDilaContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import type {
import parents from "unist-util-parents";
import { selectAll } from "unist-util-select";

import type { AgreementFileChange } from "./Agreement/types";
import type { CodeFileChange } from "./Code/types";
import type { AgreementFileChange } from "./kali/types";
import type { CodeFileChange } from "./legi/types";
import type {
Article,
ArticleWithParent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getContribReferences from "../../extractDilaReferences/contribution";
import getEditorialContentReferences from "../../extractDilaReferences/editorialContents";
import getTravailEmploiReferences from "../../extractDilaReferences/ficheTravailEmploi";
import getMailTemplateReferences from "../../extractDilaReferences/mailTemplates";
import getContribReferences from "./extractReferences/contribution";
import getEditorialContentReferences from "./extractReferences/editorialContents";
import getTravailEmploiReferences from "./extractReferences/ficheTravailEmploi";
import getMailTemplateReferences from "./extractReferences/mailTemplates";
import { DilaChanges } from "./types";
import { DocumentReferences } from "@shared/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelevantDocumentsExtractor } from "../dila/ReleventDocuments";
import { RelevantDocumentsExtractor } from "../RelevantDocuments";
import { DilaChanges, DocumentReferences } from "@shared/types";

export class RelevantDocumentsExtractorStub
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, expect, it } from "@jest/globals";
import type { DilaChanges } from "@shared/types";
import { RelevantDocumentsExtractorImpl } from "../diff/dila/ReleventDocuments";
import { RelevantDocumentsExtractorImpl } from "../RelevantDocuments";

jest.mock("../extractDilaReferences/ficheTravailEmploi", () => () => []);
jest.mock("../extractDilaReferences/mailTemplates", () => () => []);
jest.mock("../extractDilaReferences/editorialContents", () => () => []);
jest.mock("../extractDilaReferences/contribution", () => () => [
jest.mock("../extractReferences/ficheTravailEmploi", () => () => []);
jest.mock("../extractReferences/mailTemplates", () => () => []);
jest.mock("../extractReferences/editorialContents", () => () => []);
jest.mock("../extractReferences/contribution", () => () => [
{
document: {
id: "id-generic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from "@jest/globals";
import type { FicheTravail } from "../ficheTravailEmploi";
import main, { extractFicheTravailEmploiRef } from "../ficheTravailEmploi";

jest.mock("../getAllDocumentsBySource", () => {
jest.mock("../../../shared/getAllDocumentsBySource", () => {
return {
getAllDocumentsBySource: () => mockFiches,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from "@jest/globals";
import type { Contrib } from "../getOldContribRef";
import { extractContributionsRef, getOldContribRef } from "../getOldContribRef";

jest.mock("../../getAllDocumentsBySource", () => {
jest.mock("../../../../shared/getAllDocumentsBySource", () => {
return {
getAllDocumentsBySource: () => mockContributions,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from "@shared/types";
import { SOURCES } from "@socialgouv/cdtn-sources";

import { getAllDocumentsBySource } from "../getAllDocumentsBySource";
import { getAllDocumentsBySource } from "../../../shared/getAllDocumentsBySource";

export type Contrib = Pick<
ContributionComplete | ContributionFiltered,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { DilaApiClient } from "@socialgouv/dila-api-client";
import memoizee from "memoizee";
import pMap from "p-map";

import { getAllDocumentsBySource } from "./getAllDocumentsBySource";
import { WarningRepository } from "../repositories/WarningRepository";
import { getAllDocumentsBySource } from "../../shared/getAllDocumentsBySource";
import { WarningRepository } from "../../../repositories/WarningRepository";
import { gqlClient } from "@shared/utils";

export type EditorialContentSubset = Pick<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { DocumentReferences, FicheTravailEmploi } from "@shared/types";
import { SOURCES } from "@socialgouv/cdtn-sources";
import memoizee from "memoizee";

import { getAllDocumentsBySource } from "./getAllDocumentsBySource";
import { getAllDocumentsBySource } from "../../shared/getAllDocumentsBySource";

let references: DocumentReferences[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { DilaApiClient } from "@socialgouv/dila-api-client";
import memoizee from "memoizee";
import pMap from "p-map";

import { getAllDocumentsBySource } from "./getAllDocumentsBySource";
import { WarningRepository } from "../repositories/WarningRepository";
import { getAllDocumentsBySource } from "../../shared/getAllDocumentsBySource";
import { WarningRepository } from "../../../repositories/WarningRepository";
import { gqlClient } from "@shared/utils";

export type MailTemplateSubset = Pick<
Expand Down
4 changes: 2 additions & 2 deletions targets/alert-cli/src/diff/dila/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./Agreement";
export * from "./Code";
export * from "./kali";
export * from "./legi";
export * from "./CompareDilaContent";
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "../CompareDilaContent";
import type { Diff, DilaChanges } from "../types";
import type { AgreementFileChange } from "./types";
import { RelevantDocumentsExtractor } from "../ReleventDocuments";
import { RelevantDocumentsExtractor } from "../RelevantDocuments";

function extractChanges(fileChange: AgreementFileChange): {
changes: Diff;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DataDiffFunction } from "../../type";
import type { DataDiffFunction } from "../../../types";
import processAgreementChanges from "./ProcessAgreementChanges";
import processAgreementFileChanges from "./ProcessAgreementFileChanges";
import { RelevantDocumentsExtractorImpl } from "../ReleventDocuments";
import { RelevantDocumentsExtractorImpl } from "../RelevantDocuments";

const processAgreementDataDiff: DataDiffFunction = async ({
tag,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Agreement } from "@socialgouv/kali-data-types";

import { createToJson, getFilename } from "../../../node-git.helpers";
import { createToJson, getFilename } from "../../../utils/node-git.helpers";
import type { AgreementFileChange } from "./types";
import { Diff, DiffFile, LoadFileFn } from "../../type";
import { Diff, DiffFile, LoadFileFn } from "../../../types";
import { GitTagData } from "../../../types";

const agreementFileChange = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import noChanges from "./dataset/filechanges_kali_agreement_no_changes.json";
import removed from "./dataset/filechanges_kali_agreement_removed.json";
import revelantChanges from "./dataset/filechanges_kali_agreement_revelant_changes.json";
import { Commit } from "../../../../types";
import { RelevantDocumentsExtractorStub } from "../../../__tests__/RelevantDocumentsExtractorStub";
import { RelevantDocumentsExtractorStub } from "../../__tests__/RelevantDocumentsExtractorStub";

describe("Calcul des différences sur les conventions collectives (kali-data)", () => {
describe("Aucun changement dans une convention collective", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect } from "@jest/globals";

import processAgreementFileChanges from "../ProcessAgreementFileChanges";
import { DiffFile, LoadFileFn, PatchStatus } from "../../../type";
import { DiffFile, LoadFileFn, PatchStatus } from "../../../../types";

describe("Creation des AgreementFileChange à partir d'un patch", () => {
const createPatch = (status: PatchStatus): DiffFile => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { GitTagData } from "../../../types";
import { compareDilaContent } from "../CompareDilaContent";
import type { DilaChanges } from "../types";
import type { CodeFileChange } from "./types";
import { RelevantDocumentsExtractor } from "../ReleventDocuments";
import { RelevantDocumentsExtractor } from "../RelevantDocuments";

const processCodeChanges = async (
tag: GitTagData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DataDiffFunction } from "../../type";
import type { DataDiffFunction } from "../../../types";
import processCodeChanges from "./ProcessCodeChanges";
import processCodeFileChanges from "./ProcessCodeFileChanges";
import { RelevantDocumentsExtractorImpl } from "../ReleventDocuments";
import { RelevantDocumentsExtractorImpl } from "../RelevantDocuments";

const processCodeDataDiff: DataDiffFunction = async ({
tag,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Code } from "@socialgouv/legi-data-types";

import { createToJson } from "../../../node-git.helpers";
import { createToJson } from "../../../utils/node-git.helpers";
import type { CodeFileChange } from "./types";
import { Diff, DiffFile, LoadFileFn } from "../../type";
import { Diff, DiffFile, LoadFileFn } from "../../../types";
import { GitTagData } from "../../../types";

const codeFileChanges = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import irrevelantChanges from "./dataset/filechanges_legi_code_irrevelant_change
import noChanges from "./dataset/filechanges_legi_code_no_changes.json";
import revelantChanges from "./dataset/filechanges_legi_code_revelant_changes.json";
import { Commit } from "../../../../types";
import { RelevantDocumentsExtractorStub } from "../../../__tests__/RelevantDocumentsExtractorStub";
import { RelevantDocumentsExtractorStub } from "../../__tests__/RelevantDocumentsExtractorStub";

describe("Calcul des différences sur les code (legi-data)", () => {
describe("Aucun changement", () => {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions targets/alert-cli/src/diff/dila/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {
} from "@socialgouv/kali-data-types";
import type { CodeArticle, CodeSection } from "@socialgouv/legi-data-types";

import type { AgreementFileChange } from "./Agreement/types";
import type { CodeFileChange } from "./Code/types";
import type { AgreementFileChange } from "./kali/types";
import type { CodeFileChange } from "./legi/types";

export type DilaChanges = CommonDilaChanges & {
file: string;
Expand Down
13 changes: 7 additions & 6 deletions targets/alert-cli/src/diff/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ccns } from "../ccn-list";
import { DataDiffFunction } from "./type";
import { DataDiffFunction } from "../types";
import { processAgreementDataDiff, processCodeDataDiff } from "./dila";
import { processVddDiff } from "./fiches-vdd";
import { processTravailDataDiff } from "./fiches-travail-data";
import { processVddDiff } from "./sp";
import { processTravailDataDiff } from "./travail-data";
import { GitTagData } from "../types";
import { AlertChanges } from "@shared/types";
import { GithubApi } from "../APIs/api";
import { GithubApi } from "../utils/github";
import { getAgreements } from "./shared/getAgreements";

export class AlertDetector {
githubApi: GithubApi;
Expand All @@ -19,14 +19,15 @@ export class AlertDetector {
private async getFileFilter(
repository: string
): Promise<(path: string) => boolean> {
const ccns = await getAgreements();
switch (repository) {
case "socialgouv/legi-data":
// only code-du-travail
return (path: string) => path.endsWith("LEGITEXT000006072050.json");
case "socialgouv/kali-data":
// only a ccn matching our list
return (path: string) =>
ccns.some((ccn) => new RegExp(ccn.id).test(path));
ccns.some((ccn) => new RegExp(ccn.kali_id).test(path));
case "socialgouv/fiches-vdd": {
/** @type {string[]} */
const ficheVddIDs = this.fichesServicePublicIds;
Expand Down
Loading

0 comments on commit add9832

Please sign in to comment.