Skip to content

Commit

Permalink
Gérer de nouveaux problèmes avec le robot de vérification de liens (#…
Browse files Browse the repository at this point in the history
…4345)

* fix: soucis d'accès aux page sncf et gestion des transformations de structures des aides (link/teleservice) => (link)

* fix: ajout de paramètres supplémentaire dans le header

* fix: corriger les liens résolus dans le grist
  • Loading branch information
jenovateurs authored Jun 24, 2024
1 parent 3b1aebd commit ca1d0d3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,14 @@ If you want changes to be made locally instead of generating pull requests in pr

- First, [contribuer/public/admin/config.yml#L19](https://github.com/betagouv/aides-jeunes/blob/main/contribuer/public/admin/config.yml#L19) ([`local_backend: true`](https://decapcms.org/docs/working-with-a-local-git-repository)) must be uncommented;
- `npx netlify-cms-proxy-server` should be ran from `.` and

## Check Link Validity

Some parameters can be use to debug the command

- `--dry-run` : this command is useful to not send update/new row to Grist
- `--no-priority` : without getting priority from analytic data
- `--only [slug benefit]` : work on specific benefit

Here is an example of how using this parameters
`npm run tools:check-links-validity -- --dry-run`
40 changes: 35 additions & 5 deletions lib/benefits/link-validity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,39 @@ export function determineOperationsOnBenefitLinkError(
: processCron
const operations: GristOperation[] = []
const benefitId = benefitLinksCheckResult.id
const existingWarningsLink = existingWarnings?.[benefitId]

benefitLinksCheckResult.links.forEach((link) => {
const existingWarning = existingWarnings?.[benefitId]?.[link.type]
const existingWarning = existingWarningsLink?.[link.type]
processor(benefitLinksCheckResult, link, existingWarning, operations)
if (
(!existingWarning && existingWarningsLink) ||
(existingWarning && Object.entries(existingWarningsLink).length > 1)
) {
// cas ou le lien a été supprimé ainsi que sa propriété
for (const type in existingWarningsLink) {
if (
!benefitLinksCheckResult.links.some(
(linkObject) =>
linkObject.link === existingWarningsLink[type]?.fields?.Lien &&
benefitLinksCheckResult.links.length > 0
) || //Si le lien analysé n'est pas présent dans la liste des liens d'erreurs et qu'il y a au moins un lien
(!existingWarning &&
benefitLinksCheckResult.links.some(
(linkObject) =>
linkObject.link === existingWarningsLink[type]?.fields?.Lien &&
linkObject.ok
))
) {
processor(
benefitLinksCheckResult,
link,
existingWarningsLink[type],
operations
)
}
}
}
})

return operations
Expand All @@ -111,19 +141,19 @@ export function determineExistingWarningsFixByPrivateBenefits(
)
if (privateBenefit?.length) {
for (const type in existingWarnings[warningBenefitId]) {
const fixPullRequestUrl =
const PR =
pullRequestURL &&
existingWarnings[warningBenefitId][type].fields.PR !== pullRequestURL
? pullRequestURL
: existingWarnings[warningBenefitId][type].fields.PR
? { pullRequestURL }
: {}
benefitOperationsList.push([
{
type: "update",
data: {
id: existingWarnings[warningBenefitId][type].id,
fields: {
Corrige: true,
PR: fixPullRequestUrl,
...PR,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion lib/types/link-validity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface GristFields {
Dans_une_PR: boolean
Corrige: boolean
Date_PR: number
Date_correction: number
Date_correction: Date
PR: string
Date_erreur_de_detection: string
Aide: string
Expand Down
8 changes: 7 additions & 1 deletion tools/check-links-validity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ async function getHTTPStatus(link) {
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0",
Referer: "https://mes-aides.1jeune1solution.beta.gouv.fr/",
TE: "trailers",
"Upgrade-Insecure-Requests": 1,
"Sec-Fetch-Mode": "navigate",
"Sec-GPC": "1",
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document",
},
httpsAgent,
})
Expand Down Expand Up @@ -266,7 +273,6 @@ async function main() {
`Ajout: ${recordsByOperationTypes.add.length}`,
`Mise à jour: ${recordsByOperationTypes.update.length}`,
].join("\n")

Mattermost.post(text, process.env.MATTERMOST_ALERTING_URL)
}
}
Expand Down

0 comments on commit ca1d0d3

Please sign in to comment.