summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-03-06 12:49:55 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-03-06 12:49:55 +0000
commit348dff0a826c45f00f992e761423a22d2ac32bc3 (patch)
tree49275fc2d66610c88cfb74f7572228bf94de9ffa /app
parent05be66df9b9e0b68606d7fa621ebdf35106f7df1 (diff)
parent20feaa9eff410cba133e5598f643883e603ba5da (diff)
downloadgitlab-ce-348dff0a826c45f00f992e761423a22d2ac32bc3.tar.gz
Merge branch 'introduce-pipeline-triggers' into 'master'
Improve pipeline triggers API See merge request !9713
Diffstat (limited to 'app')
-rw-r--r--app/helpers/triggers_helper.rb4
-rw-r--r--app/models/ci/trigger.rb11
-rw-r--r--app/models/user.rb1
-rw-r--r--app/services/ci/create_trigger_request_service.rb2
4 files changed, 12 insertions, 6 deletions
diff --git a/app/helpers/triggers_helper.rb b/app/helpers/triggers_helper.rb
index b0135ea2e95..a48d4475e97 100644
--- a/app/helpers/triggers_helper.rb
+++ b/app/helpers/triggers_helper.rb
@@ -1,9 +1,9 @@
module TriggersHelper
def builds_trigger_url(project_id, ref: nil)
if ref.nil?
- "#{Settings.gitlab.url}/api/v3/projects/#{project_id}/trigger/builds"
+ "#{Settings.gitlab.url}/api/v4/projects/#{project_id}/trigger/pipeline"
else
- "#{Settings.gitlab.url}/api/v3/projects/#{project_id}/ref/#{ref}/trigger/builds"
+ "#{Settings.gitlab.url}/api/v4/projects/#{project_id}/ref/#{ref}/trigger/pipeline"
end
end
diff --git a/app/models/ci/trigger.rb b/app/models/ci/trigger.rb
index 39a1dd86241..8aa45b2f02e 100644
--- a/app/models/ci/trigger.rb
+++ b/app/models/ci/trigger.rb
@@ -5,10 +5,11 @@ module Ci
acts_as_paranoid
belongs_to :project, foreign_key: :gl_project_id
+ belongs_to :owner, class_name: "User"
+
has_many :trigger_requests, dependent: :destroy
- validates :token, presence: true
- validates :token, uniqueness: true
+ validates :token, presence: true, uniqueness: true
before_validation :set_default_values
@@ -25,7 +26,11 @@ module Ci
end
def short_token
- token[0...10]
+ token[0...4]
+ end
+
+ def can_show_token?(user)
+ owner.blank? || owner == user
end
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index d3bb04060bf..dfba51d3b00 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -95,6 +95,7 @@ class User < ActiveRecord::Base
has_many :todos, dependent: :destroy
has_many :notification_settings, 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_merge_requests, dependent: :nullify, foreign_key: :assignee_id, class_name: "MergeRequest"
diff --git a/app/services/ci/create_trigger_request_service.rb b/app/services/ci/create_trigger_request_service.rb
index 6af3c1ca5b1..dca5aa9f5d7 100644
--- a/app/services/ci/create_trigger_request_service.rb
+++ b/app/services/ci/create_trigger_request_service.rb
@@ -3,7 +3,7 @@ module Ci
def execute(project, trigger, ref, variables = nil)
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)
if pipeline.persisted?
trigger_request