diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-01-13 00:06:35 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-01-13 00:06:35 +0300 |
commit | 6774a701a6b7a8c2508b5e36bd292a63f3d9d7d6 (patch) | |
tree | a1bf4b61a2490145c8eb23724a2877ac3a267fce /app | |
parent | 1c6a1253899219b84cc9cb8b090a3bfbbd19605e (diff) | |
parent | bba8e59a044f34a02000b752a70198fb74236b1d (diff) |
Merge branch 'refactor_push_data_builder' into 'master'
Refactor push data builder
See merge request !1384
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/services_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/projects/tags_controller.rb | 1 | ||||
-rw-r--r-- | app/services/create_tag_service.rb | 14 | ||||
-rw-r--r-- | app/services/git_push_service.rb | 63 | ||||
-rw-r--r-- | app/services/git_tag_push_service.rb | 16 | ||||
-rw-r--r-- | app/services/test_hook_service.rb | 2 |
6 files changed, 19 insertions, 80 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index ef4d2609147..b2ce99aeb45 100644 --- a/app/controllers/projects/services_controller.rb +++ b/app/controllers/projects/services_controller.rb @@ -24,8 +24,7 @@ class Projects::ServicesController < Projects::ApplicationController end def test - data = GitPushService.new.sample_data(project, current_user) - + data = Gitlab::PushDataBuilder.build_sample(project, current_user) @service.execute(data) redirect_to :back diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb index 162ddef0fec..64b820160d3 100644 --- a/app/controllers/projects/tags_controller.rb +++ b/app/controllers/projects/tags_controller.rb @@ -13,6 +13,7 @@ class Projects::TagsController < Projects::ApplicationController def create result = CreateTagService.new(@project, current_user). execute(params[:tag_name], params[:ref], params[:message]) + if result[:status] == :success @tag = result[:tag] redirect_to project_tags_path(@project) diff --git a/app/services/create_tag_service.rb b/app/services/create_tag_service.rb index 9b2a2270233..041c2287c36 100644 --- a/app/services/create_tag_service.rb +++ b/app/services/create_tag_service.rb @@ -21,10 +21,15 @@ class CreateTagService < BaseService new_tag = repository.find_tag(tag_name) if new_tag + if project.gitlab_ci? + push_data = create_push_data(project, current_user, new_tag) + project.gitlab_ci_service.async_execute(push_data) + end + Event.create_ref_event(project, current_user, new_tag, 'add', 'refs/tags') - return success(new_tag) + success(new_tag) else - return error('Invalid reference name') + error('Invalid reference name') end end @@ -33,4 +38,9 @@ class CreateTagService < BaseService out[:tag] = branch out end + + def create_push_data(project, user, tag) + Gitlab::PushDataBuilder. + build(project, user, Gitlab::Git::BLANK_SHA, tag.target, 'refs/tags/' + tag.name, []) + end end diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 529af1970f6..a9ea7daabc8 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -52,16 +52,6 @@ class GitPushService end end - # This method provide a sample data - # generated with post_receive_data method - # for given project - # - def sample_data(project, user) - @project, @user = project, user - @push_commits = project.repository.commits(project.default_branch, nil, 3) - post_receive_data(@push_commits.last.id, @push_commits.first.id, "refs/heads/#{project.default_branch}") - end - protected def create_push_event(push_data) @@ -112,58 +102,9 @@ class GitPushService end end - # Produce a hash of post-receive data - # - # data = { - # before: String, - # after: String, - # ref: String, - # user_id: String, - # user_name: String, - # project_id: String, - # repository: { - # name: String, - # url: String, - # description: String, - # homepage: String, - # }, - # commits: Array, - # total_commits_count: Fixnum - # } - # def post_receive_data(oldrev, newrev, ref) - # Total commits count - push_commits_count = push_commits.size - - # Get latest 20 commits ASC - push_commits_limited = push_commits.last(20) - - # Hash to be passed as post_receive_data - data = { - before: oldrev, - after: newrev, - ref: ref, - user_id: user.id, - user_name: user.name, - project_id: project.id, - repository: { - name: project.name, - url: project.url_to_repo, - description: project.description, - homepage: project.web_url, - }, - commits: [], - total_commits_count: push_commits_count - } - - # For performance purposes maximum 20 latest commits - # will be passed as post receive hook data. - # - push_commits_limited.each do |commit| - data[:commits] << commit.hook_attrs(project) - end - - data + Gitlab::PushDataBuilder. + build(project, user, oldrev, newrev, ref, push_commits) end def push_to_existing_branch?(ref, oldrev) diff --git a/app/services/git_tag_push_service.rb b/app/services/git_tag_push_service.rb index bacd39bf1c4..c24809ad607 100644 --- a/app/services/git_tag_push_service.rb +++ b/app/services/git_tag_push_service.rb @@ -19,20 +19,8 @@ class GitTagPushService private def create_push_data(oldrev, newrev, ref) - data = { - ref: ref, - before: oldrev, - after: newrev, - user_id: user.id, - user_name: user.name, - project_id: project.id, - repository: { - name: project.name, - url: project.url_to_repo, - description: project.description, - homepage: project.web_url - } - } + Gitlab::PushDataBuilder. + build(project, user, oldrev, newrev, ref, []) end def create_push_event diff --git a/app/services/test_hook_service.rb b/app/services/test_hook_service.rb index 17d86a7a274..21ec2c01cb8 100644 --- a/app/services/test_hook_service.rb +++ b/app/services/test_hook_service.rb @@ -1,6 +1,6 @@ class TestHookService def execute(hook, current_user) - data = GitPushService.new.sample_data(hook.project, current_user) + data = Gitlab::PushDataBuilder.build_sample(hook.project, current_user) hook.execute(data) end end |