Skip to content

Refactor rendercode.ts to remove duplicates#552

Closed
tibisabau wants to merge 2 commits intofedify-dev:mainfrom
tibisabau:415-refactor-rendercode
Closed

Refactor rendercode.ts to remove duplicates#552
tibisabau wants to merge 2 commits intofedify-dev:mainfrom
tibisabau:415-refactor-rendercode

Conversation

@tibisabau
Copy link

Summary

Refactored rendercode.ts to eliminate code duplication between renderRequest()
and renderResponse() functions by extracting common rendering logic into a
shared private function.

Related issue

Changes

  • Extracted common rendering logic from renderRequest() and renderResponse()
    into a private render() function
  • Modified renderRequest() to construct its status line and delegate to
    render()
  • Modified renderResponse() to construct its status line and delegate to
    render()

Benefits

  • Reduced code duplication by approximately 20 lines of duplicate code
  • Improved maintainability - changes to the rendering logic now only need to
    be made in one place
  • Preserved existing functionality and public API without breaking changes
  • Type-safe implementation using Request | Response union type

Checklist

  • Did you add a changelog entry to the CHANGES.md?
  • Did you write some relevant docs about this change (if it's a new feature)?
  • Did you write a regression test to reproduce the bug (if it's a bug fix)?
  • Did you write some tests for this change (if it's a new feature)?
  • Did you run mise test on your machine?

Additional notes

The code in this pull request was generated by GitHub Copilot with the Claude Sonnet 4.5 model.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tibisabau, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the rendercode.ts file to significantly reduce code duplication within the renderRequest and renderResponse functions. By extracting their shared logic into a new private render helper function, the change enhances maintainability and readability without altering the external behavior or public API. This ensures that future modifications to the rendering process only need to be applied in a single location.

Highlights

  • Code Duplication Removal: Extracted common rendering logic from renderRequest() and renderResponse() into a new private render() function.
  • Refactored renderRequest(): Modified renderRequest() to construct its status line and delegate the rest of the rendering to the new render() function.
  • Refactored renderResponse(): Modified renderResponse() to construct its status line (including handling statusText fallback) and delegate the rest of the rendering to the new render() function.
  • Improved Maintainability: Reduced code duplication by approximately 20 lines, enhancing maintainability and ensuring type safety with the Request | Response union type.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively refactors rendercode.ts to remove duplicated logic between renderRequest() and renderResponse() by introducing a shared render() function. The change improves code maintainability and is well-executed. I have a couple of minor suggestions to remove redundant await keywords, which is a good practice for performance.

code += `\n${body}`;
return code;
const statusLine = `${request.method} ${url.pathname + url.search}`;
return await render(request, statusLine);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The await keyword is not necessary when returning a promise from an async function like this. You can return the promise directly, which avoids creating an unnecessary microtask and is slightly more performant.

Suggested change
return await render(request, statusLine);
return render(request, statusLine);

}\n`;
for (const [key, value] of response.headers.entries()) {
}`;
return await render(response, statusLine);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the comment on renderRequest, the await keyword is redundant here and can be removed.

Suggested change
return await render(response, statusLine);
return render(response, statusLine);

@dahlia
Copy link
Member

dahlia commented Feb 2, 2026

Did you vibe-code it? Please read our AI usage policy first. Thanks.

@dahlia dahlia closed this Feb 2, 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.

Reduce the duplicated codes in rendercode.ts

2 participants