Skip to content

[Duplicate Code] getCopilotModel() duplicates getConfigEnvValue() logic in api-proxy-service.ts #3307

@github-actions

Description

@github-actions

Duplicate Code Opportunity

Summary

  • Pattern: getCopilotModel() is a near-exact duplicate of the more general getConfigEnvValue() defined four lines below it in the same file
  • Locations: src/services/api-proxy-service.ts lines 39–61
  • Impact: Two functions doing the same env-precedence lookup logic (additionalEnv ?? envFile ?? process.env); any future change to the lookup priority must be applied to both

Evidence

getCopilotModel (lines 39–49):

function getCopilotModel(config: WrapperConfig): string | undefined {
  const envFileModel = config.envFile
    ? readEnvFile(config.envFile).COPILOT_MODEL
    : undefined;
  const model =
    config.additionalEnv?.COPILOT_MODEL ??
    envFileModel ??
    (config.envAll ? process.env.COPILOT_MODEL : undefined);
  const normalizedModel = model?.trim();
  return normalizedModel || undefined;
}

getConfigEnvValue (lines 51–61):

function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
  const envFileValue = config.envFile
    ? readEnvFile(config.envFile)[key]
    : undefined;
  const value =
    config.additionalEnv?.[key] ??
    envFileValue ??
    (config.envAll ? process.env[key] : undefined);
  const normalizedValue = value?.trim();
  return normalizedValue || undefined;
}

getCopilotModel is exactly getConfigEnvValue(config, 'COPILOT_MODEL').

Suggested Refactoring

Remove getCopilotModel and replace its single call site (line 297) with:

const copilotModel = getConfigEnvValue(config, 'COPILOT_MODEL');

This is a one-line change plus deleting the 10-line function. The getConfigEnvValue name already communicates the intent clearly.

If the specialised name is valued for readability, keep it as a one-liner wrapper:

const getCopilotModel = (config: WrapperConfig) => getConfigEnvValue(config, 'COPILOT_MODEL');

Affected Files

  • src/services/api-proxy-service.ts — lines 39–49 (function to remove), line 297 (call site to update)

Effort Estimate

Low — one-line fix; the function has a single call site.


Detected by Duplicate Code Detector workflow. Run date: 2026-05-17

Generated by Duplicate Code Detector · ● 8M ·

  • expires on Jun 16, 2026, 9:58 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions