Skip to content

Commit 37809d6

Browse files
committed
Fix Semantic Version Comparison in HealthService using 'semver' #7584
1 parent 207320e commit 37809d6

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "Fix Semantic Version Comparison in HealthService using 'semver'"
3+
labels: bug, AI
4+
---
5+
6+
GH ticket id: #7584
7+
8+
**Epic:** #7564
9+
**Phase:** 1
10+
**Assignee:** tobiu
11+
**Status:** To Do
12+
13+
## Description
14+
15+
The `HealthService.#checkGhVersion()` method currently uses string comparison (`>=`) to check if the installed `gh` CLI version meets the minimum requirement. This is a critical bug that breaks for semantic versioning (e.g., "2.9.0" incorrectly compares as greater than "2.10.0").
16+
17+
This will be fixed by incorporating the official `semver` npm package.
18+
19+
## Acceptance Criteria
20+
21+
1. The `semver` package is added as a `devDependency` to `package.json`.
22+
2. `npm install` is run to update the `node_modules` directory.
23+
3. `HealthService.mjs` is updated to import the `semver` package.
24+
4. The `#checkGhVersion()` method is refactored to use `semver.gte(currentVersion, minVersion)` for the version comparison instead of the incorrect string comparison.

ai/mcp/server/github-workflow/services/HealthService.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {exec} from 'child_process';
22
import {promisify} from 'util';
33
import aiConfig from '../../config.mjs';
44
import Base from '../../../../../src/core/Base.mjs';
5+
import semver from 'semver';
56

67
const execAsync = promisify(exec);
78

@@ -40,14 +41,16 @@ class HealthService extends Base {
4041
const versionMatch = stdout.match(/gh version ([\d.]+)/);
4142
if (versionMatch) {
4243
const currentVersion = versionMatch[1];
43-
if (currentVersion >= aiConfig.githubWorkflow.minGhVersion) {
44+
const minVersion = aiConfig.githubWorkflow.minGhVersion;
45+
46+
if (semver.gte(currentVersion, minVersion)) {
4447
return {installed: true, versionOk: true, version: currentVersion};
4548
} else {
4649
return {
4750
installed: true,
4851
versionOk: false,
4952
version : currentVersion,
50-
error : `gh version (${currentVersion}) is outdated. Please upgrade to at least ${aiConfig.githubWorkflow.minGhVersion}.`
53+
error : `gh version (${currentVersion}) is outdated. Please upgrade to at least ${minVersion}.`
5154
};
5255
}
5356
}

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
"parse5" : "^8.0.0",
125125
"postcss" : "^8.5.6",
126126
"sass" : "^1.93.2",
127+
"semver" : "^7.5.4",
127128
"siesta-lite" : "5.5.2",
128129
"terser" : "^5.44.0",
129130
"url" : "^0.11.4",

0 commit comments

Comments
 (0)