Commit 34261146 authored by Markus Koller's avatar Markus Koller

Merge branch 'add-user-id-to-user-webhook-data' into 'master'

Include the user id in the webhook payload

See merge request gitlab-org/gitlab!50287
parents df069ab5 038cd1ab
...@@ -1358,6 +1358,7 @@ class User < ApplicationRecord ...@@ -1358,6 +1358,7 @@ class User < ApplicationRecord
def hook_attrs def hook_attrs
{ {
id: id,
name: name, name: name,
username: username, username: username,
avatar_url: avatar_url(only_path: false), avatar_url: avatar_url(only_path: false),
......
---
title: Include the user id in the webhook payload
merge_request: 50287
author:
type: added
...@@ -535,9 +535,11 @@ X-Gitlab-Event: System Hook ...@@ -535,9 +535,11 @@ X-Gitlab-Event: System Hook
{ {
"object_kind": "merge_request", "object_kind": "merge_request",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"email": "admin@example.com"
}, },
"project": { "project": {
"name": "Example", "name": "Example",
......
...@@ -257,6 +257,7 @@ X-Gitlab-Event: Issue Hook ...@@ -257,6 +257,7 @@ X-Gitlab-Event: Issue Hook
"object_kind": "issue", "object_kind": "issue",
"event_type": "issue", "event_type": "issue",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon", "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
...@@ -420,9 +421,11 @@ X-Gitlab-Event: Note Hook ...@@ -420,9 +421,11 @@ X-Gitlab-Event: Note Hook
{ {
"object_kind": "note", "object_kind": "note",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
"email": "admin@example.com"
}, },
"project_id": 5, "project_id": 5,
"project":{ "project":{
...@@ -500,9 +503,11 @@ X-Gitlab-Event: Note Hook ...@@ -500,9 +503,11 @@ X-Gitlab-Event: Note Hook
{ {
"object_kind": "note", "object_kind": "note",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
"email": "admin@example.com"
}, },
"project_id": 5, "project_id": 5,
"project":{ "project":{
...@@ -627,9 +632,11 @@ X-Gitlab-Event: Note Hook ...@@ -627,9 +632,11 @@ X-Gitlab-Event: Note Hook
{ {
"object_kind": "note", "object_kind": "note",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
"email": "admin@example.com"
}, },
"project_id": 5, "project_id": 5,
"project":{ "project":{
...@@ -733,9 +740,11 @@ X-Gitlab-Event: Note Hook ...@@ -733,9 +740,11 @@ X-Gitlab-Event: Note Hook
{ {
"object_kind": "note", "object_kind": "note",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
"email": "admin@example.com"
}, },
"project_id": 5, "project_id": 5,
"project":{ "project":{
...@@ -809,9 +818,11 @@ X-Gitlab-Event: Merge Request Hook ...@@ -809,9 +818,11 @@ X-Gitlab-Event: Merge Request Hook
{ {
"object_kind": "merge_request", "object_kind": "merge_request",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
"email": "admin@example.com"
}, },
"project": { "project": {
"id": 1, "id": 1,
...@@ -970,9 +981,11 @@ X-Gitlab-Event: Wiki Page Hook ...@@ -970,9 +981,11 @@ X-Gitlab-Event: Wiki Page Hook
{ {
"object_kind": "wiki_page", "object_kind": "wiki_page",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon",
"email": "admin@example.com"
}, },
"project": { "project": {
"id": 1, "id": 1,
...@@ -1061,6 +1074,7 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1061,6 +1074,7 @@ X-Gitlab-Event: Pipeline Hook
"url": "http://192.168.64.1:3005/gitlab-org/gitlab-test/merge_requests/1" "url": "http://192.168.64.1:3005/gitlab-org/gitlab-test/merge_requests/1"
}, },
"user":{ "user":{
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon", "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon",
...@@ -1102,9 +1116,11 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1102,9 +1116,11 @@ X-Gitlab-Event: Pipeline Hook
"manual": true, "manual": true,
"allow_failure": false, "allow_failure": false,
"user":{ "user":{
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon",
"email": "admin@example.com"
}, },
"runner": null, "runner": null,
"artifacts_file":{ "artifacts_file":{
...@@ -1124,9 +1140,11 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1124,9 +1140,11 @@ X-Gitlab-Event: Pipeline Hook
"manual": false, "manual": false,
"allow_failure": false, "allow_failure": false,
"user":{ "user":{
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon",
"email": "admin@example.com"
}, },
"runner": { "runner": {
"id":380987, "id":380987,
...@@ -1151,9 +1169,11 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1151,9 +1169,11 @@ X-Gitlab-Event: Pipeline Hook
"manual": false, "manual": false,
"allow_failure": false, "allow_failure": false,
"user":{ "user":{
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon",
"email": "admin@example.com"
}, },
"runner": { "runner": {
"id":380987, "id":380987,
...@@ -1178,9 +1198,11 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1178,9 +1198,11 @@ X-Gitlab-Event: Pipeline Hook
"manual": false, "manual": false,
"allow_failure": false, "allow_failure": false,
"user":{ "user":{
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon",
"email": "admin@example.com"
}, },
"runner": { "runner": {
"id":380987, "id":380987,
...@@ -1205,9 +1227,11 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1205,9 +1227,11 @@ X-Gitlab-Event: Pipeline Hook
"manual": false, "manual": false,
"allow_failure": false, "allow_failure": false,
"user":{ "user":{
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon",
"email": "admin@example.com"
}, },
"runner": null, "runner": null,
"artifacts_file":{ "artifacts_file":{
...@@ -1254,7 +1278,8 @@ X-Gitlab-Event: Job Hook ...@@ -1254,7 +1278,8 @@ X-Gitlab-Event: Job Hook
"id": 3, "id": 3,
"name": "User", "name": "User",
"email": "user@gitlab.com", "email": "user@gitlab.com",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon" "avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon",
"email": "admin@example.com"
}, },
"commit": { "commit": {
"id": 2366, "id": 2366,
...@@ -1330,6 +1355,7 @@ X-Gitlab-Event: Deployment Hook ...@@ -1330,6 +1355,7 @@ X-Gitlab-Event: Deployment Hook
}, },
"short_sha": "279484c0", "short_sha": "279484c0",
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
...@@ -1472,6 +1498,7 @@ X-Gitlab-Event: Feature Flag Hook ...@@ -1472,6 +1498,7 @@ X-Gitlab-Event: Feature Flag Hook
"http_url":"http://example.com/gitlabhq/gitlab-test.git" "http_url":"http://example.com/gitlabhq/gitlab-test.git"
}, },
"user": { "user": {
"id": 1,
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
......
...@@ -26,6 +26,7 @@ RSpec.describe Gitlab::DataBuilder::Build do ...@@ -26,6 +26,7 @@ RSpec.describe Gitlab::DataBuilder::Build do
it { it {
expect(data[:user]).to eq( expect(data[:user]).to eq(
{ {
id: user.id,
name: user.name, name: user.name,
username: user.username, username: user.username,
avatar_url: user.avatar_url(only_path: false), avatar_url: user.avatar_url(only_path: false),
......
...@@ -41,6 +41,7 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do ...@@ -41,6 +41,7 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do
expect(project_data).to eq(project.hook_attrs(backward: false)) expect(project_data).to eq(project.hook_attrs(backward: false))
expect(data[:merge_request]).to be_nil expect(data[:merge_request]).to be_nil
expect(data[:user]).to eq({ expect(data[:user]).to eq({
id: user.id,
name: user.name, name: user.name,
username: user.username, username: user.username,
avatar_url: user.avatar_url(only_path: false), avatar_url: user.avatar_url(only_path: false),
......
...@@ -5089,9 +5089,10 @@ RSpec.describe User do ...@@ -5089,9 +5089,10 @@ RSpec.describe User do
end end
describe '#hook_attrs' do describe '#hook_attrs' do
it 'includes name, username, avatar_url, and email' do it 'includes id, name, username, avatar_url, and email' do
user = create(:user) user = create(:user)
user_attributes = { user_attributes = {
id: user.id,
name: user.name, name: user.name,
username: user.username, username: user.username,
avatar_url: user.avatar_url(only_path: false), avatar_url: user.avatar_url(only_path: false),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment