-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (65 loc) · 2.54 KB
/
content-monitor.yml
File metadata and controls
79 lines (65 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Monitor Blog Content Changes
on:
push:
branches: [ main ]
paths:
- 'index.md'
jobs:
check-content-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: npm install gray-matter node-fetch
- name: Check for content changes
id: check-changes
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const matter = require('gray-matter');
// Get the current content
const currentContent = matter(fs.readFileSync('index.md', 'utf8'));
const currentFeatures = currentContent.data.features || [];
// Get the previous content
const { execSync } = require('child_process');
const previousContent = execSync('git show HEAD^:index.md').toString();
const previousFeatures = matter(previousContent).data.features || [];
// Find new features
const newFeatures = currentFeatures.filter(current => {
return !previousFeatures.some(prev => prev.link === current.link);
});
if (newFeatures.length > 0) {
// Make API call for new content
const fetch = require('node-fetch');
try {
const response = await fetch('https://prod.snorkell.ai/alert-emails-to-user', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
newBlogs: newFeatures,
timestamp: new Date().toISOString()
}),
});
if (!response.ok) {
throw new Error(`API call failed with status ${response.status}`);
}
console.log('Successfully notified about new content:',
newFeatures.map(f => f.title).join(', '));
} catch (error) {
core.setFailed(`Failed to send notification: ${error.message}`);
}
}
- name: Handle API call failure
if: ${{ failure() }}
run: |
echo "Failed to process content changes or send notifications"
exit 1