-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueryIssues.ts
53 lines (44 loc) · 1.64 KB
/
queryIssues.ts
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 https = require('https');
const userAgent = "Node.js";
const reqHeader = {
'User-Agent': userAgent,
'Accept': 'application/vnd.github.v3+json'
}
interface GithubIssueSummary {
url: string
number: Number
}
async function githubQuery(get: string) {
return new Promise((resolve, reject) => {
https.get('https://api.github.com/repos/heremaps/harp.gl/issues', { headers: reqHeader },
(response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => body.push(chunk));
// we are done, resolve promise with those joined chunks
response.on('end', () => resolve(JSON.parse(body.join(''))));
}).on("error", (err) => {
reject(err);
})
})
}
githubQuery('').then((body)=>{
const issues = body as GithubIssueSummary[];
issues.forEach((issue: GithubIssueSummary) => console.log(issue.number));
});
// https.get('https://api.github.com/repos/heremaps/harp.gl/issues', { headers: reqHeader },
// (resp) => {
// let data = '';
// resp.on('data', (chunk) => {
// data += chunk;
// });
// resp.on('end', () => {
// onGithubIssues(JSON.parse(data));
// });
// }).on("error", (err) => {
// console.log("Error: " + err.message);
// });