Skip to content

Commit

Permalink
update api rating result to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Nov 14, 2023
1 parent 1d23b5d commit 99f4f9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
27 changes: 10 additions & 17 deletions .github/workflows/apis-guru.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: APIs Guru Ratings
on:
workflow_dispatch:
# schedule:
# - cron: "0 17,22 * * 1-5"
schedule:
- cron: 0 0 * * 0

jobs:
generate:
Expand All @@ -15,14 +15,6 @@ 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 @@ -53,10 +45,11 @@ jobs:
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
- name: Upload Package.json
uses: "google-github-actions/upload-cloud-storage@v1"
with:
path: apis-guru.json
destination: rate-my-openapi-public
parent: false
headers: |-
content-type: application/json
11 changes: 5 additions & 6 deletions apps/api/apis-guru.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ await fs.promises.writeFile(ratingsPath, reportJson, "utf-8");

async function rateFile(file) {
console.log(`Processing ${file}`);
const relativeFile = path.relative(baseDir, file);

const { stdout } = await execa(
"git",
["log", "-1", "--format=%ad", "--", path.relative(baseDir, file)],
["log", "-1", "--format=%ad", "--", relativeFile],
{ cwd: baseDir },
);

const lastModified = new Date(stdout);

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

await createReportFromLocal(file, reportId);

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

ratings.push(report);

console.log({ reportId });
console.log(report);
}

0 comments on commit 99f4f9a

Please sign in to comment.