summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/project.rb15
-rw-r--r--app/models/project_services/gitlab_ci_service.rb47
2 files changed, 14 insertions, 48 deletions
diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb
index ae901d4ccd0..37fbcc287bb 100644
--- a/app/models/ci/project.rb
+++ b/app/models/ci/project.rb
@@ -92,21 +92,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
diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb
index 1bba6326949..820dd3f567c 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?
+ prop_accessor :token
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,7 +45,8 @@ class GitlabCiService < CiService
end
end
- service_hook.execute(data)
+ ci_project = Ci::Project.find_by(gitlab_id: project.id)
+ Ci::CreateCommitService.new.execute(ci_project, data)
end
def get_ci_commit(sha, ref)
@@ -68,24 +59,22 @@ class GitlabCiService < CiService
: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
@@ -112,11 +101,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
@@ -125,10 +110,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