Skip to content

Commit

Permalink
updated api guru build
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Nov 14, 2023
1 parent 9991768 commit 428ffe2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/apis-guru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GH_TOKEN_COMMIT_AND_BYPASS_BRANCH_PROTECTION }}

- name: Setup Git
run: |
git config user.name "Integration Service"
git config user.email "<[email protected]>"
- id: "auth-gcp"
name: "Authenticate to Google Cloud"
Expand Down Expand Up @@ -44,3 +52,11 @@ jobs:
GOOGLE_CLOUD_STORAGE_BUCKET: rate-my-open-api-prod
GOOGLE_CLOUD_PROJECT_ID: zuplo-marketing
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

- name: git add changed files
run: git add apis-guru.json

- name: Commit Updated API Ratings
run: |
git commit -m "Updated API Ratings"
git push origin main
25 changes: 14 additions & 11 deletions apps/api/apis-guru.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ const files = await glob(

const queue = new PQueue({ concurrency: 10 });

let ratings = [];

const ratingsPath = path.resolve(process.cwd(), "../../apis-guru.json");
if (fs.existsSync(ratingsPath)) {
ratings = await fs.promises.readFile(ratingsPath, "utf-8").then(JSON.parse);
}

await queue.addAll(files.map((file) => () => rateFile(file)));

const reportJson = JSON.stringify(ratings, null, 2);
await fs.promises.writeFile(ratingsPath, reportJson, "utf-8");

async function rateFile(file) {
console.log(`Processing ${file}`);

Expand All @@ -30,15 +40,8 @@ async function rateFile(file) {

const lastModified = new Date(stdout);

const reportPath = path.resolve(file, "../rating.json");

let report;
if (fs.existsSync(reportPath)) {
report = await fs.promises.readFile(reportPath, "utf-8").then(JSON.parse);
} else {
report = {};
}

const report =
ratings.find((r) => r.file === path.relative(baseDir, file)) || {};
if (
report.lastModified ? new Date(report.lastModified) >= lastModified : false
) {
Expand All @@ -50,11 +53,11 @@ async function rateFile(file) {

await createReportFromLocal(file, reportId);

report.file = path.relative(baseDir, file);
report.lastModified = lastModified.toISOString();
report.reportId = reportId;

const reportJson = JSON.stringify(report, null, 2);
await fs.promises.writeFile(reportPath, reportJson);
ratings.push(report);

console.log({ reportId });
}

0 comments on commit 428ffe2

Please sign in to comment.