From 1125d9addea72e46c93fa44b0bad4d9e3333a64c Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 17 Jul 2023 12:47:06 +0800 Subject: [PATCH] fix: debug --- action.yml | 3 +++ dist/index.js | 6 +++++- package.json | 12 ++++++++++-- pre-commit | 3 +++ src/index.js | 9 +++++++-- 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 pre-commit diff --git a/action.yml b/action.yml index 1a0609e..76b9bd1 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,9 @@ inputs: required: false description: 'Branch to push report.' default: 'workflows/weekly-stats' + SPECIFIC_REPO: + required: false + description: 'Specify the repo to stat.' runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index 669d2f4..0978a00 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2212,6 +2212,7 @@ var core = require_core(); var https = require("https"); var fs = require("fs"); var repo = process.env.GITHUB_REPOSITORY; +exec(`echo ${repo}`); function getRange() { const today = /* @__PURE__ */ new Date(); const lastWeek = new Date( @@ -2239,6 +2240,9 @@ async function request(search) { data += chunk; }); res.on("end", () => { + console.log(url, JSON.parse(data)); + exec(`echo ${url}`); + exec(`echo ${JSON.parse(data)}`); resolve(JSON.parse(data)); }); }).on("error", reject); @@ -2297,7 +2301,7 @@ async function getContributorIds() { `commits?q=repo:${repo}+author-date:${since}..${until}` ); const contributors = Array.from( - new Set(result.items.map((item) => item.author.login)) + new Set(result?.items?.map((item) => item.author.login) || []) ); return contributors.join(",") + ` (${contributors.length})`; } diff --git a/package.json b/package.json index fbfd648..f84b5e0 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,14 @@ "@actions/core": "^1.10.0" }, "devDependencies": { - "esbuild": "^0.18.13" - } + "esbuild": "^0.18.13", + "husky": "^8.0.3", + "lint-staged": "^13.2.3" + }, + "husky": { + "hooks": { + "pre-commit": "npm run build && lint-staged" + } + }, + "lint-staged": "" } diff --git a/pre-commit b/pre-commit new file mode 100644 index 0000000..b0a4685 --- /dev/null +++ b/pre-commit @@ -0,0 +1,3 @@ +npm run build +git add dist +exit 0 \ No newline at end of file diff --git a/src/index.js b/src/index.js index ec2b9b1..1a6b4bc 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,9 @@ const core = require('@actions/core'); const https = require('https'); const fs = require('fs'); -const repo = process.env.GITHUB_REPOSITORY; +const repo = process.env.SPECIFIC_REPO || process.env.GITHUB_REPOSITORY; + +console.log(repo); /** * get today and last week in format YYYY-MM-DD @@ -50,6 +52,9 @@ async function request(search) { data += chunk; }); res.on('end', () => { + console.log(url, JSON.parse(data)); + exec(`echo ${url}`); + exec(`echo ${JSON.parse(data)}`); resolve(JSON.parse(data)); }); }) @@ -143,7 +148,7 @@ async function getContributorIds() { `commits?q=repo:${repo}+author-date:${since}..${until}` ); const contributors = Array.from( - new Set(result.items.map((item) => item.author.login)) + new Set(result?.items?.map((item) => item.author.login) || []) ); return contributors.join(',') + ` (${contributors.length})`; }