Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit eacb867

Browse files
committed
feat(api): add fallback data when reaching github limits
1 parent a5abef2 commit eacb867

27 files changed

+112385
-11
lines changed

src/store/Github/actions.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { api, proxy } from "../../utils/request";
1+
import { api, proxy, local } from "../../utils/request";
22
import lodash from "lodash";
33

44
function getLastCommit (repo) {
55
return api.get(`/repos/ovh-ux/${repo}/commits`)
6-
.catch(() => proxy.get(`/repos/ovh-ux/${repo}/commits`))
6+
.catch(() => local.get(`${repo}_last_commits.json`))
77
.then((response) => {
88
const last = response.data[0].sha;
99
return last;
@@ -12,7 +12,7 @@ function getLastCommit (repo) {
1212

1313
function compareCommits (repo, first, last) {
1414
return api.get(`/repos/ovh-ux/${repo}/compare/${first}...${last}`)
15-
.catch(() => proxy.get(`/repos/ovh-ux/${repo}/compare/${first}...${last}`))
15+
.catch(() => local.get(`${repo}_compare.json`))
1616
.then((response) => {
1717
const total = response.data.total_commits;
1818
return total;
@@ -21,7 +21,7 @@ function compareCommits (repo, first, last) {
2121

2222
function getCommits (repo) {
2323
return getLastCommit(repo).then((lastcommit) => {
24-
const first = { "ovh-manager-web": "6a63e7c0199620f8e62d73a378cde770bb51f56f", "ovh-manager-cloud": "44256bffb7ab124e9537c470cbfa42b4fae7432f", "ovh-manager-telecom": "7ddd35c7ccde0f55dd217852949c5ef83e9c85a9", "ovh-manager-dedicated": "c9c25615fb3e2a8f975e5906268dc259675be799" };
24+
const first = {"ovh-manager-web": "6a63e7c0199620f8e62d73a378cde770bb51f56f", "ovh-manager-cloud": "44256bffb7ab124e9537c470cbfa42b4fae7432f", "ovh-manager-telecom": "7ddd35c7ccde0f55dd217852949c5ef83e9c85a9", "ovh-manager-dedicated": "c9c25615fb3e2a8f975e5906268dc259675be799"};
2525
return compareCommits(repo, first[repo], lastcommit).then((response) => {
2626
return response + 1;
2727
});
@@ -30,7 +30,7 @@ function getCommits (repo) {
3030

3131
function getContributors (repo) {
3232
return api.get(`/repos/ovh-ux/${repo}/contributors`)
33-
.catch(() => proxy.get(`/repos/ovh-ux/${repo}/contributors`))
33+
.catch(() => local.get(`${repo}_contributors.json`))
3434
.then((response) => {
3535
const data = response.data;
3636
const contributors = [];
@@ -45,7 +45,7 @@ function getContributors (repo) {
4545

4646
function getTopics (repo) {
4747
return api.get(`/repos/ovh-ux/${repo}/topics`)
48-
.catch(() => proxy.get(`/repos/ovh-ux/${repo}/topics`))
48+
.catch(() => local.get(`${repo}_topics.json`))
4949
.then((response) => {
5050
const data = response.data.names;
5151
const topics = [];
@@ -60,7 +60,7 @@ function getTopics (repo) {
6060
export default {
6161
nbrRepos ({ commit }) {
6262
return api.get("/users/ovh-ux")
63-
.catch(() => proxy.get("/users/ovh-ux"))
63+
.catch(() => local.get("ovh-ux.json"))
6464
.then((response) => {
6565
const nbr_repos = response.data.public_repos;
6666

@@ -69,15 +69,15 @@ export default {
6969
},
7070
lastPushed ({ commit }) {
7171
return api.get("/users/ovh-ux/repos?sort=pushed&direction=desc")
72-
.catch(() => proxy.get("/users/ovh-ux/repos?sort=pushed&direction=desc"))
72+
.catch(() => local.get("reposDesc.json"))
7373
.then((response) => {
7474
const last = response.data[0];
7575
commit("LAST_PUSHED", last);
7676
});
7777
},
7878
aboutTechno ({ commit }) {
7979
return api.get("/users/ovh-ux/repos?per_page=500")
80-
.catch(() => proxy.get("/users/ovh-ux/repos?per_page=500"))
80+
.catch(() => local.get("reposAll.json"))
8181
.then((response) => {
8282
const data = response.data;
8383
const language_obj = {};
@@ -104,7 +104,7 @@ export default {
104104
},
105105
manager ({ commit }, repo) {
106106
api.get(`/repos/ovh-ux/${repo}`)
107-
.catch(() => proxy.get(`/repos/ovh-ux/${repo}`))
107+
.catch(() => local.get(`${repo}.json`))
108108
.then((data) => {
109109
getCommits(repo).then((commits) => {
110110
getContributors(repo).then((contributors) => {
@@ -125,7 +125,6 @@ export default {
125125
},
126126
otherProjects ({ commit }) {
127127
return api.get("/users/ovh-ux/repos?sort=pushed&direction=desc")
128-
.catch(() => proxy.get("/users/ovh-ux/repos?sort=pushed&direction=desc"))
129128
.then((response) => {
130129
const data = response.data;
131130
commit("OTHER_PROJECTS", data);

src/utils/request.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ export const proxy = axios.create({
1818
Accept: "application/vnd.github.mercy-preview+json"
1919
}
2020
});
21+
22+
export const local = axios.create({
23+
baseURL: "/static/api/",
24+
method: "get"
25+
});

static/api-urls.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ovh-ux
2+
3+
https://api.github.com/users/ovh-ux
4+
5+
# ovh-ux repos
6+
7+
https://api.github.com/users/ovh-ux/repos?sort=pushed&direction=desc
8+
https://api.github.com/users/ovh-ux/repos?per_page=500
9+
10+
# managers
11+
12+
https://api.github.com/repos/ovh-ux/ovh-manager-telecom
13+
https://api.github.com/repos/ovh-ux/ovh-manager-cloud
14+
https://api.github.com/repos/ovh-ux/ovh-manager-web
15+
https://api.github.com/repos/ovh-ux/ovh-manager-dedicated
16+
17+
# managers last commit
18+
19+
https://api.github.com/repos/ovh-ux/ovh-manager-telecom/commits
20+
https://api.github.com/repos/ovh-ux/ovh-manager-cloud/commits
21+
https://api.github.com/repos/ovh-ux/ovh-manager-web/commits
22+
https://api.github.com/repos/ovh-ux/ovh-manager-dedicated/commits
23+
24+
# managers commits compare (where ${last} is variable depend of last commit)
25+
26+
https://api.github.com/repos/ovh-ux/ovh-manager-telecom/compare/7ddd35c7ccde0f55dd217852949c5ef83e9c85a9...${last}
27+
https://api.github.com/repos/ovh-ux/ovh-manager-cloud/44256bffb7ab124e9537c470cbfa42b4fae7432f...${last}
28+
https://api.github.com/repos/ovh-ux/ovh-manager-web/6a63e7c0199620f8e62d73a378cde770bb51f56f...${last}
29+
https://api.github.com/repos/ovh-ux/ovh-manager-dedicated/c9c25615fb3e2a8f975e5906268dc259675be799...${last}
30+
31+
# managers contributors
32+
33+
https://api.github.com/repos/ovh-ux/ovh-manager-telecom/contributors
34+
https://api.github.com/repos/ovh-ux/ovh-manager-cloud/contributors
35+
https://api.github.com/repos/ovh-ux/ovh-manager-web/contributors
36+
https://api.github.com/repos/ovh-ux/ovh-manager-dedicated/contributors
37+
38+
# managers tags
39+
40+
https://api.github.com/repos/ovh-ux/ovh-manager-telecom/topics
41+
https://api.github.com/repos/ovh-ux/ovh-manager-cloud/topics
42+
https://api.github.com/repos/ovh-ux/ovh-manager-web/topics
43+
https://api.github.com/repos/ovh-ux/ovh-manager-dedicated/topics

0 commit comments

Comments
 (0)