Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d46bea3f
Commit
d46bea3f
authored
Jan 27, 2022
by
charlie ablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add owners array to webhook data
- update docs - update tests Changelog: added
parent
b30f4de3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
16 deletions
+74
-16
app/models/namespaces/user_namespace.rb
app/models/namespaces/user_namespace.rb
+4
-0
app/models/project.rb
app/models/project.rb
+10
-1
doc/system_hooks/system_hooks.md
doc/system_hooks/system_hooks.md
+31
-11
lib/gitlab/hook_data/project_builder.rb
lib/gitlab/hook_data/project_builder.rb
+18
-3
spec/lib/gitlab/hook_data/project_builder_spec.rb
spec/lib/gitlab/hook_data/project_builder_spec.rb
+2
-1
spec/models/namespaces/user_namespace_spec.rb
spec/models/namespaces/user_namespace_spec.rb
+9
-0
No files found.
app/models/namespaces/user_namespace.rb
View file @
d46bea3f
...
...
@@ -25,5 +25,9 @@ module Namespaces
def
self
.
sti_name
'User'
end
def
owners
Array
.
wrap
(
owner
)
end
end
end
app/models/project.rb
View file @
d46bea3f
...
...
@@ -1520,8 +1520,17 @@ class Project < ApplicationRecord
group
||
namespace
.
try
(
:owner
)
end
def
deprecated_owner
# Kept in order to maintain webhook structures until we remove owner_name and owner_email
# See https://gitlab.com/gitlab-org/gitlab/-/issues/350603
group
||
namespace
.
try
(
:owner
)
end
def
owners
Array
.
wrap
(
owner
)
# This will be phased out and replaced with `owners` relationship
# backed by memberships with direct/inherited Owner access roles
# See https://gitlab.com/groups/gitlab-org/-/epics/7405
team
.
owners
end
def
first_owner
...
...
doc/system_hooks/system_hooks.md
View file @
d46bea3f
...
...
@@ -79,8 +79,12 @@ X-Gitlab-Event: System Hook
"updated_at"
:
"2012-07-21T07:38:22Z"
,
"event_name"
:
"project_create"
,
"name"
:
"StoreCloud"
,
"owner_email"
:
"johnsmith@
gmail
.com"
,
"owner_email"
:
"johnsmith@
example
.com"
,
"owner_name"
:
"John Smith"
,
"owners"
:
[{
"name"
:
"John"
,
"email"
:
"user1@example.com"
}],
"path"
:
"storecloud"
,
"path_with_namespace"
:
"jsmith/storecloud"
,
"project_id"
:
74
,
...
...
@@ -96,8 +100,12 @@ X-Gitlab-Event: System Hook
"updated_at"
:
"2012-07-21T07:38:22Z"
,
"event_name"
:
"project_destroy"
,
"name"
:
"Underscore"
,
"owner_email"
:
"johnsmith@
gmail
.com"
,
"owner_email"
:
"johnsmith@
example
.com"
,
"owner_name"
:
"John Smith"
,
"owners"
:
[{
"name"
:
"John"
,
"email"
:
"user1@example.com"
}],
"path"
:
"underscore"
,
"path_with_namespace"
:
"jsmith/underscore"
,
"project_id"
:
73
,
...
...
@@ -117,7 +125,11 @@ X-Gitlab-Event: System Hook
"path_with_namespace"
:
"jsmith/underscore"
,
"project_id"
:
73
,
"owner_name"
:
"John Smith"
,
"owner_email"
:
"johnsmith@gmail.com"
,
"owner_email"
:
"johnsmith@example.com"
,
"owners"
:
[{
"name"
:
"John"
,
"email"
:
"user1@example.com"
}],
"project_visibility"
:
"internal"
,
"old_path_with_namespace"
:
"jsmith/overscore"
}
...
...
@@ -138,7 +150,11 @@ Please refer to `group_rename` and `user_rename` for that case.
"path_with_namespace"
:
"scores/underscore"
,
"project_id"
:
73
,
"owner_name"
:
"John Smith"
,
"owner_email"
:
"johnsmith@gmail.com"
,
"owner_email"
:
"johnsmith@example.com"
,
"owners"
:
[{
"name"
:
"John"
,
"email"
:
"user1@example.com"
}],
"project_visibility"
:
"internal"
,
"old_path_with_namespace"
:
"jsmith/overscore"
}
...
...
@@ -152,8 +168,12 @@ Please refer to `group_rename` and `user_rename` for that case.
"updated_at"
:
"2012-07-21T07:38:22Z"
,
"event_name"
:
"project_update"
,
"name"
:
"StoreCloud"
,
"owner_email"
:
"johnsmith@
gmail
.com"
,
"owner_email"
:
"johnsmith@
example
.com"
,
"owner_name"
:
"John Smith"
,
"owners"
:
[{
"name"
:
"John"
,
"email"
:
"user1@example.com"
}],
"path"
:
"storecloud"
,
"path_with_namespace"
:
"jsmith/storecloud"
,
"project_id"
:
74
,
...
...
@@ -173,7 +193,7 @@ Please refer to `group_rename` and `user_rename` for that case.
"project_name"
:
"StoreCloud"
,
"project_path"
:
"storecloud"
,
"project_path_with_namespace"
:
"jsmith/storecloud"
,
"user_email"
:
"johnsmith@
gmail
.com"
,
"user_email"
:
"johnsmith@
example
.com"
,
"user_name"
:
"John Smith"
,
"user_username"
:
"johnsmith"
,
"user_id"
:
41
,
...
...
@@ -193,7 +213,7 @@ Please refer to `group_rename` and `user_rename` for that case.
"project_name"
:
"StoreCloud"
,
"project_path"
:
"storecloud"
,
"project_path_with_namespace"
:
"jsmith/storecloud"
,
"user_email"
:
"johnsmith@
gmail
.com"
,
"user_email"
:
"johnsmith@
example
.com"
,
"user_name"
:
"John Smith"
,
"user_username"
:
"johnsmith"
,
"user_id"
:
41
,
...
...
@@ -213,7 +233,7 @@ Please refer to `group_rename` and `user_rename` for that case.
"project_name"
:
"StoreCloud"
,
"project_path"
:
"storecloud"
,
"project_path_with_namespace"
:
"jsmith/storecloud"
,
"user_email"
:
"johnsmith@
gmail
.com"
,
"user_email"
:
"johnsmith@
example
.com"
,
"user_name"
:
"John Smith"
,
"user_username"
:
"johnsmith"
,
"user_id"
:
41
,
...
...
@@ -360,7 +380,7 @@ If the user is blocked via LDAP, `state` is `ldap_blocked`.
"group_id"
:
78
,
"group_name"
:
"StoreCloud"
,
"group_path"
:
"storecloud"
,
"user_email"
:
"johnsmith@
gmail
.com"
,
"user_email"
:
"johnsmith@
example
.com"
,
"user_name"
:
"John Smith"
,
"user_username"
:
"johnsmith"
,
"user_id"
:
41
...
...
@@ -378,7 +398,7 @@ If the user is blocked via LDAP, `state` is `ldap_blocked`.
"group_id"
:
78
,
"group_name"
:
"StoreCloud"
,
"group_path"
:
"storecloud"
,
"user_email"
:
"johnsmith@
gmail
.com"
,
"user_email"
:
"johnsmith@
example
.com"
,
"user_name"
:
"John Smith"
,
"user_username"
:
"johnsmith"
,
"user_id"
:
41
...
...
@@ -396,7 +416,7 @@ If the user is blocked via LDAP, `state` is `ldap_blocked`.
"group_id"
:
78
,
"group_name"
:
"StoreCloud"
,
"group_path"
:
"storecloud"
,
"user_email"
:
"johnsmith@
gmail
.com"
,
"user_email"
:
"johnsmith@
example
.com"
,
"user_name"
:
"John Smith"
,
"user_username"
:
"johnsmith"
,
"user_id"
:
41
...
...
lib/gitlab/hook_data/project_builder.rb
View file @
d46bea3f
...
...
@@ -16,6 +16,7 @@ module Gitlab
# project_id: 1,
# owner_name: "John",
# owner_email: "user1@example.org",
# owners: [name: "John", email: "user1@example.org"],
# project_visibility: "internal",
# old_path_with_namespace: "old-path-with-namespace"
# }
...
...
@@ -32,19 +33,33 @@ module Gitlab
private
def
project_data
owner
=
project
.
owner
owners
=
project
.
owners
.
compact
# When this is removed, also remove the `deprecated_owner` method
# See https://gitlab.com/gitlab-org/gitlab/-/issues/350603
owner
=
project
.
deprecated_owner
{
name:
project
.
name
,
path:
project
.
path
,
path_with_namespace:
project
.
full_path
,
project_id:
project
.
id
,
owner_name:
owner
.
name
,
owner_email:
owner
.
respond_to?
(
:email
)
?
owner
.
email
:
""
,
owner_name:
owner
.
try
(
:name
),
owner_email:
user_email
(
owner
),
owners:
owners
.
map
do
|
owner
|
owner_data
(
owner
)
end
,
project_visibility:
project
.
visibility
.
downcase
}
end
def
owner_data
(
user
)
{
name:
user
.
name
,
email:
user_email
(
user
)
}
end
def
user_email
(
user
)
user
.
respond_to?
(
:email
)
?
user
.
email
:
""
end
def
event_specific_project_data
(
event
)
return
{}
unless
event
==
:rename
||
event
==
:transfer
...
...
spec/lib/gitlab/hook_data/project_builder_spec.rb
View file @
d46bea3f
...
...
@@ -13,7 +13,7 @@ RSpec.describe Gitlab::HookData::ProjectBuilder do
let
(
:attributes
)
do
[
:event_name
,
:created_at
,
:updated_at
,
:name
,
:path
,
:path_with_namespace
,
:project_id
,
:owner_name
,
:owner_email
,
:project_visibility
:owner
s
,
:owner
_name
,
:owner_email
,
:project_visibility
]
end
...
...
@@ -30,6 +30,7 @@ RSpec.describe Gitlab::HookData::ProjectBuilder do
expect
(
data
[
:project_id
]).
to
eq
(
project
.
id
)
expect
(
data
[
:owner_name
]).
to
eq
(
'John'
)
expect
(
data
[
:owner_email
]).
to
eq
(
'john@example.com'
)
expect
(
data
[
:owners
]).
to
contain_exactly
({
name:
'John'
,
email:
'john@example.com'
})
expect
(
data
[
:project_visibility
]).
to
eq
(
'internal'
)
end
end
...
...
spec/models/namespaces/user_namespace_spec.rb
View file @
d46bea3f
...
...
@@ -9,4 +9,13 @@ RSpec.describe Namespaces::UserNamespace, type: :model do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:owner
)
}
end
describe
'#owners'
do
let
(
:owner
)
{
build
(
:user
)
}
let
(
:namespace
)
{
build
(
:namespace
,
owner:
owner
)
}
specify
do
expect
(
namespace
.
owners
).
to
match_array
([
owner
])
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment