-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.mjs
37 lines (31 loc) · 990 Bytes
/
diff.mjs
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
import { readFileSync } from 'fs'
const oldFile = JSON.parse(readFileSync('old.lock', 'utf8'))
const newFile = JSON.parse(readFileSync('composer.lock', 'utf8'))
let text = '';
for (const p of oldFile.packages) {
const newP = newFile.packages.find(p2 => p2.name === p.name)
if (newP && newP.version !== p.version) {
text += `Package ${p.name} version has been changed from ${p.version} to ${newP.version}\n`
}
}
for (const p of oldFile.packages) {
if (!newFile.packages.find(p2 => p2.name === p.name)) {
text += `Package ${p.name} has been removed\n`
}
}
for (const p of newFile.packages) {
if (!oldFile.packages.find(p2 => p2.name === p.name)) {
text += `Package ${p.name} has been added\n`
}
}
if (text.length) {
await fetch(process.env.SLACK_WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
text
})
})
}