-
Notifications
You must be signed in to change notification settings - Fork 4
/
fetchIssues.js
56 lines (50 loc) · 1.54 KB
/
fetchIssues.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
'use strict'
const { Octokit } = require('@octokit/rest')
/* istanbul ignore next */
const getGithubClient = () => {
/* istanbul ignore next */
return new Octokit({
auth: process.env.GH_AUTH_TOKEN
})
}
const fetchIssues = async (includeBody, labels, org, client) => {
const itemSearchResults = await Promise.all(
labels.map(async label => {
const issues = await client.search.issuesAndPullRequests({
q: `is:issue is:open sort:updated-desc label:"${label}" org:"${org}"`
})
return issues.data.items
})
)
const items = itemSearchResults.flat()
const dedupeMap = new Map()
for (let item of items) {
// eslint-disable-next-line no-unused-vars
const [_, orgMatch, repoNameMatch] = item.repository_url.match(
/https:\/\/api\.github\.com\/repos\/([a-zA-Z0-9\-_]+)\/(\.?[a-zA-Z0-9\-_]+)/
)
dedupeMap.set(item.html_url, {
url: item.html_url,
title: item.title,
comments: item.comments,
body: includeBody ? item.body : undefined,
author: {
name: item.user?.login,
avatar_url: item.user?.avatar_url,
acc_url: item.user.html_url
},
project: {
org: orgMatch,
name: repoNameMatch,
url: `https://github.com/${orgMatch}/${repoNameMatch}`
},
locked: item.locked,
state: item.state,
created_at: item.created_at,
updated_at: item.updated_at,
labels: item.labels.map(({ name }) => name)
})
}
return Array.from(dedupeMap.values())
}
module.exports = { fetchIssues, getGithubClient }