diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-04-06 15:20:58 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-04-06 15:20:58 +0300 |
commit | 9c2301808b2d96d41d8972d114c9f77dd2b2471f (patch) | |
tree | d47e8894686ae060aed528bef1c0861df2d7478b /app | |
parent | 0d0042d27481d31027a10edb2ba3a184bff5075a (diff) | |
download | gitlab-ce-9c2301808b2d96d41d8972d114c9f77dd2b2471f.tar.gz |
CI project forking
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project_services/gitlab_ci_service.rb | 24 | ||||
-rw-r--r-- | app/services/projects/fork_service.rb | 6 | ||||
-rw-r--r-- | app/workers/fork_registrator_worker.rb | 12 |
3 files changed, 42 insertions, 0 deletions
diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb index edaeeffc228..d66a1331951 100644 --- a/app/models/project_services/gitlab_ci_service.rb +++ b/app/models/project_services/gitlab_ci_service.rb @@ -59,6 +59,26 @@ class GitlabCiService < CiService end end + def register_fork(new_project, user_token) + params = { + id: new_project.id, + name_with_namespace: new_project.name_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( + register_fork_path, + body: { + project_id: project.id, + project_token: token, + user_token: user_token, + data: params.to_yaml}, + verify: false + ) + end + def commit_coverage(sha, ref) response = get_ci_build(sha, ref) @@ -75,6 +95,10 @@ class GitlabCiService < CiService project_url + "?ref=" + project.default_branch end + def register_fork_path + project_url.sub(/projects\/\d*/, 'api/v1/forks') + end + def status_img_path project_url + "/status.png?ref=" + project.default_branch end diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index 6b0d4aca3e1..b5150fefc4c 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -40,12 +40,18 @@ module Projects if project.save project.team << [@current_user, :master] end + #Now fork the repo unless gitlab_shell.fork_repository(@from_project.path_with_namespace, project.namespace.path) raise 'forking failed in gitlab-shell' end + project.ensure_satellite_exists end + + if @from_project.gitlab_ci? + ForkRegistratorWorker.perform_async(@from_project.id, project.id, @current_user.private_token) + end rescue => ex project.errors.add(:base, 'Fork transaction failed.') project.destroy diff --git a/app/workers/fork_registrator_worker.rb b/app/workers/fork_registrator_worker.rb new file mode 100644 index 00000000000..49d040d65ee --- /dev/null +++ b/app/workers/fork_registrator_worker.rb @@ -0,0 +1,12 @@ +class ForkRegistratorWorker + include Sidekiq::Worker + + sidekiq_options queue: :default + + def perform(from_project_id, to_project_id, private_token) + from_project = Project.find(from_project_id) + to_project = Project.find(to_project_id) + + from_project.gitlab_ci_service.register_fork(to_project, private_token) + end +end |