diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-12 10:51:31 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-12 10:51:31 +0300 |
commit | 319704451233f4abfbb0e4bcc9bb3e0a756f5eb1 (patch) | |
tree | 84bf4724b4079e05f6230ca4dcc88f9f41ed8532 /app | |
parent | 31bcd04711d448c016506897b8431273e3454faa (diff) |
Refactor push data builder. Moved it to separate class
Also execute GitLab CI on creating tag via UI
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 | 10 | ||||
-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, 17 insertions, 78 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index ef4d2609147..9c203debc3f 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(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..6c3d15e9f4d 100644 --- a/app/services/create_tag_service.rb +++ b/app/services/create_tag_service.rb @@ -21,6 +21,11 @@ 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) else @@ -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, 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..3c03aeaaf66 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(hook.project, current_user) hook.execute(data) end end |