-
Notifications
You must be signed in to change notification settings - Fork 10
/
fetchData.js
35 lines (30 loc) · 1.02 KB
/
fetchData.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
const fetch = require('node-fetch');
class FetchData {
async getRepositories(owner) {
const url = `https://api.github.com/users/${owner}/repos`;
const response = await fetch(url);
if (response.ok) {
const repositories = await response.json();
return repositories;
} else {
throw new Error('Failed to retrieve repositories');
}
}
async getGithubStatistics(owner, repo) {
const url = `https://api.github.com/repos/${owner}/${repo}`;
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
const statistics = {
Stars: data.stargazers_count,
Forks: data.forks_count,
'Open Issues': data.open_issues_count,
Watchers: data.subscribers_count,
};
return statistics;
} else {
return null;
}
}
}
module.exports = FetchData;