mirror of
https://github.com/LukeHagar/stats-action.git
synced 2025-12-06 04:21:26 +00:00
added throttling support
This commit is contained in:
12
.github/workflows/test.yaml
vendored
12
.github/workflows/test.yaml
vendored
@@ -11,11 +11,15 @@ jobs:
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install
|
||||
- name: Run install
|
||||
uses: borales/actions-yarn@v5
|
||||
with:
|
||||
cmd: install
|
||||
|
||||
- name: Run Build
|
||||
run: yarn build
|
||||
- name: Run build
|
||||
uses: borales/actions-yarn@v5
|
||||
with:
|
||||
cmd: build
|
||||
|
||||
- uses: ./
|
||||
with:
|
||||
|
||||
5904
package-lock.json
generated
5904
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,12 +6,10 @@
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@octokit/action": "^6.0.7",
|
||||
"@octokit/plugin-paginate-graphql": "^4.0.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"octokit": "^3.1.2",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.1.4"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc && ncc build lib/index.js"
|
||||
|
||||
36
src/index.ts
36
src/index.ts
@@ -2,9 +2,12 @@ import core from "@actions/core";
|
||||
import { config } from "dotenv";
|
||||
import { writeFileSync } from "fs";
|
||||
import { Octokit } from "octokit";
|
||||
import { throttling } from "@octokit/plugin-throttling";
|
||||
import { ContributionsCollection, Language } from "./Types";
|
||||
config();
|
||||
|
||||
const ThrottledOctokit = Octokit.plugin(throttling);
|
||||
|
||||
export async function getGraphQLData(octokit: Octokit, username: string) {
|
||||
return octokit.graphql.paginate(
|
||||
`query userInfo($login: String!, $cursor: String) {
|
||||
@@ -157,8 +160,6 @@ export async function getContributionCollection(
|
||||
);
|
||||
}
|
||||
|
||||
console.log(promises);
|
||||
|
||||
const years = (await Promise.all(promises)).filter(Boolean) as {
|
||||
viewer: { contributionsCollection: ContributionsCollection };
|
||||
}[];
|
||||
@@ -262,7 +263,31 @@ try {
|
||||
|
||||
if (!username) throw new Error("Username is not present");
|
||||
|
||||
const octokit = new Octokit({ auth: token });
|
||||
const octokit = new ThrottledOctokit({
|
||||
auth: token,
|
||||
throttle: {
|
||||
onRateLimit: (retryAfter, options, octokit, retryCount) => {
|
||||
octokit.log.warn(
|
||||
`Request quota exhausted for request ${options.method} ${options.url}`
|
||||
);
|
||||
|
||||
if (retryCount < 1) {
|
||||
// only retries once
|
||||
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
onSecondaryRateLimit: (retryAfter, options, octokit) => {
|
||||
// does not retry, only logs a warning
|
||||
octokit.log.warn(
|
||||
`SecondaryRateLimit detected for request ${options.method} ${options.url}.`
|
||||
);
|
||||
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const fetchedAt = Date.now();
|
||||
|
||||
@@ -276,11 +301,6 @@ try {
|
||||
getContributionCollection(octokit, accountCreationDate),
|
||||
]);
|
||||
|
||||
console.log(userDetails);
|
||||
console.log(graphQLData);
|
||||
console.log(totalCommits);
|
||||
console.log(contributionsCollection);
|
||||
|
||||
let starCount = 0;
|
||||
let forkCount = 0;
|
||||
for (const repo of graphQLData.user.repositories.nodes) {
|
||||
|
||||
Reference in New Issue
Block a user