gemini-code-assist[bot] commented on code in PR #38711: URL: https://github.com/apache/beam/pull/38711#discussion_r3312889350
########## scripts/tools/gcp_bom_upgrade_check.py: ########## @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import urllib.request +import re +import os + +def get_latest_bom(): + url = "https://repo1.maven.org/maven2/com/google/cloud/libraries-bom/maven-metadata.xml" + with urllib.request.urlopen(url) as response: + xml = response.read().decode('utf-8') Review Comment:  Using `urllib.request.urlopen` without a timeout can cause the script to hang indefinitely if the network connection is unstable or Maven Central is unresponsive. Specifying a timeout prevents the CI/CD workflow from blocking. ```suggestion url = "https://repo1.maven.org/maven2/com/google/cloud/libraries-bom/maven-metadata.xml" with urllib.request.urlopen(url, timeout=15) as response: xml = response.read().decode('utf-8') ``` ########## scripts/tools/gcp_bom_upgrade_check.py: ########## @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import urllib.request +import re +import os + +def get_latest_bom(): + url = "https://repo1.maven.org/maven2/com/google/cloud/libraries-bom/maven-metadata.xml" + with urllib.request.urlopen(url) as response: + xml = response.read().decode('utf-8') + match = re.search(r'<release>([^<]+)</release>', xml) + if match: + return match.group(1) + raise RuntimeError("Could not find latest release in Maven metadata") + +def get_current_bom(): + path = "buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy" + with open(path) as f: + content = f.read() Review Comment:  Using a hardcoded relative path assumes the script is always executed from the repository root. If the script is run from another directory (e.g., from within `scripts/tools/`), it will fail with a `FileNotFoundError`. Resolving the path relative to the script's location makes it more robust. ```suggestion def get_current_bom(): script_dir = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(script_dir, "..", "..", "buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy") with open(path) as f: content = f.read() ``` ########## scripts/tools/gcp_bom_upgrade_check.py: ########## @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import urllib.request +import re +import os + +def get_latest_bom(): + url = "https://repo1.maven.org/maven2/com/google/cloud/libraries-bom/maven-metadata.xml" + with urllib.request.urlopen(url) as response: + xml = response.read().decode('utf-8') + match = re.search(r'<release>([^<]+)</release>', xml) + if match: + return match.group(1) + raise RuntimeError("Could not find latest release in Maven metadata") + +def get_current_bom(): + path = "buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy" + with open(path) as f: + content = f.read() + match = re.search(r'google_cloud_platform_libraries_bom\s*:\s*[\"\']com\.google\.cloud:libraries-bom:([0-9.]+)[\"\']', content) + if match: + return match.group(1) + raise RuntimeError("Could not find current libraries-bom in BeamModulePlugin.groovy") + +def to_tuple(version_str): + return tuple(map(int, version_str.split('.'))) Review Comment:  If the version string contains non-integer suffixes (e.g., `26.1.0-sp1` or `26.1.0-alpha`), `int()` will raise a `ValueError`. Parsing only the leading digits of each dot-separated component makes the version comparison robust against non-standard version strings. ```suggestion def to_tuple(version_str): parts = [] for part in version_str.split('.'): match = re.match(r'^(\d+)', part) parts.append(int(match.group(1)) if match else 0) return tuple(parts) ``` -- 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]
