mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-09-03 04:18:06 +00:00
feat: enable multi page star fetching for private vercel instances (#2159)
* feat: enable multi-page stars' fetching for private vercel instances This commit enables multi-page stars' support from fetching on private Vercel instances. This feature can be disabled on the public Vercel instance by adding the `FETCH_SINGLE_PAGE_STARS=true` as an env variable in the public Vercel instance. This variable will not be present when people deploy their own Vercel instance, causing the code to fetch multiple star pages. * fix: improve stats multi-page fetching behavoir This commit makes sure that the GraphQL api is only called one time per 100 repositories. The old method added one unnecesairy GraphQL call. * docs: update documentation * style: improve code syntax Co-authored-by: Matteo Pierro <pierromatteo@gmail.com> * lol happy new year * docs: remove rate limit documentation for now Remove the `FETCH_SINGLE_PAGE_STARS` from documentation for now since it might confuse people. * fix: fix error in automatic merge * feat: make sure env variable is read Co-authored-by: Matteo Pierro <pierromatteo@gmail.com> Co-authored-by: Anurag <hazru.anurag@gmail.com>
This commit is contained in:
co-authored by
Matteo Pierro
Anurag
parent
c1dc7b850c
commit
60fae292a3
+11
-24
@@ -25,7 +25,7 @@ stats.rank = calculateRank({
|
||||
issues: stats.totalIssues,
|
||||
});
|
||||
|
||||
const data = {
|
||||
const data_stats = {
|
||||
data: {
|
||||
user: {
|
||||
name: stats.name,
|
||||
@@ -40,15 +40,6 @@ const data = {
|
||||
followers: { totalCount: 0 },
|
||||
repositories: {
|
||||
totalCount: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const repositoriesData = {
|
||||
data: {
|
||||
user: {
|
||||
repositories: {
|
||||
nodes: [{ stargazers: { totalCount: 100 } }],
|
||||
pageInfo: {
|
||||
hasNextPage: false,
|
||||
@@ -83,11 +74,7 @@ const faker = (query, data) => {
|
||||
setHeader: jest.fn(),
|
||||
send: jest.fn(),
|
||||
};
|
||||
mock
|
||||
.onPost("https://api.github.com/graphql")
|
||||
.replyOnce(200, data)
|
||||
.onPost("https://api.github.com/graphql")
|
||||
.replyOnce(200, repositoriesData);
|
||||
mock.onPost("https://api.github.com/graphql").replyOnce(200, data);
|
||||
|
||||
return { req, res };
|
||||
};
|
||||
@@ -98,7 +85,7 @@ afterEach(() => {
|
||||
|
||||
describe("Test /api/", () => {
|
||||
it("should test the request", async () => {
|
||||
const { req, res } = faker({}, data);
|
||||
const { req, res } = faker({}, data_stats);
|
||||
|
||||
await api(req, res);
|
||||
|
||||
@@ -133,7 +120,7 @@ describe("Test /api/", () => {
|
||||
text_color: "fff",
|
||||
bg_color: "fff",
|
||||
},
|
||||
data,
|
||||
data_stats,
|
||||
);
|
||||
|
||||
await api(req, res);
|
||||
@@ -154,7 +141,7 @@ describe("Test /api/", () => {
|
||||
});
|
||||
|
||||
it("should have proper cache", async () => {
|
||||
const { req, res } = faker({}, data);
|
||||
const { req, res } = faker({}, data_stats);
|
||||
|
||||
await api(req, res);
|
||||
|
||||
@@ -170,7 +157,7 @@ describe("Test /api/", () => {
|
||||
});
|
||||
|
||||
it("should set proper cache", async () => {
|
||||
const { req, res } = faker({ cache_seconds: 15000 }, data);
|
||||
const { req, res } = faker({ cache_seconds: 15000 }, data_stats);
|
||||
await api(req, res);
|
||||
|
||||
expect(res.setHeader.mock.calls).toEqual([
|
||||
@@ -196,7 +183,7 @@ describe("Test /api/", () => {
|
||||
|
||||
it("should set proper cache with clamped values", async () => {
|
||||
{
|
||||
let { req, res } = faker({ cache_seconds: 200000 }, data);
|
||||
let { req, res } = faker({ cache_seconds: 200000 }, data_stats);
|
||||
await api(req, res);
|
||||
|
||||
expect(res.setHeader.mock.calls).toEqual([
|
||||
@@ -212,7 +199,7 @@ describe("Test /api/", () => {
|
||||
|
||||
// note i'm using block scoped vars
|
||||
{
|
||||
let { req, res } = faker({ cache_seconds: 0 }, data);
|
||||
let { req, res } = faker({ cache_seconds: 0 }, data_stats);
|
||||
await api(req, res);
|
||||
|
||||
expect(res.setHeader.mock.calls).toEqual([
|
||||
@@ -227,7 +214,7 @@ describe("Test /api/", () => {
|
||||
}
|
||||
|
||||
{
|
||||
let { req, res } = faker({ cache_seconds: -10000 }, data);
|
||||
let { req, res } = faker({ cache_seconds: -10000 }, data_stats);
|
||||
await api(req, res);
|
||||
|
||||
expect(res.setHeader.mock.calls).toEqual([
|
||||
@@ -248,7 +235,7 @@ describe("Test /api/", () => {
|
||||
username: "anuraghazra",
|
||||
count_private: true,
|
||||
},
|
||||
data,
|
||||
data_stats,
|
||||
);
|
||||
|
||||
await api(req, res);
|
||||
@@ -288,7 +275,7 @@ describe("Test /api/", () => {
|
||||
text_color: "fff",
|
||||
bg_color: "fff",
|
||||
},
|
||||
data,
|
||||
data_stats,
|
||||
);
|
||||
|
||||
await api(req, res);
|
||||
|
||||
Reference in New Issue
Block a user