Skip to content

Conversation

@parthea
Copy link
Contributor

@parthea parthea commented Dec 12, 2025

When adding a new API version to an existing library, the contents of the existing package level CHANGELOG.md file is removed. The issue is that a new changelog is created unconditionally here:

_create_new_changelog_for_library(library_id, output)

As an example, the command below adds the client library code for google/cloud/maintenance/api/v1 to an existing package google-cloud-maintenance-api

librarian generate -api=google/cloud/maintenance/api/v1 -library=google-cloud-maintenance-api

After running the command locally, see that the contents of this CHANGELOG.md is gone. See below

(py392) partheniou@partheniou-vm-3:~/git/google-cloud-python$ git diff packages/google-cloud-maintenance-api/CHANGELOG.md
diff --git a/packages/google-cloud-maintenance-api/CHANGELOG.md b/packages/google-cloud-maintenance-api/CHANGELOG.md
index 6436543a6e6..d884ea3cedb 100644
--- a/packages/google-cloud-maintenance-api/CHANGELOG.md
+++ b/packages/google-cloud-maintenance-api/CHANGELOG.md
@@ -3,31 +3,3 @@
 [PyPI History][1]
 
 [1]: https://pypi.org/project/google-cloud-maintenance-api/#history
-
-## [0.2.0](https://github.com/googleapis/google-cloud-python/compare/google-cloud-maintenance-api-v0.1.1...google-cloud-maintenance-api-v0.2.0) (2025-10-20)
-
-
-### Features
-
-* Add support for Python 3.14  ([98ee71abc0f97c88239b50bf0e0827df19630def](https://github.com/googleapis/google-cloud-python/commit/98ee71abc0f97c88239b50bf0e0827df19630def))
-
-
-### Bug Fixes
-
-* Deprecate credentials_file argument  ([98ee71abc0f97c88239b50bf0e0827df19630def](https://github.com/googleapis/google-cloud-python/commit/98ee71abc0f97c88239b50bf0e0827df19630def))
-
-## [0.1.1](https://github.com/googleapis/google-cloud-python/compare/google-cloud-maintenance-api-v0.1.0...google-cloud-maintenance-api-v0.1.1) (2025-07-23)
-
-
-### Documentation
-
-* Add missing comments for messages ([f955689](https://github.com/googleapis/google-cloud-python/commit/f9556891d9224fefd09202539a7d5830f724e2c4))
-
-## 0.1.0 (2025-06-23)

With the fix in this PR, a package level changelog will only be created if it is not present. An existing changelog will remain untouched.

@gemini-code-assist
Copy link

Summary of Changes

Hello @parthea, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial fix to the librarian tool, preventing the accidental deletion of existing package-level CHANGELOG.md files. Previously, when generating new API versions for existing libraries, the tool would unconditionally overwrite the changelog, leading to loss of release history. The updated logic ensures that a new changelog is only created if one does not already exist, thereby preserving valuable historical information.

Highlights

  • Bug Fix: Resolved an issue where adding a new API version to an existing library would unintentionally delete the contents of its CHANGELOG.md file.
  • Conditional Changelog Creation: The _create_new_changelog_for_library function in cli.py now only executes if the target library's directory (and thus its changelog) does not already exist, preventing data loss.
  • Path Resolution: Introduced logic to correctly determine the library's path, accounting for monorepo structures, to ensure the existence check is accurate.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@parthea parthea marked this pull request as ready for review December 12, 2025 16:29
@parthea parthea requested review from a team as code owners December 12, 2025 16:29
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where CHANGELOG.md was being overwritten when adding a new API version to an existing library. The fix correctly checks if the library directory exists before creating a new changelog, which effectively prevents this issue. The logic is sound. I've included one suggestion to use pathlib more idiomatically for path construction, which will improve code clarity and robustness.

Comment on lines +295 to +296
path_to_library = f"packages/{library_id}" if is_mono_repo else "."
if not Path(f"{repo}/{path_to_library}").exists():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved readability and cross-platform compatibility, it's better to use pathlib's / operator for joining path components rather than f-string formatting. This is the idiomatic way to work with pathlib and avoids potential issues with path separators.

Suggested change
path_to_library = f"packages/{library_id}" if is_mono_repo else "."
if not Path(f"{repo}/{path_to_library}").exists():
path_to_library_str = f"packages/{library_id}" if is_mono_repo else "."
if not (Path(repo) / path_to_library_str).exists():

@parthea parthea merged commit b511ec0 into main Dec 12, 2025
25 checks passed
@parthea parthea deleted the create-package-changelog-if-not-present branch December 12, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants