Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11168 clean unused glossary languages #12331

Merged
merged 19 commits into from
Oct 10, 2024

Conversation

gersona
Copy link
Contributor

@gersona gersona commented Aug 24, 2024

Proposed changes

  • new task added to glossary/tasks.py to cleanup unused glossaries
  • glossary cleanup triggered after one translation is removed and on sync glossary languages

Checklist

  • Lint and unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added documentation to describe my feature.
  • I have squashed my commits into logic units.
  • I have described the changes in the commit messages.

Other information

Summary by Sourcery

Add a task to clean up unused glossaries and enhance the glossary synchronization process to include the deletion of empty stale glossaries. Update tests to verify the new functionality.

New Features:

  • Introduce a new task to clean up unused glossaries in the glossary/tasks.py file.

Enhancements:

  • Enhance the sync_glossary_languages function to delete empty stale glossaries in addition to adding missing glossary languages.

Tests:

  • Add a test to verify the cleanup of stale glossaries in weblate/glossary/tests.py.
  • Modify existing tests to account for the cleanup of stale glossaries in weblate/api/tests.py.

Summary by CodeRabbit

  • New Features

    • Introduced automatic removal of stale empty glossaries to enhance documentation management.
    • Added a cleanup mechanism for stale glossaries during the synchronization of glossary languages.
  • Bug Fixes

    • Improved support for Docker network names in automatic suggestion settings.
  • Tests

    • Added a new test to validate the cleanup functionality for stale glossaries.

Copy link

sentry-io bot commented Aug 24, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: weblate/glossary/tasks.py

Function Unhandled Issue
sync_glossary_languages WeblateLockTimeoutError: Lock on component-update-lock-30325 could not be acquired in 5s ...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

@gersona gersona marked this pull request as ready for review August 26, 2024 08:18
@gersona gersona requested a review from orangesunny as a code owner August 26, 2024 08:18
weblate/glossary/tasks.py Outdated Show resolved Hide resolved
Co-authored-by: Michal Čihař <michal@cihar.com>
@nijel
Copy link
Member

nijel commented Sep 4, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Sep 4, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes implement a feature that automatically removes stale empty glossaries in the documentation system, enhancing content management. Additionally, a bug fix allows the use of Docker network names in automatic suggestion settings. The updates include new tests and modifications to existing methods to ensure proper functionality and maintenance of glossary entries.

Changes

Files Change Summary
docs/changes.rst Introduced feature to remove stale empty glossaries and fixed Docker network name usage in suggestions.
weblate/api/tests.py Added _translation_count function to exclude glossary translations in tests.
weblate/glossary/tasks.py Added cleanup_stale_glossaries task to delete empty glossaries; updated sync_glossary_languages logic.
weblate/glossary/tests.py Added test_stale_glossaries_cleanup to validate the cleanup functionality.
weblate/trans/models/translation.py Updated remove method to clarify functionality and invoke cleanup_stale_glossaries asynchronously.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Translation
    participant Task
    participant Database

    User->>Translation: Remove translation
    Translation->>Database: Log removal
    Translation->>Task: Call cleanup_stale_glossaries
    Task->>Database: Check for stale glossaries
    Task->>Database: Remove stale glossaries
Loading

Assessment against linked issues

Objective Addressed Explanation
Cleanup of not needed empty glossaries (#11168)
Automatic cleanup during translation removal (#11168)

🐰 Hopping through the fields so bright,
Stale glossaries gone, what a delight!
With Docker names now in the game,
Our documentation shines, never the same!
Let's celebrate with a joyful cheer,
For a cleaner system, we hold dear! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 19a68e4 and 7d58c16.

Files selected for processing (5)
  • docs/changes.rst (1 hunks)
  • weblate/api/tests.py (2 hunks)
  • weblate/glossary/tasks.py (3 hunks)
  • weblate/glossary/tests.py (2 hunks)
  • weblate/trans/models/translation.py (2 hunks)
Additional comments not posted (9)
weblate/glossary/tasks.py (4)

22-25: LGTM!

The code changes are approved.


50-74: LGTM!

The code changes are approved.

The previous review comment suggesting the use of the remove method has been addressed in this implementation.


7-8: LGTM!

The code changes are approved.


13-13: LGTM!

The code changes are approved.

weblate/glossary/tests.py (1)

480-491: LGTM!

The test_stale_glossaries_cleanup test is well-structured and correctly verifies the functionality of the cleanup_stale_glossaries function. It follows the AAA (Arrange-Act-Assert) pattern:

  1. Arrange: Records the initial count of glossary translations.
  2. Act: Deletes a translation and calls the cleanup_stale_glossaries function.
  3. Assert: Checks if the count of glossary translations has decreased by 1.

The test uses the assertEqual assertion to verify the expected outcome.

docs/changes.rst (1)

10-11: This is a changelog entry describing a new feature. It does not contain any code that needs to be reviewed.

weblate/trans/models/translation.py (2)

1340-1341: Approved: The remove method now cleans up the translation more thoroughly.

The updated remove method ensures the translation is deleted from both the VCS and the database. This keeps them in sync and prevents stale data.

Also, invoking cleanup_stale_glossaries after the deletion is a good practice to remove any glossary entries that are no longer needed.

Also applies to: 1372-1372


1340-1341: Docstring update looks good.

The revised docstring correctly states that the remove method now removes translations from both the VCS and the database.

weblate/api/tests.py (1)

3298-3300: LGTM!

The changes to the test_delete method look good. Introducing the _translation_count function improves the specificity of the test by excluding glossaries from the translation count.

Also applies to: 3302-3302, 3313-3314

weblate/glossary/tasks.py Show resolved Hide resolved
weblate/glossary/tasks.py Outdated Show resolved Hide resolved
@nijel nijel added this to the 5.8 milestone Sep 4, 2024
Copy link
Member

@orangesunny orangesunny left a comment

Choose a reason for hiding this comment

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

docs part OK

@nijel nijel self-assigned this Sep 19, 2024
@nijel nijel enabled auto-merge (squash) September 19, 2024 08:01
@nijel
Copy link
Member

nijel commented Sep 19, 2024

@sourcery-ai review

Copy link

sourcery-ai bot commented Sep 19, 2024

Reviewer's Guide by Sourcery

This pull request implements a new feature to clean up unused glossary languages in Weblate. It introduces a new task to remove stale empty glossaries and integrates this cleanup process into existing workflows. The changes primarily affect the glossary management system, with updates to related tests and API functionality.

File-Level Changes

Change Details Files
Implemented a new task to clean up unused glossaries
  • Added a new function 'cleanup_stale_glossaries' to remove empty stale glossaries
  • Integrated the cleanup task into the 'sync_glossary_languages' function
  • Added a delay call to 'cleanup_stale_glossaries' in the translation removal process
weblate/glossary/tasks.py
weblate/trans/models/translation.py
Updated existing functions to accommodate the new cleanup feature
  • Modified 'sync_glossary_languages' function to include cleanup of stale glossaries
  • Updated the 'remove' method in the Translation model to trigger glossary cleanup
weblate/glossary/tasks.py
weblate/trans/models/translation.py
Added new test cases for the glossary cleanup functionality
  • Created a new test 'test_stale_glossaries_cleanup' to validate the cleanup process
  • Modified existing API tests to account for glossary cleanup side effects
weblate/glossary/tests.py
weblate/api/tests.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @gersona - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

weblate/trans/models/translation.py Outdated Show resolved Hide resolved
docs/changes.rst Outdated Show resolved Hide resolved
weblate/glossary/tasks.py Show resolved Hide resolved
@nijel nijel disabled auto-merge September 19, 2024 10:24
weblate/glossary/tasks.py Outdated Show resolved Hide resolved
weblate/glossary/tasks.py Show resolved Hide resolved
weblate/glossary/tasks.py Outdated Show resolved Hide resolved
weblate/glossary/tasks.py Show resolved Hide resolved
@gersona gersona marked this pull request as draft September 30, 2024 08:10
@gersona gersona changed the title 11168 clean unused glossary languages WIP: 11168 clean unused glossary languages Sep 30, 2024
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.20%. Comparing base (54e6e13) to head (bf4066a).
Report is 51 commits behind head on main.

Files with missing lines Patch % Lines
weblate/glossary/tasks.py 90.47% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12331      +/-   ##
==========================================
+ Coverage   91.14%   91.20%   +0.05%     
==========================================
  Files         596      596              
  Lines       60940    61067     +127     
  Branches     9646     6340    -3306     
==========================================
+ Hits        55545    55696     +151     
+ Misses       3724     3723       -1     
+ Partials     1671     1648      -23     
Files with missing lines Coverage Δ
weblate/api/tests.py 100.00% <100.00%> (ø)
weblate/glossary/tests.py 100.00% <100.00%> (ø)
weblate/trans/models/translation.py 86.10% <100.00%> (+0.15%) ⬆️
weblate/glossary/tasks.py 83.67% <90.47%> (+4.36%) ⬆️

... and 33 files with indirect coverage changes

@gersona gersona force-pushed the 11168_clean_unused_glossary_languages branch from 07efc6a to 59b5b58 Compare September 30, 2024 10:25
@gersona gersona requested a review from nijel September 30, 2024 14:19
@gersona gersona marked this pull request as ready for review September 30, 2024 14:19
@gersona gersona changed the title WIP: 11168 clean unused glossary languages 11168 clean unused glossary languages Sep 30, 2024
weblate/glossary/tasks.py Outdated Show resolved Hide resolved
weblate/glossary/tasks.py Outdated Show resolved Hide resolved
Co-authored-by: Michal Čihař <michal@cihar.com>
@nijel nijel merged commit 1a38bed into WeblateOrg:main Oct 10, 2024
34 of 35 checks passed
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.

Remove empty stale glossaries
3 participants