Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-10-01 13:33:51 +0300
committerDouwe Maan <douwe@gitlab.com>2015-10-01 13:33:51 +0300
commit7c7b664c01a87817ce3f35fb6bdab2498cff4f5d (patch)
tree19f001c79fb1ac98625b477152372b8b1ec49783 /app/models
parent333463ddf280180d1878186160eb5a5e9c5c6e3e (diff)
parent1ca119930fc5f6125ca4d5db4e1a658d5df9dfcd (diff)
Merge branch 'master' into flevour/gitlab-ce-project-path-insensitive-lookup
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb6
-rw-r--r--app/models/ci/commit.rb31
-rw-r--r--app/models/ci/project.rb55
-rw-r--r--app/models/ci/runner.rb4
-rw-r--r--app/models/merge_request.rb14
-rw-r--r--app/models/merge_request_diff.rb4
-rw-r--r--app/models/notification.rb21
-rw-r--r--app/models/project.rb31
-rw-r--r--app/models/project_services/buildkite_service.rb8
-rw-r--r--app/models/project_services/ci/hip_chat_message.rb8
-rw-r--r--app/models/project_services/ci/slack_message.rb10
-rw-r--r--app/models/project_services/drone_ci_service.rb16
-rw-r--r--app/models/project_services/gitlab_ci_service.rb92
-rw-r--r--app/models/sent_notification.rb20
-rw-r--r--app/models/user.rb2
15 files changed, 173 insertions, 149 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 8096d4fa5ae..cda4fdd4982 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -30,7 +30,6 @@ module Ci
LAZY_ATTRIBUTES = ['trace']
belongs_to :commit, class_name: 'Ci::Commit'
- belongs_to :project, class_name: 'Ci::Project'
belongs_to :runner, class_name: 'Ci::Runner'
belongs_to :trigger_request, class_name: 'Ci::TriggerRequest'
@@ -80,7 +79,6 @@ module Ci
new_build.commands = build.commands
new_build.tag_list = build.tag_list
new_build.commit_id = build.commit_id
- new_build.project_id = build.project_id
new_build.name = build.name
new_build.allow_failure = build.allow_failure
new_build.stage = build.stage
@@ -137,7 +135,7 @@ module Ci
state :canceled, value: 'canceled'
end
- delegate :sha, :short_sha, :before_sha, :ref,
+ delegate :sha, :short_sha, :before_sha, :ref, :project,
to: :commit, prefix: false
def trace_html
@@ -188,7 +186,7 @@ module Ci
end
def project_id
- commit.project_id
+ commit.project.id
end
def project_name
diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb
index 23cd47dfe37..6d048779cde 100644
--- a/app/models/ci/commit.rb
+++ b/app/models/ci/commit.rb
@@ -18,8 +18,8 @@
module Ci
class Commit < ActiveRecord::Base
extend Ci::Model
-
- belongs_to :project, class_name: 'Ci::Project'
+
+ belongs_to :gl_project, class_name: '::Project', foreign_key: :gl_project_id
has_many :builds, dependent: :destroy, class_name: 'Ci::Build'
has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'
@@ -36,6 +36,14 @@ module Ci
sha
end
+ def project
+ @project ||= gl_project.ensure_gitlab_ci_project
+ end
+
+ def project_id
+ project.id
+ end
+
def last_build
builds.order(:id).last
end
@@ -111,15 +119,14 @@ module Ci
builds_attrs = config_processor.builds_for_stage_and_ref(stage, ref, tag)
builds_attrs.map do |build_attrs|
builds.create!({
- project: project,
- name: build_attrs[:name],
- commands: build_attrs[:script],
- tag_list: build_attrs[:tags],
- options: build_attrs[:options],
- allow_failure: build_attrs[:allow_failure],
- stage: build_attrs[:stage],
- trigger_request: trigger_request,
- })
+ name: build_attrs[:name],
+ commands: build_attrs[:script],
+ tag_list: build_attrs[:tags],
+ options: build_attrs[:options],
+ allow_failure: build_attrs[:allow_failure],
+ stage: build_attrs[:stage],
+ trigger_request: trigger_request,
+ })
end
end
@@ -236,7 +243,7 @@ module Ci
end
def config_processor
- @config_processor ||= Ci::GitlabCiYamlProcessor.new(push_data[:ci_yaml_file] || project.generated_yaml_config)
+ @config_processor ||= Ci::GitlabCiYamlProcessor.new(push_data[:ci_yaml_file])
rescue Ci::GitlabCiYamlProcessor::ValidationError => e
save_yaml_error(e.message)
nil
diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb
index ae901d4ccd0..77cce261fc8 100644
--- a/app/models/ci/project.rb
+++ b/app/models/ci/project.rb
@@ -33,8 +33,6 @@ module Ci
belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id
- has_many :commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit'
- has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build'
has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject'
has_many :runners, through: :runner_projects, class_name: 'Ci::Runner'
has_many :web_hooks, dependent: :destroy, class_name: 'Ci::WebHook'
@@ -54,13 +52,13 @@ module Ci
# Validations
#
validates_presence_of :name, :timeout, :token, :default_ref,
- :path, :ssh_url_to_repo, :gitlab_id
+ :path, :ssh_url_to_repo, :gitlab_id
validates_uniqueness_of :gitlab_id
validates :polling_interval,
- presence: true,
- if: ->(project) { project.always_build.present? }
+ presence: true,
+ if: ->(project) { project.always_build.present? }
scope :public_only, ->() { where(public: true) }
@@ -78,12 +76,12 @@ module Ci
def parse(project)
params = {
- name: project.name_with_namespace,
- gitlab_id: project.id,
- path: project.path_with_namespace,
- default_ref: project.default_branch || 'master',
- ssh_url_to_repo: project.ssh_url_to_repo,
- email_add_pusher: current_application_settings.add_pusher,
+ name: project.name_with_namespace,
+ gitlab_id: project.id,
+ path: project.path_with_namespace,
+ default_ref: project.default_branch || 'master',
+ ssh_url_to_repo: project.ssh_url_to_repo,
+ email_add_pusher: current_application_settings.add_pusher,
email_only_broken_builds: current_application_settings.all_broken_builds,
}
@@ -92,21 +90,6 @@ module Ci
project
end
- # TODO: remove
- def from_gitlab(user, scope = :owned, options)
- opts = user.authenticate_options
- opts.merge! options
-
- raise 'Implement me of fix'
- #projects = Ci::Network.new.projects(opts.compact, scope)
-
- if projects
- projects.map { |pr| OpenStruct.new(pr) }
- else
- []
- end
- end
-
def already_added?(project)
where(gitlab_id: project.id).any?
end
@@ -114,12 +97,12 @@ module Ci
def unassigned(runner)
joins("LEFT JOIN #{Ci::RunnerProject.table_name} ON #{Ci::RunnerProject.table_name}.project_id = #{Ci::Project.table_name}.id " \
"AND #{Ci::RunnerProject.table_name}.runner_id = #{runner.id}").
- where('#{Ci::RunnerProject.table_name}.project_id' => nil)
+ where("#{Ci::RunnerProject.table_name}.project_id" => nil)
end
def ordered_by_last_commit_date
- last_commit_subquery = "(SELECT project_id, MAX(committed_at) committed_at FROM #{Ci::Commit.table_name} GROUP BY project_id)"
- joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.id = last_commit.project_id").
+ last_commit_subquery = "(SELECT gl_project_id, MAX(committed_at) committed_at FROM #{Ci::Commit.table_name} GROUP BY gl_project_id)"
+ joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON #{Ci::Project.table_name}.gitlab_id = last_commit.gl_project_id").
order("CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END, last_commit.committed_at DESC")
end
@@ -139,10 +122,14 @@ module Ci
def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank?
+ self.default_ref ||= 'master'
+ self.name ||= gl_project.name_with_namespace
+ self.path ||= gl_project.path_with_namespace
+ self.ssh_url_to_repo ||= gl_project.ssh_url_to_repo
end
def tracked_refs
- @tracked_refs ||= default_ref.split(",").map{|ref| ref.strip}
+ @tracked_refs ||= default_ref.split(",").map { |ref| ref.strip }
end
def valid_token? token
@@ -221,5 +208,13 @@ module Ci
def setup_finished?
commits.any?
end
+
+ def commits
+ gl_project.ci_commits
+ end
+
+ def builds
+ gl_project.ci_builds
+ end
end
end
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index 1e9f78a3748..6838ccfaaab 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -41,6 +41,10 @@ module Ci
query: "%#{query.try(:downcase)}%")
end
+ def gl_projects_ids
+ projects.select(:gitlab_id)
+ end
+
def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank?
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 93faa133875..eb468c6cd53 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -433,10 +433,22 @@ class MergeRequest < ActiveRecord::Base
target_project.repository.fetch_ref(
source_project.repository.path_to_repo,
"refs/heads/#{source_branch}",
- "refs/merge-requests/#{iid}/head"
+ ref_path
)
end
+ def ref_path
+ "refs/merge-requests/#{iid}/head"
+ end
+
+ def ref_is_fetched?
+ File.exists?(File.join(project.repository.path_to_repo, ref_path))
+ end
+
+ def ensure_ref_fetched
+ fetch_ref unless ref_is_fetched?
+ end
+
def in_locked_state
begin
lock_mr
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb
index e317c8eac4d..f75f999b0d0 100644
--- a/app/models/merge_request_diff.rb
+++ b/app/models/merge_request_diff.rb
@@ -123,12 +123,12 @@ class MergeRequestDiff < ActiveRecord::Base
if new_diffs.any?
if new_diffs.size > Commit::DIFF_HARD_LIMIT_FILES
self.state = :overflow_diff_files_limit
- new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES]
+ new_diffs = new_diffs.first(Commit::DIFF_HARD_LIMIT_LINES)
end
if new_diffs.sum { |diff| diff.diff.lines.count } > Commit::DIFF_HARD_LIMIT_LINES
self.state = :overflow_diff_lines_limit
- new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES]
+ new_diffs = new_diffs.first(Commit::DIFF_HARD_LIMIT_LINES)
end
end
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 1395274173d..171b8df45c2 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -12,7 +12,7 @@ class Notification
class << self
def notification_levels
- [N_DISABLED, N_PARTICIPATING, N_WATCH, N_MENTION]
+ [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH]
end
def options_with_labels
@@ -26,7 +26,7 @@ class Notification
end
def project_notification_levels
- [N_DISABLED, N_PARTICIPATING, N_WATCH, N_GLOBAL, N_MENTION]
+ [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH, N_GLOBAL]
end
end
@@ -57,4 +57,21 @@ class Notification
def level
target.notification_level
end
+
+ def to_s
+ case level
+ when N_DISABLED
+ 'Disabled'
+ when N_PARTICIPATING
+ 'Participating'
+ when N_WATCH
+ 'Watching'
+ when N_MENTION
+ 'On mention'
+ when N_GLOBAL
+ 'Global'
+ else
+ # do nothing
+ end
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 3b233f2b890..4bcc16d8e9c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -39,6 +39,7 @@ class Project < ActiveRecord::Base
include Gitlab::VisibilityLevel
include Referable
include Sortable
+ include AfterCommitQueue
extend Gitlab::ConfigHelper
extend Enumerize
@@ -117,6 +118,8 @@ class Project < ActiveRecord::Base
has_many :deploy_keys, through: :deploy_keys_projects
has_many :users_star_projects, dependent: :destroy
has_many :starrers, through: :users_star_projects, source: :user
+ has_many :ci_commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit', foreign_key: :gl_project_id
+ has_many :ci_builds, through: :ci_commits, source: :builds, dependent: :destroy, class_name: 'Ci::Build'
has_one :import_data, dependent: :destroy, class_name: "ProjectImportData"
has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id
@@ -191,7 +194,7 @@ class Project < ActiveRecord::Base
state :finished
state :failed
- after_transition any => :started, do: :add_import_job
+ after_transition any => :started, do: :schedule_add_import_job
after_transition any => :finished, do: :clear_import_data
end
@@ -275,13 +278,17 @@ class Project < ActiveRecord::Base
id && persisted?
end
+ def schedule_add_import_job
+ run_after_commit(:add_import_job)
+ end
+
def add_import_job
if forked?
unless RepositoryForkWorker.perform_async(id, forked_from_project.path_with_namespace, self.namespace.path)
import_fail
end
else
- RepositoryImportWorker.perform_in(2.seconds, id)
+ RepositoryImportWorker.perform_async(id)
end
end
@@ -428,7 +435,7 @@ class Project < ActiveRecord::Base
end
def gitlab_ci?
- gitlab_ci_service && gitlab_ci_service.active
+ gitlab_ci_service && gitlab_ci_service.active && gitlab_ci_project.present?
end
def ci_services
@@ -735,4 +742,22 @@ class Project < ActiveRecord::Base
errors.add(:base, 'Failed create wiki')
false
end
+
+ def ci_commit(sha)
+ gitlab_ci_project.commits.find_by(sha: sha) if gitlab_ci?
+ end
+
+ def ensure_gitlab_ci_project
+ gitlab_ci_project || create_gitlab_ci_project
+ end
+
+ def enable_ci(user)
+ # Enable service
+ service = gitlab_ci_service || create_gitlab_ci_service
+ service.active = true
+ service.save
+
+ # Create Ci::Project
+ Ci::CreateProjectService.new.execute(user, self)
+ end
end
diff --git a/app/models/project_services/buildkite_service.rb b/app/models/project_services/buildkite_service.rb
index 9e5da6f45d2..40058b53df5 100644
--- a/app/models/project_services/buildkite_service.rb
+++ b/app/models/project_services/buildkite_service.rb
@@ -69,14 +69,6 @@ class BuildkiteService < CiService
"#{project_url}/builds?commit=#{sha}"
end
- def builds_path
- "#{project_url}/builds?branch=#{project.default_branch}"
- end
-
- def status_img_path
- "#{buildkite_endpoint('badge')}/#{status_token}.svg"
- end
-
def title
'Buildkite'
end
diff --git a/app/models/project_services/ci/hip_chat_message.rb b/app/models/project_services/ci/hip_chat_message.rb
index 58825fe066c..25c72033eac 100644
--- a/app/models/project_services/ci/hip_chat_message.rb
+++ b/app/models/project_services/ci/hip_chat_message.rb
@@ -1,5 +1,7 @@
module Ci
class HipChatMessage
+ include Gitlab::Application.routes.url_helpers
+
attr_reader :build
def initialize(build)
@@ -8,13 +10,13 @@ module Ci
def to_s
lines = Array.new
- lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_url(project)}\">#{project.name}</a> - ")
+ lines.push("<a href=\"#{ci_project_url(project)}\">#{project.name}</a> - ")
if commit.matrix?
- lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_ref_commits_url(project, commit.ref, commit.sha)}\">Commit ##{commit.id}</a></br>")
+ lines.push("<a href=\"#{ci_project_ref_commits_url(project, commit.ref, commit.sha)}\">Commit ##{commit.id}</a></br>")
else
first_build = commit.builds_without_retry.first
- lines.push("<a href=\"#{Ci::RoutesHelper.ci_project_build_url(project, first_build)}\">Build '#{first_build.name}' ##{first_build.id}</a></br>")
+ lines.push("<a href=\"#{ci_project_build_url(project, first_build)}\">Build '#{first_build.name}' ##{first_build.id}</a></br>")
end
lines.push("#{commit.short_sha} #{commit.git_author_name} - #{commit.git_commit_message}</br>")
diff --git a/app/models/project_services/ci/slack_message.rb b/app/models/project_services/ci/slack_message.rb
index 491ace50111..757b1961143 100644
--- a/app/models/project_services/ci/slack_message.rb
+++ b/app/models/project_services/ci/slack_message.rb
@@ -2,6 +2,8 @@ require 'slack-notifier'
module Ci
class SlackMessage
+ include Gitlab::Application.routes.url_helpers
+
def initialize(commit)
@commit = commit
end
@@ -27,7 +29,7 @@ module Ci
next unless build.failed?
fields << {
title: build.name,
- value: "Build <#{Ci::RoutesHelper.ci_project_build_url(project, build)}|\##{build.id}> failed in #{build.duration.to_i} second(s)."
+ value: "Build <#{ci_project_build_url(project, build)}|\##{build.id}> failed in #{build.duration.to_i} second(s)."
}
end
end
@@ -44,12 +46,12 @@ module Ci
attr_reader :commit
def attachment_message
- out = "<#{Ci::RoutesHelper.ci_project_url(project)}|#{project_name}>: "
+ out = "<#{ci_project_url(project)}|#{project_name}>: "
if commit.matrix?
- out << "Commit <#{Ci::RoutesHelper.ci_project_ref_commits_url(project, commit.ref, commit.sha)}|\##{commit.id}> "
+ out << "Commit <#{ci_project_ref_commits_url(project, commit.ref, commit.sha)}|\##{commit.id}> "
else
build = commit.builds_without_retry.first
- out << "Build <#{Ci::RoutesHelper.ci_project_build_path(project, build)}|\##{build.id}> "
+ out << "Build <#{ci_project_build_url(project, build)}|\##{build.id}> "
end
out << "(<#{commit_sha_link}|#{commit.short_sha}>) "
out << "of <#{commit_ref_link}|#{commit.ref}> "
diff --git a/app/models/project_services/drone_ci_service.rb b/app/models/project_services/drone_ci_service.rb
index 3e2b7faecdb..c73c4b058a1 100644
--- a/app/models/project_services/drone_ci_service.rb
+++ b/app/models/project_services/drone_ci_service.rb
@@ -26,7 +26,7 @@ class DroneCiService < CiService
format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" }, if: :activated?
validates :token,
presence: true,
- format: { with: /\A([A-Za-z0-9]+)\z/ }, if: :activated?
+ if: :activated?
after_save :compose_service_hook, if: :activated?
@@ -135,20 +135,6 @@ class DroneCiService < CiService
commit_page(sha, ref)
end
- def builds_path
- url = [drone_url, "#{project.namespace.path}/#{project.path}"]
-
- URI.join(*url).to_s
- end
-
- def status_img_path
- url = [drone_url,
- "api/badges/#{project.namespace.path}/#{project.path}/status.svg",
- "?branch=#{URI::encode(project.default_branch)}"]
-
- URI.join(*url).to_s
- end
-
def title
'Drone CI'
end
diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb
index acbbc9935b6..23ab206efba 100644
--- a/app/models/project_services/gitlab_ci_service.rb
+++ b/app/models/project_services/gitlab_ci_service.rb
@@ -19,22 +19,12 @@
#
class GitlabCiService < CiService
- API_PREFIX = "api/v1"
-
- prop_accessor :project_url, :token, :enable_ssl_verification
- validates :project_url,
- presence: true,
- format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" }, if: :activated?
- validates :token,
- presence: true,
- format: { with: /\A([A-Za-z0-9]+)\z/ }, if: :activated?
+ include Gitlab::Application.routes.url_helpers
after_save :compose_service_hook, if: :activated?
def compose_service_hook
hook = service_hook || build_service_hook
- hook.url = [project_url, "/build", "?token=#{token}"].join("")
- hook.enable_ssl_verification = enable_ssl_verification
hook.save
end
@@ -55,71 +45,57 @@ class GitlabCiService < CiService
end
end
- service_hook.execute(data)
+ ci_project = Ci::Project.find_by(gitlab_id: project.id)
+ if ci_project
+ Ci::CreateCommitService.new.execute(ci_project, data)
+ end
end
- def commit_status_path(sha, ref)
- URI::encode(project_url + "/refs/#{ref}/commits/#{sha}/status.json?token=#{token}")
+ def token
+ if project.gitlab_ci_project.present?
+ project.gitlab_ci_project.token
+ end
end
- def get_ci_build(sha, ref)
- @ci_builds ||= {}
- @ci_builds[sha] ||= HTTParty.get(commit_status_path(sha, ref), verify: false)
+ def get_ci_commit(sha, ref)
+ Ci::Project.find(project.gitlab_ci_project).commits.find_by_sha_and_ref!(sha, ref)
end
def commit_status(sha, ref)
- response = get_ci_build(sha, ref)
-
- if response.code == 200 and response["status"]
- response["status"]
- else
- :error
- end
- rescue Errno::ECONNREFUSED
+ get_ci_commit(sha, ref).status
+ rescue ActiveRecord::RecordNotFound
:error
end
- def fork_registration(new_project, private_token)
- params = {
+ def fork_registration(new_project, current_user)
+ params = OpenStruct.new({
id: new_project.id,
name_with_namespace: new_project.name_with_namespace,
path_with_namespace: new_project.path_with_namespace,
web_url: new_project.web_url,
default_branch: new_project.default_branch,
ssh_url_to_repo: new_project.ssh_url_to_repo
- }
-
- HTTParty.post(
- fork_registration_path,
- body: {
- project_id: project.id,
- project_token: token,
- private_token: private_token,
- data: params },
- verify: false
+ })
+
+ ci_project = Ci::Project.find_by!(gitlab_id: project.id)
+
+ Ci::CreateProjectService.new.execute(
+ current_user,
+ params,
+ ci_project
)
end
def commit_coverage(sha, ref)
- response = get_ci_build(sha, ref)
-
- if response.code == 200 and response["coverage"]
- response["coverage"]
- end
- rescue Errno::ECONNREFUSED
- nil
+ get_ci_commit(sha, ref).coverage
+ rescue ActiveRecord::RecordNotFound
+ :error
end
def build_page(sha, ref)
- URI::encode(project_url + "/refs/#{ref}/commits/#{sha}")
- end
-
- def builds_path
- project_url + "?ref=" + project.default_branch
- end
-
- def status_img_path
- project_url + "/status.png?ref=" + project.default_branch
+ if project.gitlab_ci_project.present?
+ ci_project_ref_commits_url(project.gitlab_ci_project, ref, sha)
+ end
end
def title
@@ -135,11 +111,7 @@ class GitlabCiService < CiService
end
def fields
- [
- { type: 'text', name: 'token', placeholder: 'GitLab CI project specific token' },
- { type: 'text', name: 'project_url', placeholder: 'http://ci.gitlabhq.com/projects/3' },
- { type: 'checkbox', name: 'enable_ssl_verification', title: "Enable SSL verification" }
- ]
+ []
end
private
@@ -148,10 +120,6 @@ class GitlabCiService < CiService
repository.blob_at(sha, '.gitlab-ci.yml')
end
- def fork_registration_path
- project_url.sub(/projects\/\d*/, "#{API_PREFIX}/forks")
- end
-
def repository
project.repository
end
diff --git a/app/models/sent_notification.rb b/app/models/sent_notification.rb
index 33b113a2a27..3eed5c16e45 100644
--- a/app/models/sent_notification.rb
+++ b/app/models/sent_notification.rb
@@ -8,6 +8,7 @@
# noteable_type :string(255)
# recipient_id :integer
# commit_id :string(255)
+# line_code :string(255)
# reply_key :string(255) not null
#
@@ -21,13 +22,20 @@ class SentNotification < ActiveRecord::Base
validates :noteable_id, presence: true, unless: :for_commit?
validates :commit_id, presence: true, if: :for_commit?
+ validates :line_code, format: { with: /\A[a-z0-9]+_\d+_\d+\Z/ }, allow_blank: true
class << self
+ def reply_key
+ return nil unless Gitlab::IncomingEmail.enabled?
+
+ SecureRandom.hex(16)
+ end
+
def for(reply_key)
find_by(reply_key: reply_key)
end
- def record(noteable, recipient_id, reply_key)
+ def record(noteable, recipient_id, reply_key, params = {})
return unless reply_key
noteable_id = nil
@@ -38,7 +46,7 @@ class SentNotification < ActiveRecord::Base
noteable_id = noteable.id
end
- create(
+ params.reverse_merge!(
project: noteable.project,
noteable_type: noteable.class.name,
noteable_id: noteable_id,
@@ -46,6 +54,14 @@ class SentNotification < ActiveRecord::Base
recipient_id: recipient_id,
reply_key: reply_key
)
+
+ create(params)
+ end
+
+ def record_note(note, recipient_id, reply_key, params = {})
+ params[:line_code] = note.line_code
+
+ record(note.noteable, recipient_id, reply_key, params)
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 25371f9138a..3879f3fd381 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -172,7 +172,7 @@ class User < ActiveRecord::Base
# User's Dashboard preference
# Note: When adding an option, it MUST go on the end of the array.
- enum dashboard: [:projects, :stars]
+ enum dashboard: [:projects, :stars, :project_activity, :starred_project_activity]
# User's Project preference
# Note: When adding an option, it MUST go on the end of the array.