Commit aa94066b authored by guillaume micouin's avatar guillaume micouin Committed by Mayra Cabrera

add avatar_url in job webhook, and email in pipeline webhook

parent 30b55047
...@@ -1226,7 +1226,8 @@ class User < ApplicationRecord ...@@ -1226,7 +1226,8 @@ class User < ApplicationRecord
{ {
name: name, name: name,
username: username, username: username,
avatar_url: avatar_url(only_path: false) avatar_url: avatar_url(only_path: false),
email: email
} }
end end
......
---
title: add avatar_url in job webhook, and email in pipeline webhook
merge_request: 24992
author: Guillaume Micouin
type: added
...@@ -1054,7 +1054,8 @@ X-Gitlab-Event: Pipeline Hook ...@@ -1054,7 +1054,8 @@ X-Gitlab-Event: Pipeline Hook
"user":{ "user":{
"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": "user_email@gitlab.com"
}, },
"project":{ "project":{
"id": 1, "id": 1,
...@@ -1243,7 +1244,8 @@ X-Gitlab-Event: Job Hook ...@@ -1243,7 +1244,8 @@ X-Gitlab-Event: Job Hook
"user": { "user": {
"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"
}, },
"commit": { "commit": {
"id": 2366, "id": 2366,
......
...@@ -38,11 +38,7 @@ module Gitlab ...@@ -38,11 +38,7 @@ module Gitlab
project_id: project.id, project_id: project.id,
project_name: project.full_name, project_name: project.full_name,
user: { user: user.try(:hook_attrs),
id: user.try(:id),
name: user.try(:name),
email: user.try(:email)
},
commit: { commit: {
# note: commit.id is actually the pipeline id # note: commit.id is actually the pipeline id
......
...@@ -4,7 +4,8 @@ require 'spec_helper' ...@@ -4,7 +4,8 @@ require 'spec_helper'
describe Gitlab::DataBuilder::Build do describe Gitlab::DataBuilder::Build do
let(:runner) { create(:ci_runner, :instance) } let(:runner) { create(:ci_runner, :instance) }
let(:build) { create(:ci_build, :running, runner: runner) } let(:user) { create(:user) }
let(:build) { create(:ci_build, :running, runner: runner, user: user) }
describe '.build' do describe '.build' do
let(:data) do let(:data) do
...@@ -22,6 +23,15 @@ describe Gitlab::DataBuilder::Build do ...@@ -22,6 +23,15 @@ describe Gitlab::DataBuilder::Build do
it { expect(data[:project_id]).to eq(build.project.id) } it { expect(data[:project_id]).to eq(build.project.id) }
it { expect(data[:project_name]).to eq(build.project.full_name) } it { expect(data[:project_name]).to eq(build.project.full_name) }
it { expect(data[:pipeline_id]).to eq(build.pipeline.id) } it { expect(data[:pipeline_id]).to eq(build.pipeline.id) }
it {
expect(data[:user]).to eq(
{
name: user.name,
username: user.username,
avatar_url: user.avatar_url(only_path: false),
email: user.email
})
}
it { expect(data[:commit][:id]).to eq(build.pipeline.id) } it { expect(data[:commit][:id]).to eq(build.pipeline.id) }
it { expect(data[:runner][:id]).to eq(build.runner.id) } it { expect(data[:runner][:id]).to eq(build.runner.id) }
it { expect(data[:runner][:description]).to eq(build.runner.description) } it { expect(data[:runner][:description]).to eq(build.runner.description) }
......
...@@ -11,7 +11,8 @@ describe Gitlab::DataBuilder::Pipeline do ...@@ -11,7 +11,8 @@ describe Gitlab::DataBuilder::Pipeline do
project: project, project: project,
status: 'success', status: 'success',
sha: project.commit.sha, sha: project.commit.sha,
ref: project.default_branch) ref: project.default_branch,
user: user)
end end
let!(:build) { create(:ci_build, pipeline: pipeline) } let!(:build) { create(:ci_build, pipeline: pipeline) }
...@@ -37,6 +38,12 @@ describe Gitlab::DataBuilder::Pipeline do ...@@ -37,6 +38,12 @@ describe Gitlab::DataBuilder::Pipeline do
expect(build_data[:allow_failure]).to eq(build.allow_failure) expect(build_data[:allow_failure]).to eq(build.allow_failure)
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({
name: user.name,
username: user.username,
avatar_url: user.avatar_url(only_path: false),
email: user.email
})
end end
context 'pipeline without variables' do context 'pipeline without variables' do
......
...@@ -4200,4 +4200,17 @@ describe User, :do_not_mock_admin_mode do ...@@ -4200,4 +4200,17 @@ describe User, :do_not_mock_admin_mode do
expect(described_class.bots).to match_array([bot]) expect(described_class.bots).to match_array([bot])
end end
end end
describe '#hook_attrs' do
it 'includes name, username, avatar_url, and email' do
user = create(:user)
user_attributes = {
name: user.name,
username: user.username,
avatar_url: user.avatar_url(only_path: false),
email: user.email
}
expect(user.hook_attrs).to eq(user_attributes)
end
end
end end
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