-
Notifications
You must be signed in to change notification settings - Fork 4
/
fetch-issues.js
54 lines (49 loc) · 1.5 KB
/
fetch-issues.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
import { Octokit } from '@octokit/rest'
/* c8 ignore start */
const getGithubClient = () => {
return new Octokit({
auth: process.env.GH_AUTH_TOKEN
})
}
/* c8 ignore stop */
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 (const 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())
}
export { fetchIssues, getGithubClient }