microsoft / microsoft/FluidFramework
Duplicate code: latestVersions commands repeat ADO logging/variable-setting block
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.9k
- Forks
- 586
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 146
Description
Analysis of commit 19a716b6250d945acb514205d6f452bd524b4a57
Assignee: @copilot
Summary
The latestVersions CI command logic contains an identical (>10 LOC) block that logs status/warnings and sets Azure DevOps output variables. This block is duplicated between the deprecated command (check/latestVersions) and its replacement (vnext/check/latestVersions), increasing maintenance cost and risk of behavior drift.
Duplication Details
Pattern: ADO output variable + warning logging for isLatestInMajor result
- Severity: Medium
- Occurrences: 2 (exact/near-exact duplication)
- Locations:
build-tools/packages/build-cli/src/commands/check/latestVersions.ts(lines 51–79)build-tools/packages/build-cli/src/commands/vnext/check/latestVersions.ts(lines 63–91)
Code sample (duplicated block)
if (result.isLatest) {
this.log(
`Version \$\{versionInput.version} is the latest version for major version \$\{result.majorVersion}`,
);
this.log(`##vso[task.setvariable variable=shouldDeploy;isoutput=true]true`);
this.log(
`##vso[task.setvariable variable=majorVersion;isoutput=true]\$\{result.majorVersion}`,
);
return;
}
if (result.latestVersion !== undefined) {
this.log(
`##[warning]skipping deployment stage. input version \$\{versionInput.version} does not match the latest version \$\{result.latestVersion}`,
);
this.log(`##vso[task.setvariable variable=shouldDeploy;isoutput=true]false`);
this.log(
`##vso[task.setvariable variable=majorVersion;isoutput=true]\$\{result.majorVersion}`,
);
return;
}
this.log(
`##[warning]No major version found corresponding to input version \$\{versionInput.version}`,
);
this.log(`##vso[task.setvariable variable=shouldDeploy;isoutput=true]false`);
this.log(
`##vso[task.setvariable variable=majorVersion;isoutput=true]\$\{result.majorVersion}`,
);
Impact Analysis
- Maintainability: Any tweak to CI messaging/ADO variables must be made twice.
- Bug Risk: Small differences between the two command implementations can lead to inconsistent pipeline behavior.
- Code Bloat: Duplicated logic adds noise in two command entrypoints.
Refactoring Recommendations
-
Extract the shared result-handling block into a helper
- Suggested location:
build-tools/packages/build-cli/src/library/latestVersions.ts - Suggested shape:
logLatestVersionsAdoResult(logFn, inputVersion, result)- where
logFnisthis.log.bind(this)
- Then both commands call the shared helper.
- Suggested location:
-
Keep the deprecated command as a thin wrapper
- Since
check/latestVersions.tsis already deprecated, keep only the parts that differ (argument parsing + version discovery), then delegate result reporting to the shared helper.
- Since
Implementation Checklist
- Create helper in
src/library/latestVersions.tsfor ADO variable/reporting logic - Update both commands to use the helper
- Verify output text and ADO variable names are unchanged
Analysis Metadata
- Analyzed Files: 2 (plus targeted scanning of build-cli sources)
- Detection Method: Serena semantic inspection + cross-file duplicate-window scan
- Commit:
19a716b6250d945acb514205d6f452bd524b4a57 - Analysis Date: 2026-04-05
Generated by Duplicate Code Detector · ◷
To install this agentic workflow, run
gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read build-tools/packages/build-cli/src/commands/check/latestVersions.ts and src/commands/vnext/check/latestVersions.ts, then inspect src/library/latestVersions.ts for the shared helper location. Extract the repeated ADO reporting logic, update both commands, and verify that the output text and ADO variable names remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ci-cd, cli, tooling
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100