-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbrigade.js
56 lines (47 loc) · 1.69 KB
/
brigade.js
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
const {events, Job, Group} = require("brigadier")
const ACTION_MOVE = "action_move_card_from_list_to_list"
// Event handler: trello
events.on("trello", (e, p) => {
// Parse the JSON payload from Trello.
var hook = JSON.parse(e.payload)
var d = hook.action.display
// Ignore other events. Just capture moves.
if (d.translationKey != ACTION_MOVE) {
console.log(`Skipped ${d.translationKey}`)
return
}
// JOB 1: Store move record in CosmosDB
var mongo = new Job("trello-db", "mongo:3.2")
mongo.storage.enabled = false
mongo.tasks = [
dbCmd(p, `db.trello.insert(${e.payload})`)
]
// JOB 2: Slack job will send the message.
var slack = new Job("slack-notify", "technosophos/slack-notify:latest", ["/slack-notify"])
var m = `From "${d.entities.listBefore.text}" to "${d.entities.listAfter.text}" <${hook.model.shortUrl}> <@U0RMKK605>`
slack.storage.enabled = false
slack.env = {
SLACK_WEBHOOK: p.secrets.SLACK_WEBHOOK,
SLACK_USERNAME: "Trello",
SLACK_TITLE: `Moved "${d.entities.card.text}"`,
SLACK_MESSAGE: m,
SLACK_ICON: "https://a.trellocdn.com/images/ios/0307bc39ec6c9ff499c80e18c767b8b1/apple-touch-icon-152x152-precomposed.png"
}
// Run the jobs in order.
Group.runEach([ mongo, slack ])
})
events.on("exec", (e, p) => {
var mongo = new Job("trello-db", "mongo:3.2")
mongo.storage.enabled = false
mongo.tasks = [
dbCmd(p, 'db.trello.find()')
]
mongo.run().then( res => {
console.log(res.data)
})
})
function dbCmd(p, script) {
return `mongo ${p.secrets.cosmosName}.documents.azure.com:10255/test ` +
`-u ${p.secrets.cosmosName} -p ${p.secrets.cosmosKey} --ssl --sslAllowInvalidCertificates ` +
`--eval '${script}'`
}