Repository navigation
Expand file tree
/
Copy pathgithub-issues.js
More file actions
executable file
·67 lines (58 loc) · 2 KB
/
Copy pathgithub-issues.js
File metadata and controls
executable file
·67 lines (58 loc) · 2 KB
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
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
/**
* List GitHub issues for a repo in a Taskify company's connected org.
*
* Usage: node github-issues.js <repo> [--org taskify] [--state open]
*/
var REPO = process.argv[2]
var ORG = null
var STATE = 'open'
var API = 'http://localhost:3005/db/taskify'
process.argv.forEach(function (arg, i) {
if (arg === '--org' && process.argv[i + 1]) ORG = process.argv[i + 1]
if (arg === '--api' && process.argv[i + 1]) API = process.argv[i + 1]
if (arg === '--state' && process.argv[i + 1]) STATE = process.argv[i + 1]
})
if (!REPO) {
console.error('Usage: node github-issues.js <repo> [--org <org>] [--state open|closed|all]')
process.exit(1)
}
async function getOrg() {
if (ORG) return ORG
try {
var res = await fetch(API + '/company/c1')
var company = await res.json()
if (company.githubOrg) return company.githubOrg
} catch (e) {}
console.error('No GitHub org found. Use --org <name> or set it in Company Settings.')
process.exit(1)
}
async function listIssues(org, repo) {
var page = 1
var issues = []
while (true) {
var res = await fetch('https://api.github.com/repos/' + org + '/' + repo + '/issues?state=' + STATE + '&per_page=100&page=' + page, {
headers: { 'Accept': 'application/vnd.github.v3+json' }
})
if (!res.ok) {
console.error('GitHub API error:', res.status, await res.text())
process.exit(1)
}
var batch = await res.json()
if (batch.length === 0) break
issues = issues.concat(batch)
page++
}
// Filter out PRs (GitHub API returns them as issues too)
return issues.filter(function (i) { return !i.pull_request })
}
var org = await getOrg()
console.log('GitHub: ' + org + '/' + REPO + ' (' + STATE + ')')
console.log('')
var issues = await listIssues(org, REPO)
console.log('Issues (' + issues.length + '):')
console.log('')
issues.forEach(function (i) {
var labels = i.labels.map(function (l) { return l.name }).join(', ')
console.log(' #' + i.number + ' ' + i.title + (labels ? ' [' + labels + ']' : ''))
})