-
Notifications
You must be signed in to change notification settings - Fork 113
feat(vcs): support for new VCS integration (backend) #2284
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2026 CERN. | ||
| # | ||
| # Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
| # it under the terms of the MIT License; see LICENSE file for more details. | ||
|
|
||
| """ | ||
| Notification builders for VCS. | ||
|
|
||
| These are kept in a separate file as invenio-vcs is an optional dependency, so imports would fail if the package isn't available. | ||
| """ | ||
|
|
||
| from invenio_notifications.models import Notification | ||
| from invenio_notifications.registry import EntityResolverRegistry | ||
| from invenio_notifications.services.builders import NotificationBuilder | ||
| from invenio_notifications.services.generators import EntityResolve, UserEmailBackend | ||
| from invenio_users_resources.notifications.filters import UserPreferencesRecipientFilter | ||
| from invenio_vcs.generic_models import GenericRelease, GenericRepository | ||
| from invenio_vcs.notifications.generators import RepositoryUsersRecipient | ||
|
|
||
|
|
||
| class RepositoryReleaseNotificationBuilder(NotificationBuilder): | ||
| """Notification builder for repository release events.""" | ||
|
|
||
| type = "repository-release" | ||
|
|
||
| @classmethod | ||
| def build( | ||
| cls, | ||
| provider: str, | ||
| generic_repository: GenericRepository, | ||
| generic_release: GenericRelease, | ||
| ): | ||
| """Build the notification.""" | ||
| return Notification( | ||
| type=cls.type, | ||
| context={ | ||
| "provider": provider, | ||
| "repository_provider_id": generic_repository.id, | ||
| "repository_full_name": generic_repository.full_name, | ||
| "release_tag": generic_release.tag_name, | ||
| }, | ||
| ) | ||
|
|
||
| context = [] | ||
|
|
||
| recipients = [RepositoryUsersRecipient("provider", "repository_provider_id")] | ||
|
|
||
| recipient_filters = [UserPreferencesRecipientFilter()] | ||
|
|
||
| recipient_backends = [UserEmailBackend()] | ||
|
|
||
|
|
||
| class RepositoryReleaseSuccessNotificationBuilder(RepositoryReleaseNotificationBuilder): | ||
| """Notification builder for successful repository release events.""" | ||
|
|
||
| type = f"{RepositoryReleaseNotificationBuilder.type}.success" | ||
|
|
||
| @classmethod | ||
| def build( | ||
| cls, | ||
| provider: str, | ||
| generic_repository: GenericRepository, | ||
| generic_release: GenericRelease, | ||
| record, | ||
| ): | ||
| """Build the notification.""" | ||
| notification = super().build(provider, generic_repository, generic_release) | ||
| notification.context["record"] = EntityResolverRegistry.reference_entity(record) | ||
| return notification | ||
|
|
||
| context = [EntityResolve(key="record")] | ||
|
|
||
|
|
||
| class RepositoryReleaseFailureNotificationBuilder(RepositoryReleaseNotificationBuilder): | ||
| """ | ||
| Notification builder for failed repository release events. | ||
|
|
||
| The failure might occur before or after a draft has been successfully saved, so `draft` is allowed | ||
| to be `None`. The notification message should include a link to edit the draft if it's available. | ||
| """ | ||
|
|
||
| type = f"{RepositoryReleaseNotificationBuilder.type}.failure" | ||
|
|
||
| @classmethod | ||
| def build( | ||
| cls, | ||
| provider: str, | ||
| generic_repository: GenericRepository, | ||
| generic_release: GenericRelease, | ||
| error_message: str, | ||
| draft=None, | ||
| ): | ||
| """Build the notification.""" | ||
| notification = super().build(provider, generic_repository, generic_release) | ||
| notification.context["error_message"] = error_message | ||
| if draft is not None: | ||
| notification.context["draft"] = EntityResolverRegistry.reference_entity( | ||
| draft | ||
| ) | ||
| else: | ||
| notification.context["draft"] = None | ||
| return notification | ||
|
|
||
| context = [EntityResolve(key="draft")] | ||
|
|
||
|
|
||
| class RepositoryReleaseCommunityRequiredNotificationBuilder( | ||
| RepositoryReleaseNotificationBuilder | ||
| ): | ||
| """ | ||
| Release is saved as a draft but the user needs to add a community. | ||
|
|
||
| Notification builder for when a release is saved as a draft but | ||
| fails to be published because the user needs to manually select | ||
| a community for the draft. | ||
| """ | ||
|
|
||
| type = f"{RepositoryReleaseNotificationBuilder.type}.community-required" | ||
|
|
||
| @classmethod | ||
| def build( | ||
| cls, | ||
| provider: str, | ||
| generic_repository: GenericRepository, | ||
| generic_release: GenericRelease, | ||
| draft, | ||
| ): | ||
| """Build the notification.""" | ||
| notification = super().build(provider, generic_repository, generic_release) | ||
| notification.context["draft"] = EntityResolverRegistry.reference_entity(draft) | ||
| return notification | ||
|
|
||
| context = [EntityResolve(key="draft")] | ||
|
|
||
|
|
||
| class RepositoryReleaseCommunitySubmittedNotificationBuilder( | ||
| RepositoryReleaseNotificationBuilder | ||
| ): | ||
| """Notification builder for when a release is submitted for review by a community.""" | ||
|
|
||
| type = f"{RepositoryReleaseNotificationBuilder.type}.community-submitted" | ||
|
|
||
| @classmethod | ||
| def build( | ||
| cls, | ||
| provider: str, | ||
| generic_repository: GenericRepository, | ||
| generic_release: GenericRelease, | ||
| request, | ||
| community, | ||
| ): | ||
| """Build the notification.""" | ||
| notification = super().build(provider, generic_repository, generic_release) | ||
| notification.context["request"] = EntityResolverRegistry.reference_entity( | ||
| request | ||
| ) | ||
| notification.context["community"] = EntityResolverRegistry.reference_entity( | ||
| community | ||
| ) | ||
| return notification | ||
|
|
||
| context = [EntityResolve(key="request"), EntityResolve(key="community")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2026 CERN. | ||
| # | ||
| # Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
| # it under the terms of the MIT License; see LICENSE file for more details. | ||
| """RDM service component for updating VCS release models when drafts are published.""" | ||
|
|
||
| from invenio_drafts_resources.services.records.components import ServiceComponent | ||
| from invenio_vcs.models import Release, ReleaseStatus | ||
|
|
||
|
|
||
| class VCSComponent(ServiceComponent): | ||
| """Service component for VCS.""" | ||
|
|
||
| def publish(self, identity, draft=None, record=None): | ||
| """Publish.""" | ||
| if record is None: | ||
| return | ||
|
|
||
| record_model_id = record.model.id | ||
| # See if there's a release that originally failed to publish but was saved in a draft state | ||
| db_release = Release.get_for_record(record_model_id, only_draft=True) | ||
| # If this record didn't come from a VCS release or the release originally succeeded, we won't find anything. | ||
| if db_release is None: | ||
| return | ||
| if ( | ||
| db_release.status != ReleaseStatus.FAILED | ||
| and db_release.status != ReleaseStatus.PUBLISH_PENDING | ||
| ): | ||
| return | ||
|
|
||
| # We are now publishing it, so we can correct the release's status | ||
| db_release.status = ReleaseStatus.PUBLISHED | ||
| db_release.record_is_draft = False | ||
| # We can delete the error that originally happened during publish | ||
| db_release.errors = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2023 CERN. | ||
| # Copyright (C) 2023-2026 CERN. | ||
| # | ||
| # Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
| # it under the terms of the MIT License; see LICENSE file for more details. | ||
| """RDM records implementation of Github.""" | ||
| """RDM records implementation of the legacy Invenio-GitHub module. | ||
|
|
||
| This module is now deprecated. For now, to allow for an optional migration, the RDM bindings for | ||
| Invenio-GitHub have been retained. Please migrate to Invenio-VCS. | ||
| """ | ||
|
|
||
| # TODO: add link to migration docs. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2023-2025 CERN. | ||
| # | ||
| # Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
| # it under the terms of the MIT License; see LICENSE file for more details. | ||
| """RDM records implementation of Invenio-VCS.""" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shelve: document this to an issue so we dont forget :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2297