-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
53 lines (44 loc) · 1.38 KB
/
index.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
const core = require('@actions/core')
const github = require('@actions/github')
const fetch = require('node-fetch')
const PERSONAL_ACCESS_TOKEN = core.getInput('PERSONAL_ACCESS_TOKEN')
const octokit = new github.GitHub(PERSONAL_ACCESS_TOKEN)
const SLACK_URL = core.getInput('SLACK_URL')
const SINCE = core.getInput('SINCE')
async function postNotifications() {
const notifs = await octokit.activity.listNotifications({since: SINCE, participating: true, per_page: 100})
core.info(`Found ${notifs.data.length} notifications since ${SINCE}`)
notifs.data.filter(({reason}) => {
if (['mention', 'assign', ''].includes(reason)) {
return true
}
if (reason == 'review_requested') {
return
}
}).
map(async (item) => {
const {subject: {title, url, type: itemType}} = item
const res = await octokit.request(`GET ${url}`)
if (item.reason == 'review_requested') {
core.info("body", res.data.requested_reviewers)
}
return `Title: ${title} URL: ${res.data.html_url}`
}).
forEach(async body => {
body = await body
core.info(`Posting: ${body}`)
await fetch(SLACK_URL, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: body})
})
})
}
async function run() {
try {
await postNotifications()
} catch (error) {
core.setFailed(error.message)
}
}
run()