From 8e32a6f0f8bd9a221a3318198db9eafcf495335f Mon Sep 17 00:00:00 2001 From: Andrew Fontaine Date: Tue, 5 Sep 2023 13:21:27 -0400 Subject: [PATCH 1/2] Add state header to notification emails This is primarily targeted at issuable entities, and unlocks further email filtering and tagging workflows, by specifying within the email whether or not the issuable is open/closed/merged. It can maybe be looked at for other GitLab entities, but for now, issuable state is enough. Changelog: added --- app/mailers/notify.rb | 1 + doc/user/profile/notifications.md | 29 ++++++++++--------- .../mailers/notify_shared_examples.rb | 8 +++++ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 4180e76e1a074b..77d32a55941a31 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -208,6 +208,7 @@ def add_model_headers(object) headers["#{prefix}-ID"] = object.id headers["#{prefix}-IID"] = object.iid if object.respond_to?(:iid) + headers["#{prefix}-State"] = object.state if object.respond_to?(:state) end def add_project_headers diff --git a/doc/user/profile/notifications.md b/doc/user/profile/notifications.md index ba8c83e31063a9..3a581d94cdeb2a 100644 --- a/doc/user/profile/notifications.md +++ b/doc/user/profile/notifications.md @@ -368,20 +368,21 @@ a merge request or an issue. The following table lists all GitLab-specific email headers: -| Header | Description | -| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -| `List-Id` | The path of the project in an RFC 2919 mailing list identifier. You can use it for email organization with filters. | -| `X-GitLab-(Resource)-ID` | The ID of the resource the notification is for. The resource, for example, can be `Issue`, `MergeRequest`, `Commit`, or another such resource. | -| `X-GitLab-ConfidentialIssue` | The boolean value indicating issue confidentiality for notifications. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/222908) in GitLab 16.0. | -| `X-GitLab-Discussion-ID` | The ID of the thread the comment belongs to, in notification emails for comments. | -| `X-GitLab-Group-Id` | The group's ID. Only present on notification emails for [epics](../group/epics/index.md). | -| `X-GitLab-Group-Path` | The group's path. Only present on notification emails for [epics](../group/epics/index.md) | -| `X-GitLab-NotificationReason` | The reason for the notification. [See possible values.](#x-gitlab-notificationreason). | -| `X-GitLab-Pipeline-Id` | The ID of the pipeline the notification is for, in notification emails for pipelines. | -| `X-GitLab-Project-Id` | The project's ID. | -| `X-GitLab-Project-Path` | The project's path. | -| `X-GitLab-Project` | The name of the project the notification belongs to. | -| `X-GitLab-Reply-Key` | A unique token to support reply by email. | +| Header | Description | +| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `List-Id` | The path of the project in an RFC 2919 mailing list identifier. You can use it for email organization with filters. | +| `X-GitLab-(Resource)-ID` | The ID of the resource the notification is for. The resource, for example, can be `Issue`, `MergeRequest`, `Commit`, or another such resource. | +| `X-GitLab-(Resource)-State` | The state of the resource the notification is for. The resource, for example, can be `Issue` or `MergeRequest`. The value can be `opened`, `closed`, `merged`, or `locked`. | +| `X-GitLab-ConfidentialIssue` | The boolean value indicating issue confidentiality for notifications. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/222908) in GitLab 16.0. | +| `X-GitLab-Discussion-ID` | The ID of the thread the comment belongs to, in notification emails for comments. | +| `X-GitLab-Group-Id` | The group's ID. Only present on notification emails for [epics](../group/epics/index.md). | +| `X-GitLab-Group-Path` | The group's path. Only present on notification emails for [epics](../group/epics/index.md) | +| `X-GitLab-NotificationReason` | The reason for the notification. [See possible values.](#x-gitlab-notificationreason). | +| `X-GitLab-Pipeline-Id` | The ID of the pipeline the notification is for, in notification emails for pipelines. | +| `X-GitLab-Project-Id` | The project's ID. | +| `X-GitLab-Project-Path` | The project's path. | +| `X-GitLab-Project` | The name of the project the notification belongs to. | +| `X-GitLab-Reply-Key` | A unique token to support reply by email. | ### X-GitLab-NotificationReason diff --git a/spec/support/shared_examples/mailers/notify_shared_examples.rb b/spec/support/shared_examples/mailers/notify_shared_examples.rb index cf1ab7697ab954..987060d73b9bcd 100644 --- a/spec/support/shared_examples/mailers/notify_shared_examples.rb +++ b/spec/support/shared_examples/mailers/notify_shared_examples.rb @@ -54,6 +54,14 @@ expect(subject.header["X-GitLab-#{model.class.name}-IID"]).to eq nil end end + + it 'has X-GitLab-*-State header if model has state defined' do + if model.respond_to?(:state) + is_expected.to have_header "X-GitLab-#{model.class.name}-State", model.state.to_s + else + expect(subject.header["X-GitLab-#{model.class.name}-State"]).to eq nil + end + end end RSpec.shared_examples 'an email with X-GitLab headers containing project details' do -- GitLab From dbddfc88dc8eba4f0e44ff57301368ae0a39d134 Mon Sep 17 00:00:00 2001 From: Marcin Sedlak-Jakubowski Date: Wed, 6 Sep 2023 15:51:26 +0000 Subject: [PATCH 2/2] Add version note --- doc/user/profile/notifications.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user/profile/notifications.md b/doc/user/profile/notifications.md index 3a581d94cdeb2a..706065d46934e8 100644 --- a/doc/user/profile/notifications.md +++ b/doc/user/profile/notifications.md @@ -372,7 +372,7 @@ The following table lists all GitLab-specific email headers: | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `List-Id` | The path of the project in an RFC 2919 mailing list identifier. You can use it for email organization with filters. | | `X-GitLab-(Resource)-ID` | The ID of the resource the notification is for. The resource, for example, can be `Issue`, `MergeRequest`, `Commit`, or another such resource. | -| `X-GitLab-(Resource)-State` | The state of the resource the notification is for. The resource, for example, can be `Issue` or `MergeRequest`. The value can be `opened`, `closed`, `merged`, or `locked`. | +| `X-GitLab-(Resource)-State` | The state of the resource the notification is for. The resource can be, for example, `Issue` or `MergeRequest`. The value can be `opened`, `closed`, `merged`, or `locked`. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/130967) in GitLab 16.4. | | `X-GitLab-ConfidentialIssue` | The boolean value indicating issue confidentiality for notifications. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/222908) in GitLab 16.0. | | `X-GitLab-Discussion-ID` | The ID of the thread the comment belongs to, in notification emails for comments. | | `X-GitLab-Group-Id` | The group's ID. Only present on notification emails for [epics](../group/epics/index.md). | -- GitLab