| 46 | }; |
| 47 | |
| 48 | async function sendChatMsg(build, msg) { |
| 49 | let chatMsg = `${msg} <${build.logUrl}|See logs>.`; |
| 50 | |
| 51 | const success = build.status === 'SUCCESS'; |
| 52 | |
| 53 | if (!success) { |
| 54 | const joke = (await (await fetch('https://icanhazdadjoke.com/', { |
| 55 | headers: {'Accept': 'application/json'} |
| 56 | })).json()) |
| 57 | .joke; |
| 58 | const jokeMsg = `Oh no! Failed builds are not fun... So here's a joke ` + |
| 59 | `to brighten your day :) -- ${joke}`; |
| 60 | chatMsg = `${chatMsg} ${jokeMsg}`; |
| 61 | } |
| 62 | |
| 63 | const res = await request(process.env.HANGOUTS_URL, { |
| 64 | resolveWithFullResponse: true, |
| 65 | method: 'POST', |
| 66 | json: true, |
| 67 | body: {text: chatMsg}, |
| 68 | }); |
| 69 | console.log(`statusCode: ${res.statusCode}`); |
| 70 | console.log(res.body); |
| 71 | } |