Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions .github/release-note-generation/split_release_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def detect_modules(root_directory: Path):
tree = ET.parse(module_pom_xml)
root = tree.getroot()
version = root.find('mvn:version', POM_NAMESPACES).text
api_name = None
if owlbot_yaml_path.exists():
# If OwlBot configuration file exists (most cases), it's the better
# source to get the OwlBot-generated pull request title prefix than
Expand All @@ -78,21 +79,21 @@ def detect_modules(root_directory: Path):
match = re.search(r'api-name: (.+)', owlbot_yaml_content)
if match:
api_name = match.group(1)
modules.append(LibraryModule(module_path, api_name,
version,
changelog))

if not api_name:
# Fallback to repo-metadata.json (e.g. for vertexai or Spanner transitional state)
if repo_metadata_path.exists():
with open(repo_metadata_path, 'r') as file:
repo_metadata = json.load(file)
api_name = repo_metadata.get('api_shortname')

if api_name:
modules.append(LibraryModule(module_path, api_name,
version,
changelog))
else:
# vertexai (handwritten) does not have OwlBot yaml file
with open(repo_metadata_path, 'r') as file:
repo_metadata = json.load(file)
api_name = repo_metadata['api_shortname']
if api_name:
modules.append(LibraryModule(repo_metadata_path.parent, api_name,
version,
changelog))
else:
raise Exception(f'repo_metadata_path {repo_metadata_path} does'
f' not have api_shortname field')
raise Exception(f'Could not determine api-name for {repo_metadata_path}')


return modules

Expand Down Expand Up @@ -133,7 +134,7 @@ def group_changes_by_api(main_changes: [str]):
elif section == BUG_FIXES_SECTION:
api_to_changelog[api_name].bug_fixes.append(note)
elif section == DEPENDENCIES_SECTION:
api_to_changelog[api_name].dependencies.append(note)
api_to_changelog[api_name].dependency_upgrades.append(note)
Comment thread
meltsufin marked this conversation as resolved.
return api_to_changelog


Expand Down
31 changes: 29 additions & 2 deletions .github/release-note-generation/unit_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import unittest
import tempfile
import json
from pathlib import Path

# Unit tests for split_release_note.py

from split_release_note import LibraryModule, create_changelog_entry, group_changes_by_api, ChangesOnApi
from pathlib import Path
from split_release_note import LibraryModule, create_changelog_entry, group_changes_by_api, ChangesOnApi, detect_modules

dummy_module = LibraryModule(
Path('release-note-generation/test/java-analyics-admin'),
Expand Down Expand Up @@ -81,6 +83,31 @@ def test_group_changes_by_api(self):
['No change']),
['No change'])

def test_detect_modules_fallback(self):
with tempfile.TemporaryDirectory() as tmpdirname:
tmp_path = Path(tmpdirname)
module_path = tmp_path / "java-spanner"
module_path.mkdir()

# Create minimal pom.xml
pom_path = module_path / "pom.xml"
with open(pom_path, "w") as f:
f.write('<project xmlns:mvn="http://maven.apache.org/POM/4.0.0"><mvn:version>1.0.0</mvn:version></project>')

# Create .repo-metadata.json with api_shortname
metadata_path = module_path / ".repo-metadata.json"
with open(metadata_path, "w") as f:
json.dump({"api_shortname": "spanner"}, f)

# Create CHANGELOG.md
changelog_path = module_path / "CHANGELOG.md"
changelog_path.touch()

modules = detect_modules(tmp_path)
self.assertEqual(len(modules), 1)
self.assertEqual(modules[0].api_name, "spanner")
self.assertEqual(modules[0].version, "1.0.0")


if __name__ == "__main__":
unittest.main()
Loading