-
Notifications
You must be signed in to change notification settings - Fork 515
feat(GitLab): Label linked issues and merge requests #7307
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
Show all changes
22 commits
Select commit
Hold shift + click to select a range
86782a5
feat: add tagging enabled configuration field
Zaimwa9 da7d355
feat: label linked issues and mrs
Zaimwa9 e0abda3
feat: added tagging toggle flag
Zaimwa9 e2b8e47
fix: emit gitlab link only on success labelling
Zaimwa9 8a89598
feat: remove gitlab label when unlinking last feature
Zaimwa9 86d1ba5
feat: unlinking wording
Zaimwa9 e91fa02
feat: reviewed tests
Zaimwa9 1d73265
feat: refactoring and merging client helpers
Zaimwa9 1d5dab9
feat: rename tagging_enabled to labeling_enabled on GitLabConfiguration
Zaimwa9 1172f98
feat: extract label logic into its own service
Zaimwa9 6e8060e
feat: restore original comments in test_services.py and test_mappers.py
Zaimwa9 e70e7c6
feat: removed useless div
Zaimwa9 d21c3ae
feat: coverage and replaced wording flag with feature
Zaimwa9 0724f4c
feat: rebased and included label in vcs dispatcher
Zaimwa9 0e57588
feat: test-coverage
Zaimwa9 40ab8b1
feat: rebased
Zaimwa9 8e59908
feat: fix tests
Zaimwa9 43a03a6
feat: coverage and catalogue
Zaimwa9 55623b5
feat: reviewed docstrings
Zaimwa9 d01117a
feat: regenerated catalogue
Zaimwa9 383ca89
feat: move apply label into a task
Zaimwa9 ec25de4
feat: removed comment
Zaimwa9 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
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
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
16 changes: 16 additions & 0 deletions
16
api/integrations/gitlab/migrations/0003_gitlabconfiguration_labeling_enabled.py
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,16 @@ | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("gitlab", "0002_add_gitlab_webhook_model"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="gitlabconfiguration", | ||
| name="labeling_enabled", | ||
| field=models.BooleanField(default=False), | ||
| ), | ||
| ] |
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
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
|
khvn26 marked this conversation as resolved.
|
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
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,76 @@ | ||
| from typing import Literal | ||
|
|
||
| import requests | ||
| import structlog | ||
|
|
||
| from features.feature_external_resources.models import ( | ||
| FeatureExternalResource, | ||
| ResourceType, | ||
| ) | ||
| from integrations.gitlab.client import ( | ||
| add_flagsmith_label_to_gitlab_resource, | ||
| create_flagsmith_label, | ||
| ) | ||
| from integrations.gitlab.models import GitLabConfiguration | ||
| from integrations.gitlab.services.url_parsing import ( | ||
| parse_project_path, | ||
| parse_resource_iid, | ||
| ) | ||
|
|
||
| logger = structlog.get_logger("gitlab") | ||
|
|
||
| GitLabResourceKind = Literal["issues", "merge_requests"] | ||
|
|
||
| GITLAB_RESOURCE_KIND_BY_TYPE: dict[str, GitLabResourceKind] = { | ||
| ResourceType.GITLAB_ISSUE.value: "issues", | ||
| ResourceType.GITLAB_MR.value: "merge_requests", | ||
| } | ||
|
|
||
|
|
||
| def apply_flagsmith_label_to_resource( | ||
| resource: FeatureExternalResource, | ||
| ) -> None: | ||
| """Ensure the "Flagsmith Feature" label exists on the resource's GitLab | ||
| project and apply it to the resource. No-op if labelling is disabled, | ||
| unconfigured, or the URL is unparseable. Never raises — failures are | ||
| logged via ``label.failed``. | ||
| """ | ||
| project = resource.feature.project | ||
| config: GitLabConfiguration | None = GitLabConfiguration.objects.filter( | ||
| project=project | ||
| ).first() | ||
| if not config or not config.labeling_enabled: | ||
| return | ||
|
|
||
| path_with_namespace = parse_project_path(resource.url) | ||
| resource_iid = parse_resource_iid(resource.url) | ||
| if path_with_namespace is None or resource_iid is None: | ||
| return | ||
|
|
||
| log = logger.bind( | ||
| organisation__id=project.organisation_id, | ||
| project__id=project.id, | ||
| feature__id=resource.feature_id, | ||
| gitlab_project__path=path_with_namespace, | ||
| resource__type=resource.type, | ||
| resource__iid=resource_iid, | ||
| ) | ||
|
|
||
| try: | ||
| created = create_flagsmith_label( | ||
| config.gitlab_instance_url, | ||
| config.access_token, | ||
| project_path=path_with_namespace, | ||
| ) | ||
| if created: | ||
| log.info("label.created") | ||
|
|
||
| add_flagsmith_label_to_gitlab_resource( | ||
| config.gitlab_instance_url, | ||
| config.access_token, | ||
| project_path=path_with_namespace, | ||
| resource_kind=GITLAB_RESOURCE_KIND_BY_TYPE[resource.type], | ||
| resource_iid=resource_iid, | ||
| ) | ||
| except requests.RequestException: | ||
| log.exception("label.failed") |
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
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.
Uh oh!
There was an error while loading. Please reload this page.