Skip to content

docs(stats): apply CodeRabbit auto-fixes and update README for !stats command - #30

Merged
m9tzin merged 5 commits into
mainfrom
dev
Apr 24, 2026
Merged

docs(stats): apply CodeRabbit auto-fixes and update README for !stats command#30
m9tzin merged 5 commits into
mainfrom
dev

Conversation

@m9tzin

@m9tzin m9tzin commented Apr 24, 2026

Copy link
Copy Markdown
Owner

This pull request clarifies and enforces the requirement that the /stats endpoint must be called with a player nickname, both in the backend logic and in the documentation. It also improves how query parameters are parsed for all endpoints, ensuring consistent handling of string and array types. The changes update the user-facing documentation and error messaging to prevent confusion about required parameters.

Backend logic and API behavior:

  • The /stats endpoint now requires a player (or nick) query parameter; if missing, it returns a 200 response with a plain text prompt asking for the FACEIT nickname, rather than using a default player. [1] [2]
  • The logic for parsing the player and nick query parameters is now consistent across /stats, /elo, and /streak endpoints, correctly handling both string and array values. [1] [2] [3]

Documentation updates:

  • The README.md has been updated to clearly state that the !stats command requires a nickname and to show the new required usage and error message when the nickname is missing. [1] [2] [3] [4] [5]
  • The /stats endpoint description in the server startup log now explicitly notes that the player parameter is required.

coderabbitai Bot and others added 5 commits April 22, 2026 20:51
Fixed 3 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
Fixed 3 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
…er nickname is required for the !stats command and improve usage examples
@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The pull request updates the /stats endpoint to require either a player or nick query parameter, introducing a shared getStringParam helper function across multiple route files to normalize query input handling. When the parameter is missing, the endpoint returns HTTP 200 with an instruction message. Documentation and server logs are updated accordingly.

Changes

Cohort / File(s) Summary
Documentation
README.md, src/index.js
Updates API documentation and console output to reflect that the /stats endpoint now requires a player parameter, and documents the instruction message response when the parameter is missing.
Route Parameter Normalization
src/routes/elo.js, src/routes/streak.js
Introduces a getStringParam helper function to safely extract and trim query parameters (player or nick), handling both string and array-valued inputs, replacing previous optional-chaining logic.
Stats Route Enforcement
src/routes/stats.js
Adds required parameter validation using the new getStringParam helper; returns HTTP 200 with instruction message if neither player nor nick is provided. Simplifies cache key generation and updates error messages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #27: Modifies the same route query-parameter parsing logic for /elo, /stats, and /streak, introducing consistent parameter handling patterns across these endpoints.

Suggested labels

enhancement


🐰 A validation check hops into view,
"Player required!" the message rings true,
Three routes now parse with helpers so neat,
Early returns keep the API sweet.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'docs(stats)' and 'update README for !stats command', which aligns with README.md changes, but overstates the scope by including 'apply CodeRabbit auto-fixes' when the PR also contains functional changes to route handlers (stats.js, elo.js, streak.js). Revise the title to accurately reflect both documentation updates and the functional changes to route handlers, such as: 'feat(stats): require player parameter and update documentation' or 'refactor(stats): add player parameter validation with helper function'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

175-192: ⚠️ Potential issue | 🟡 Minor

Documented response text does not match what the server actually sends.

README documents the missing-player body as:

  • Indica o nickname FACEIT — ex.: !stats s1mple

But src/routes/stats.js (line 42) sends:

  • Indique o nickname FACEIT (ex.: !stats s1mple)

Differences: verb form (Indica vs Indique — imperative mood is Indique in European/BR Portuguese) and punctuation (em-dash vs parentheses). Please reconcile both occurrences (lines 175 and 192 here) with the code, or vice versa, so the curl example output shown in the README matches reality.

📝 Proposed README alignment (if keeping the code text)
-**Missing `player`:** `200` with body `Indica o nickname FACEIT — ex.: !stats s1mple` (plain text for Twitch `urlfetch`).
+**Missing `player`:** `200` with body `Indique o nickname FACEIT (ex.: !stats s1mple)` (plain text for Twitch `urlfetch`).
...
-# Indica o nickname FACEIT — ex.: !stats s1mple
+# Indique o nickname FACEIT (ex.: !stats s1mple)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 175 - 192, The README message for the missing-player
response doesn't match the actual text returned by the server; update the README
occurrences (around lines 175 and 192) to exactly match the string emitted by
src/routes/stats.js (line 42): "Indique o nickname FACEIT (ex.: !stats s1mple)"
so the curl example output shown in README reflects reality.
🧹 Nitpick comments (1)
src/routes/elo.js (1)

27-28: Extract getStringParam to a shared helper (DRY).

The exact same one-liner is now inlined in src/routes/elo.js, src/routes/streak.js, and src/routes/stats.js (with a slightly different formatting in stats.js). Any future tweak (e.g. handling empty strings, array of multiple values, non-ASCII whitespace) would need to be applied in three places and risks diverging — and the three copies already vary in code style.

Consider extracting to something like src/utils/queryParams.js and importing it from each route:

♻️ Proposed refactor
// src/utils/queryParams.js
export const getStringParam = (p) => {
  if (typeof p === "string") return p.trim();
  if (Array.isArray(p)) return p[0]?.trim() ?? null;
  return null;
};

Then in each route:

+import { getStringParam } from "../utils/queryParams.js";
 ...
-    const getStringParam = (p) => typeof p === 'string' ? p.trim() : Array.isArray(p) ? p[0]?.trim() ?? null : null;
-    const playerQuery = getStringParam(req.query.player) || getStringParam(req.query.nick) || null;
+    const playerQuery =
+      getStringParam(req.query.player) || getStringParam(req.query.nick) || null;

Also note: the trailing || null in playerQuery is redundant — getStringParam already returns null for non-string/non-array inputs, and any falsy string result ("") combined with a missing second param still yields undefinednull via the final || null, so it can be kept purely for explicitness. Minor.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/elo.js` around lines 27 - 28, Extract the one-liner getStringParam
into a shared helper (e.g., create src/utils/queryParams.js exporting
getStringParam) and replace the inline definitions in src/routes/elo.js,
src/routes/streak.js, and src/routes/stats.js with an import of that helper;
update each route to call the shared getStringParam for request query values
(e.g., playerQuery) and remove the redundant trailing "|| null" where
getStringParam already returns null for non-string/non-array inputs so behavior
remains identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/routes/stats.js`:
- Around line 39-43: The response string returned when playerQuery is missing in
the stats route handler ("Indique o nickname FACEIT (ex.: !stats s1mple)")
diverges from README.md ("Indica o nickname FACEIT — ex.: !stats s1mple"); pick
one canonical message and make both the code and README consistent. Update the
string in the stats route's missing-player conditional (the block that checks
playerQuery and calls res.status(200).send(...)) to exactly match the README
text, or change the README entries (lines mentioning the curl example) to match
the handler’s string—ensure the message text, punctuation, and example format
are identical in both places.

---

Outside diff comments:
In `@README.md`:
- Around line 175-192: The README message for the missing-player response
doesn't match the actual text returned by the server; update the README
occurrences (around lines 175 and 192) to exactly match the string emitted by
src/routes/stats.js (line 42): "Indique o nickname FACEIT (ex.: !stats s1mple)"
so the curl example output shown in README reflects reality.

---

Nitpick comments:
In `@src/routes/elo.js`:
- Around line 27-28: Extract the one-liner getStringParam into a shared helper
(e.g., create src/utils/queryParams.js exporting getStringParam) and replace the
inline definitions in src/routes/elo.js, src/routes/streak.js, and
src/routes/stats.js with an import of that helper; update each route to call the
shared getStringParam for request query values (e.g., playerQuery) and remove
the redundant trailing "|| null" where getStringParam already returns null for
non-string/non-array inputs so behavior remains identical.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc09be9a-01c9-445e-8d15-0730e419f9cb

📥 Commits

Reviewing files that changed from the base of the PR and between e19107d and e525d7a.

📒 Files selected for processing (5)
  • README.md
  • src/index.js
  • src/routes/elo.js
  • src/routes/stats.js
  • src/routes/streak.js

Comment thread src/routes/stats.js
Comment on lines +39 to +43
if (!playerQuery) {
return res
.status(200)
.send("Indique o nickname FACEIT (ex.: !stats s1mple)");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing-player response text diverges from README.

This handler returns Indique o nickname FACEIT (ex.: !stats s1mple), but README.md (lines 175 and 192) documents the body as Indica o nickname FACEIT — ex.: !stats s1mple. Differences in verb form and punctuation will make the documented curl example output literally wrong. Pick one canonical string and use it in both places.

📝 Proposed fix (keeping the code's imperative form)
     if (!playerQuery) {
       return res
         .status(200)
         .send("Indique o nickname FACEIT (ex.: !stats s1mple)");
     }

…and update README.md lines 175 and 192 to match, or adjust this string to match the README — either direction is fine as long as they agree.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/routes/stats.js` around lines 39 - 43, The response string returned when
playerQuery is missing in the stats route handler ("Indique o nickname FACEIT
(ex.: !stats s1mple)") diverges from README.md ("Indica o nickname FACEIT — ex.:
!stats s1mple"); pick one canonical message and make both the code and README
consistent. Update the string in the stats route's missing-player conditional
(the block that checks playerQuery and calls res.status(200).send(...)) to
exactly match the README text, or change the README entries (lines mentioning
the curl example) to match the handler’s string—ensure the message text,
punctuation, and example format are identical in both places.

@m9tzin
m9tzin merged commit 221c5d5 into main Apr 24, 2026
7 checks passed
@m9tzin m9tzin mentioned this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant