Skip to content

feat(GitLab): Post comments when linking an issue or merge request to a Flagsmith feature#7306

Merged
khvn26 merged 18 commits intomainfrom
feat/gitlab-links-post-comments
Apr 23, 2026
Merged

feat(GitLab): Post comments when linking an issue or merge request to a Flagsmith feature#7306
khvn26 merged 18 commits intomainfrom
feat/gitlab-links-post-comments

Conversation

@emyller
Copy link
Copy Markdown
Contributor

@emyller emyller commented Apr 22, 2026

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7162

Post comments to GitLab issues and merge requests when:

  • A feature is linked to an issue or MR (initial state snapshot table across environments)
  • A linked feature's state changes for any environment, segment, or identity
  • A feature is unlinked from an issue or MR
  • A linked feature is deleted

State-change comments render as a snapshot of the post-change state (e.g. in **Development**: :white_check_mark: Enabled, value `X` ) rather than describing the transition, which avoids misrepresenting value-only changes as enable/disable events.

How did you test this code?

Unit tests covering the new service, task handlers, and hook call sites (patch coverage 100%).

Manual smoke against gitlab.com, posting to flagsmith/webhooks-tetsing-1:

  • Issue #2 — link → enable → value change → unlink → re-link → delete
  • MR !3 — link → segment-override state change → identity-override state change

Screenshots

image image

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 23, 2026 2:31pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ignored Ignored Preview Apr 23, 2026 2:31pm
flagsmith-frontend-staging Ignored Ignored Preview Apr 23, 2026 2:31pm

Request Review

@github-actions github-actions Bot added the api Issue related to the REST API label Apr 22, 2026
@emyller emyller changed the title Feat/gitlab links post comments feat(GitLab): Post comments when linking an issue or merge request to a Flagsmith feature Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.42%. Comparing base (885f807) to head (1aa8b6d).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7306      +/-   ##
==========================================
+ Coverage   98.39%   98.42%   +0.02%     
==========================================
  Files        1377     1391      +14     
  Lines       51744    52219     +475     
==========================================
+ Hits        50913    51396     +483     
+ Misses        831      823       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed docs Documentation updates labels Apr 22, 2026
@emyller emyller force-pushed the feat/gitlab-links-post-comments branch from ecdc5cb to db215f3 Compare April 22, 2026 05:27
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Apr 22, 2026
@emyller emyller force-pushed the feat/gitlab-links-post-comments branch from db215f3 to fc9f9eb Compare April 22, 2026 05:35
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Apr 22, 2026
emyller and others added 2 commits April 22, 2026 02:47
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@emyller emyller force-pushed the feat/gitlab-links-post-comments branch from fc9f9eb to e91ee41 Compare April 22, 2026 05:48
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Apr 22, 2026
The previous wording ("was **enabled**/was **disabled** with value X")
implied the enable/disable transition was the change, so a value-only
change read as an enable event that happened to already be enabled.

Switch to a post-change state snapshot matching the link comment's
style, e.g. "in **Development**: ✅ Enabled, value `X`".

beep boop
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Apr 22, 2026
The resource.unlinked log now fires before super().perform_destroy(), so
it lands between comment.posted and webhook.deregistered. Update the
assertion to match.

beep boop
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Apr 22, 2026
Copy link
Copy Markdown
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

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

Couple of comments, besides the question around view versus model-hook. There is this comment I'd like to explore alternatives

Comment thread api/features/versioning/serializers.py Outdated
Comment thread api/features/serializers.py
Comment thread api/integrations/gitlab/client/api.py
Comment thread api/tests/unit/integrations/gitlab/test_comments.py Outdated
Comment thread api/features/feature_external_resources/views.py Outdated
Comment thread api/integrations/gitlab/services/comments.py
Comment thread api/integrations/gitlab/tasks.py
khvn26 added 7 commits April 23, 2026 12:17
Reviewer asked whether this was lazy due to a circular import. It
isn't — move to module top. Update the patch target in the versioning
test to patch where the name is consumed rather than where it
originated.

Addresses #7306 (comment)

beep boop
Introduce post_gitlab_state_change_comment_for_feature_state in the
GitLab services layer. It short-circuits when there's no environment
or the project has no GitLabConfiguration, so the majority of projects
without GitLab no longer pay for a queue entry and a configuration
lookup per feature-state save.

Swap both state-change dispatch sites (FeatureStateSerializerBasic,
CustomEnvironmentFeatureVersionFeatureStateSerializer) to call the
helper. Move the gating tests down to the helper level and simplify
the serializer-level tests to assert dispatch delegation.

Addresses #7306 (comment)

beep boop
Pass a client timeout to the new create_issue_note and
create_merge_request_note calls so a slow or unresponsive GitLab
instance can't hang the web worker or task processor.

Rename GITLAB_WEBHOOK_TIMEOUT to GITLAB_CLIENT_TIMEOUT_SECONDS to
match the broader timeout sweep in #7307 and reduce future rebase
friction — the constant is no longer webhook-specific now that every
client call uses it.

Addresses #7306 (comment)

beep boop
The `else: return` arm in `_post_note_to_resource` was only reachable
by calling the private helper with an unknown `resource_type`. In
practice every caller passes a constrained `FeatureExternalResource.type`,
so the branch is dead code. Remove it and re-cover the unparseable-URL
path through `post_linked_comment` rather than the private helper.

Addresses #7306 (comment)

beep boop
…s/vcs

Introduce integrations/vcs/services.py with
dispatch_vcs_on_resource_create and dispatch_vcs_on_resource_destroy.
Both fan out to the per-provider side effects (today only GitLab;
GitHub and any future VCS will land alongside — #7315).

FeatureExternalResourceViewSet.perform_create and .perform_destroy
now just call the dispatchers, shedding the GitLab-specific branch,
log emission, and task dispatch. The view is leaner and adding a new
VCS becomes a one-module change rather than edits across view, model,
and serializer hooks.

Register integrations.vcs as a Django app so the docgen events
crawler picks up resource.linked and resource.unlinked at their new
location; regenerate the catalogue. Existing integration tests cover
the dispatcher at 100%.

Addresses #7306 (comment)

beep boop
Merge the two None-checks for project_path and iid into a single
combined guard, matching the pattern used in services/labels.py.
Both checks now share one branch, so there's no longer an
unreachable arm masked by `# pragma: no cover`.

Addresses #7306 (comment)

beep boop
post_state_change_comment reads feature_state.feature.project to look
up the GitLabConfiguration; without feature__project in select_related
this costs one extra query per comment dispatch.

Addresses #7306 (comment)

beep boop
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Apr 23, 2026
@khvn26 khvn26 requested a review from Zaimwa9 April 23, 2026 13:30
Move apply_initial_tag and the webhook-deregister dispatch out of the
AFTER_SAVE / AFTER_DELETE hooks on FeatureExternalResource and into
dispatch_vcs_on_resource_create / dispatch_vcs_on_resource_destroy.
The model's GitLab hooks (apply_gitlab_tag, deregister_gitlab_webhook)
are gone; all GitLab side-effects for linking and unlinking now live
in one place.

Add deregister_gitlab_webhook_for_resource alongside the existing
register_gitlab_webhook_for_resource helper so the dispatcher stays
provider-agnostic and just calls named GitLab services.

Call the destroy dispatcher after super().perform_destroy() so
has_live_resource_for_path in the deregister task naturally excludes
the just-removed row without a signature change.
@github-actions github-actions Bot added docs Documentation updates and removed feature New feature or request docs Documentation updates labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitLab integration: post comments on linked issues and MRs

3 participants