Copilot commented on code in PR #77635:
URL: https://github.com/apache/airflow/pull/77635#discussion_r4743716813


##########
scripts/ci/prek/upgrade_important_versions.py:
##########
@@ -316,6 +317,50 @@ def get_latest_pypi_version(package_name: str, 
should_upgrade: bool) -> str:
     return latest_version
 
 
+def get_latest_npm_version(
+    package_name: str,
+    should_upgrade: bool,
+    pinned_in: Path = AIRFLOW_ROOT_PATH / ".pre-commit-config.yaml",
+) -> str:
+    """Return the newest stable npm release of a package that is older than 
the cooldown window.
+
+    Never returns a version older than the one already pinned in 
``pinned_in``: a pin set by
+    hand to a release still inside the cooldown must not be downgraded by the 
next run.
+    """
+    if not should_upgrade:
+        return ""
+    if VERBOSE:
+        console.print(f"[bright_blue]Fetching latest version for 
{package_name} from npm")
+    response = requests.get(
+        f"https://registry.npmjs.org/{package_name}";, headers={"User-Agent": 
"Python requests"}
+    )
+    response.raise_for_status()
+    data = response.json()
+    publish_times: dict[str, str] = data.get("time", {})
+    cutoff = datetime.now(UTC) - timedelta(days=COOLDOWN_DAYS)
+    # npm marks pre-releases with a "-" suffix (1.2.0-beta.1).
+    stable = sorted(
+        ((Version(v), v) for v in data.get("versions", {}) if "-" not in v),
+        reverse=True,
+    )
+    latest_version = ""
+    for _, version in stable:
+        published = publish_times.get(version)
+        if published and datetime.fromisoformat(published.replace("Z", 
"+00:00")) <= cutoff:
+            latest_version = version
+            break
+    if not latest_version:
+        latest_version = data["dist-tags"]["latest"]

Review Comment:
   When no stable release is outside the cooldown, this fallback selects 
`dist-tags.latest` without applying either filter. A package whose available 
releases are all recent will therefore be upgraded immediately; a prerelease 
tagged `latest` can also be selected. Return an empty version to leave the 
existing pin unchanged when no release qualifies, and update the fallback test 
to enforce that behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to