Skip to content

Commit

Permalink
Merge pull request #11200 from wellcomecollection/prismic-linting-slack
Browse files Browse the repository at this point in the history
Trigger Slack bot when errors are found in Prismic linting Github action run
  • Loading branch information
rcantin-w committed Sep 26, 2024
2 parents cd39bf7 + 8cedb08 commit ef9fcbc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/prismic-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
registry-type: public
- name: Run Prismic linting
run: docker compose run prismic_model yarn lintPrismicData
run: docker compose run prismic_model yarn lintPrismicData slackWebhookUrl=${{ secrets.SLACK_WEBHOOK_GA_PRISMIC_LINTING_EDITORIAL_FLAG_URL }}
on-failure:
runs-on: ubuntu-latest
if: ${{ always() && (needs.prismic_linting.result == 'failure' || needs.prismic_linting.result == 'timed_out') }}
Expand Down
31 changes: 31 additions & 0 deletions prismic-model/lintPrismicData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import chalk from 'chalk';
import fs from 'fs';
import yargs from 'yargs';

import { pluralize } from '@weco/common/utils/grammar';

import { error } from './console';
import {
Expand All @@ -29,6 +32,13 @@ type ErrorProps = {
errors: string[];
};

const { slackWebhookUrl } = yargs(process.argv.slice(2))
.usage('Usage: $0 --slackWebhookUrl [string]')
.options({
slackWebhookUrl: { type: 'string' },
})
.parseSync();

// Look for eur01 safelinks. These occur when somebody has copied
// a URL directly from Outlook and isn't using the original URL.
//
Expand Down Expand Up @@ -145,6 +155,8 @@ function detectNonPromoImageStories(doc: any): string[] {
return [];
}

// Digital guides video and audio have a text field to input duration.
// We'd like the style to always be xx:xx, so we're adding a test to ensure this is respected.
function detectIncorrectAudioVideoDuration(doc: any): string[] {
const guideStopSlices =
doc?.data?.slices?.filter(s => s.slice_type === 'guide_stop') || [];
Expand Down Expand Up @@ -232,6 +244,9 @@ const getContentTypesWithUid = () => {
})
.filter(f => f);
};

// No document with the UID field should be saveable without that field filled in.
// We've had a few instances of it though, maybe they were drafts? So we're adding a test for the future.
const contentTypesWithUid = getContentTypesWithUid();
function detectMissingUidDocuments(doc: any): string[] {
return contentTypesWithUid.includes(doc.type) && !doc.uid
Expand Down Expand Up @@ -277,6 +292,22 @@ async function run() {
console.log(`- ${msg}`);
}
console.log('');

// Send an alert to Editors if anything is found on a GitHub Action run
// https://github.com/wellcomecollection/wellcomecollection.org/actions/workflows/prismic-linting.yml
if (slackWebhookUrl) {
try {
await fetch(slackWebhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
body: JSON.stringify({
message: `The Prismic linting script has found ${errors.length} ${pluralize(errors.length, 'thing')} that require${errors.length > 1 ? '' : 's'} your attention.`,
}),
});
} catch (e) {
console.log(e);
}
}
}
}

Expand Down

0 comments on commit ef9fcbc

Please sign in to comment.