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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
91ce0467
Commit
91ce0467
authored
Mar 05, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make triggers to be user aware
parent
0a75de29
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
7 deletions
+31
-7
app/models/user.rb
app/models/user.rb
+1
-0
app/services/ci/create_trigger_request_service.rb
app/services/ci/create_trigger_request_service.rb
+1
-1
db/migrate/20170215164610_add_owner_id_to_triggers.rb
db/migrate/20170215164610_add_owner_id_to_triggers.rb
+1
-1
spec/models/ci/trigger_spec.rb
spec/models/ci/trigger_spec.rb
+11
-3
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-0
spec/services/ci/create_trigger_request_service_spec.rb
spec/services/ci/create_trigger_request_service_spec.rb
+16
-2
No files found.
app/models/user.rb
View file @
91ce0467
...
@@ -95,6 +95,7 @@ class User < ActiveRecord::Base
...
@@ -95,6 +95,7 @@ class User < ActiveRecord::Base
has_many
:todos
,
dependent: :destroy
has_many
:todos
,
dependent: :destroy
has_many
:notification_settings
,
dependent: :destroy
has_many
:notification_settings
,
dependent: :destroy
has_many
:award_emoji
,
dependent: :destroy
has_many
:award_emoji
,
dependent: :destroy
has_many
:triggers
,
dependent: :destroy
,
class_name:
'Ci::Trigger'
,
foreign_key: :owner_id
has_many
:assigned_issues
,
dependent: :nullify
,
foreign_key: :assignee_id
,
class_name:
"Issue"
has_many
:assigned_issues
,
dependent: :nullify
,
foreign_key: :assignee_id
,
class_name:
"Issue"
has_many
:assigned_merge_requests
,
dependent: :nullify
,
foreign_key: :assignee_id
,
class_name:
"MergeRequest"
has_many
:assigned_merge_requests
,
dependent: :nullify
,
foreign_key: :assignee_id
,
class_name:
"MergeRequest"
...
...
app/services/ci/create_trigger_request_service.rb
View file @
91ce0467
...
@@ -3,7 +3,7 @@ module Ci
...
@@ -3,7 +3,7 @@ module Ci
def
execute
(
project
,
trigger
,
ref
,
variables
=
nil
)
def
execute
(
project
,
trigger
,
ref
,
variables
=
nil
)
trigger_request
=
trigger
.
trigger_requests
.
create
(
variables:
variables
)
trigger_request
=
trigger
.
trigger_requests
.
create
(
variables:
variables
)
pipeline
=
Ci
::
CreatePipelineService
.
new
(
project
,
nil
,
ref:
ref
).
pipeline
=
Ci
::
CreatePipelineService
.
new
(
project
,
trigger
.
owner
,
ref:
ref
).
execute
(
ignore_skip_ci:
true
,
trigger_request:
trigger_request
)
execute
(
ignore_skip_ci:
true
,
trigger_request:
trigger_request
)
if
pipeline
.
persisted?
if
pipeline
.
persisted?
trigger_request
trigger_request
...
...
db/migrate/20170215164610_add_owner_id_to_triggers.rb
View file @
91ce0467
...
@@ -5,6 +5,6 @@ class AddOwnerIdToTriggers < ActiveRecord::Migration
...
@@ -5,6 +5,6 @@ class AddOwnerIdToTriggers < ActiveRecord::Migration
def
change
def
change
add_column
:ci_triggers
,
:owner_id
,
:integer
add_column
:ci_triggers
,
:owner_id
,
:integer
add_foreign_key
:ci_triggers
,
:users
,
column: :owner_id
,
on_delete: :
nullify
add_foreign_key
:ci_triggers
,
:users
,
column: :owner_id
,
on_delete: :
cascade
end
end
end
end
spec/models/ci/trigger_spec.rb
View file @
91ce0467
require
'spec_helper'
require
'spec_helper'
describe
Ci
::
Trigger
,
models:
true
do
describe
Ci
::
Trigger
,
models:
true
do
let
(
:project
)
{
FactoryGirl
.
create
:empty_project
}
let
(
:project
)
{
create
:empty_project
}
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:owner
)
}
it
{
is_expected
.
to
have_many
(
:trigger_requests
)
}
end
describe
'before_validation'
do
describe
'before_validation'
do
it
'sets an random token if none provided'
do
it
'sets an random token if none provided'
do
trigger
=
FactoryGirl
.
create
:ci_trigger_without_token
,
project:
project
trigger
=
create
(
:ci_trigger_without_token
,
project:
project
)
expect
(
trigger
.
token
).
not_to
be_nil
expect
(
trigger
.
token
).
not_to
be_nil
end
end
it
'does not set an random token if one provided'
do
it
'does not set an random token if one provided'
do
trigger
=
FactoryGirl
.
create
:ci_trigger
,
project:
project
trigger
=
create
(
:ci_trigger
,
project:
project
)
expect
(
trigger
.
token
).
to
eq
(
'token'
)
expect
(
trigger
.
token
).
to
eq
(
'token'
)
end
end
end
end
...
...
spec/models/user_spec.rb
View file @
91ce0467
...
@@ -32,6 +32,7 @@ describe User, models: true do
...
@@ -32,6 +32,7 @@ describe User, models: true do
it
{
is_expected
.
to
have_many
(
:spam_logs
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:spam_logs
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:todos
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:todos
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:award_emoji
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:award_emoji
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:triggers
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:builds
).
dependent
(
:nullify
)
}
it
{
is_expected
.
to
have_many
(
:builds
).
dependent
(
:nullify
)
}
it
{
is_expected
.
to
have_many
(
:pipelines
).
dependent
(
:nullify
)
}
it
{
is_expected
.
to
have_many
(
:pipelines
).
dependent
(
:nullify
)
}
it
{
is_expected
.
to
have_many
(
:chat_names
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:chat_names
).
dependent
(
:destroy
)
}
...
...
spec/services/ci/create_trigger_request_service_spec.rb
View file @
91ce0467
...
@@ -13,8 +13,22 @@ describe Ci::CreateTriggerRequestService, services: true do
...
@@ -13,8 +13,22 @@ describe Ci::CreateTriggerRequestService, services: true do
context
'valid params'
do
context
'valid params'
do
subject
{
service
.
execute
(
project
,
trigger
,
'master'
)
}
subject
{
service
.
execute
(
project
,
trigger
,
'master'
)
}
it
{
expect
(
subject
).
to
be_kind_of
(
Ci
::
TriggerRequest
)
}
context
'without owner'
do
it
{
expect
(
subject
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
it
{
expect
(
subject
).
to
be_kind_of
(
Ci
::
TriggerRequest
)
}
it
{
expect
(
subject
.
pipeline
).
to
be_kind_of
(
Ci
::
Pipeline
)
}
it
{
expect
(
subject
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
end
context
'with owner'
do
let
(
:owner
)
{
create
(
:user
)
}
let
(
:trigger
)
{
create
(
:ci_trigger
,
project:
project
,
owner:
owner
)
}
it
{
expect
(
subject
).
to
be_kind_of
(
Ci
::
TriggerRequest
)
}
it
{
expect
(
subject
.
pipeline
).
to
be_kind_of
(
Ci
::
Pipeline
)
}
it
{
expect
(
subject
.
pipeline
.
user
).
to
eq
(
owner
)
}
it
{
expect
(
subject
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
it
{
expect
(
subject
.
builds
.
first
.
user
).
to
eq
(
owner
)
}
end
end
end
context
'no commit for ref'
do
context
'no commit for ref'
do
...
...
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