codeant-ai-for-open-source[bot] commented on code in PR #38124:
URL: https://github.com/apache/superset/pull/38124#discussion_r2833122069


##########
superset-frontend/scripts/oxlint-metrics-uploader.js:
##########
@@ -17,19 +17,20 @@
  * under the License.
  */
 const { execSync } = require('child_process');
-const { google } = require('googleapis');
+const { GoogleAuth } = require('google-auth-library');
+const googleSheets = require('@googleapis/sheets');
 
 const { SPREADSHEET_ID } = process.env;
 const SERVICE_ACCOUNT_KEY = JSON.parse(process.env.SERVICE_ACCOUNT_KEY || 
'{}');
 
 // Only set up Google Sheets if we have credentials
 let sheets;
 if (SERVICE_ACCOUNT_KEY.client_email) {
-  const auth = new google.auth.GoogleAuth({
+  const auth = new GoogleAuth({
     credentials: SERVICE_ACCOUNT_KEY,
     scopes: ['https://www.googleapis.com/auth/spreadsheets'],
   });
-  sheets = google.sheets({ version: 'v4', auth });
+  sheets = googleSheets({ version: 'v4', auth });

Review Comment:
   **Suggestion:** The value returned by `require('@googleapis/sheets')` is a 
module object, not a callable function, so invoking `googleSheets({ ... })` 
will throw a `TypeError` at runtime when initializing the Sheets client; 
instead, you need to call the module's `sheets` factory function. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Lint metrics uploader script crashes during module initialization.
   - ⚠️ `npm run lint-stats` CI job cannot complete successfully.
   - ⚠️ Google Sheets tech-debt dashboard stops receiving updated lint metrics.
   ```
   </details>
   
   ```suggestion
     sheets = googleSheets.sheets({ version: 'v4', auth });
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. From the repository root, navigate to the frontend and ensure 
dependencies are
   installed so `@googleapis/sheets` is available, as declared in
   `superset-frontend/package.json:97-115` (dependency `"@googleapis/sheets": 
"^13.0.1"`).
   
   2. Export a valid `SERVICE_ACCOUNT_KEY` environment variable containing JSON 
with a
   `client_email` field and set `SPREADSHEET_ID`, so the condition at
   `superset-frontend/scripts/oxlint-metrics-uploader.js:26-28` (`if
   (SERVICE_ACCOUNT_KEY.client_email)`) evaluates to true.
   
   3. Run the metrics uploader via the npm script `lint-stats` defined in
   `superset-frontend/package.json:39-63` (`"lint-stats": "node
   ./scripts/oxlint-metrics-uploader.js"`), which executes
   `scripts/oxlint-metrics-uploader.js`.
   
   4. During module initialization in `oxlint-metrics-uploader.js:19-34`, Node 
requires
   `@googleapis/sheets` into `googleSheets` (line 21) and then executes `sheets 
=
   googleSheets({ version: 'v4', auth });` at line 33; since 
`require('@googleapis/sheets')`
   returns a module object with a `.sheets` factory function rather than a 
callable function
   itself, this call throws `TypeError: googleSheets is not a function`, 
aborting the script
   before any linting or Google Sheets writes occur.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/scripts/oxlint-metrics-uploader.js
   **Line:** 33:33
   **Comment:**
        *Type Error: The value returned by `require('@googleapis/sheets')` is a 
module object, not a callable function, so invoking `googleSheets({ ... })` 
will throw a `TypeError` at runtime when initializing the Sheets client; 
instead, you need to call the module's `sheets` factory function.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38124&comment_hash=77ce48ebc83376e084094831f39242acd16406c5d6e364eb92b8af6c18045fb8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38124&comment_hash=77ce48ebc83376e084094831f39242acd16406c5d6e364eb92b8af6c18045fb8&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to