Skip to content

Fix: Replace invalid .link() usage in checkBranchPush.js with Markdown link and improve error handling#358

Open
Manas-Dikshit wants to merge 2 commits into
oppia:masterfrom
Manas-Dikshit:master
Open

Fix: Replace invalid .link() usage in checkBranchPush.js with Markdown link and improve error handling#358
Manas-Dikshit wants to merge 2 commits into
oppia:masterfrom
Manas-Dikshit:master

Conversation

@Manas-Dikshit

Copy link
Copy Markdown

The Oppiabot module checkBranchPush.js handles checks for branches that are force-pushed.
While reviewing the file, I noticed that the code was using the JavaScript string method .link() to generate an HTML link in a comment body.

Issue

The .link() method is a deprecated browser-only API (String.prototype.link) and is not supported in Node.js, which Oppiabot runs on (via Probot/Heroku).
As a result, this would throw a TypeError: 'link' is not a function during runtime, causing the force-push handler to fail silently without commenting or closing the PR.

Additionally, the function:
Used a slightly confusing variable name (isNotPrBranch)
Did not include try/catch blocks around API calls, which could cause the bot to crash if the GitHub API rate-limited or returned an error
Used a smart apostrophe (’) that can cause encoding issues in some environments

Fix Implemented
Replaced the invalid .link() call with a valid Markdown link, which renders correctly in GitHub comments:
const link = 'here (point 5)';

Renamed isNotPrBranch → isWhitelistedBranch for better readability.
Added try/catch wrappers around GitHub API calls to prevent runtime crashes.
Replaced curly apostrophe with a straight one for consistency and reliability.
Added inline comments and minor readability improvements.

Impact
Before this fix:
The bot would throw an error and fail to respond when a force push occurred on a non-whitelisted branch.
No explanatory comment would be posted to the PR, and the PR wouldn’t be closed automatically.

After this fix:
The bot correctly identifies the PR associated with a force push.
It comments politely explaining why force pushes are disallowed, with a valid link to the contributing guide.
It safely closes the PR without crashing.
Improved stability and maintainability of the Oppiabot codebase.

Testing
Verified that npm run dev runs successfully with the fix.
Simulated a force-push event on a test PR; Oppiabot commented and closed the PR as expected.
Checked Markdown rendering of the link in the PR comment on GitHub — displays correctly.

Checklist
Fixed runtime compatibility issue
Added robust error handling
Improved code readability and comments
Verified Markdown link rendering
All tests passing locally (npm test)

@Manas-Dikshit Manas-Dikshit requested a review from a team as a code owner December 25, 2025 18:21
@Manas-Dikshit Manas-Dikshit requested review from Vir-8 and removed request for a team December 25, 2025 18:21
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