diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2014-12-06 00:56:43 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-03-21 13:25:27 +0300 |
commit | 5b432e76710eb70cc41c59af1ea9a294202a49fc (patch) | |
tree | c9fa0c82f6b9a3066ef5271027489bb3a80b9d0a /app | |
parent | 6cf189f0a92772b9174f913e7c74a4889d54e9a6 (diff) |
Extend push_tag event to include tag message and last commit
Diffstat (limited to 'app')
-rw-r--r-- | app/services/create_tag_service.rb | 3 | ||||
-rw-r--r-- | app/services/git_push_service.rb | 60 | ||||
-rw-r--r-- | app/services/git_tag_push_service.rb | 18 |
3 files changed, 47 insertions, 34 deletions
diff --git a/app/services/create_tag_service.rb b/app/services/create_tag_service.rb index af4b537cb93..4115d689925 100644 --- a/app/services/create_tag_service.rb +++ b/app/services/create_tag_service.rb @@ -40,7 +40,8 @@ class CreateTagService < BaseService end def create_push_data(project, user, tag) + commits = [project.repository.commit(tag.target)].compact Gitlab::PushDataBuilder. - build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", []) + build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", commits, tag.message) end end diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index a0da07f5c90..1f0b29dff5e 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -23,42 +23,40 @@ class GitPushService project.repository.expire_cache project.update_repository_size - if push_to_branch?(ref) - if push_remove_branch?(ref, newrev) - @push_commits = [] - elsif push_to_new_branch?(ref, oldrev) - # Re-find the pushed commits. - if is_default_branch?(ref) - # Initial push to the default branch. Take the full history of that branch as "newly pushed". - @push_commits = project.repository.commits(newrev) - - # Set protection on the default branch if configured - if (current_application_settings.default_branch_protection != PROTECTION_NONE) - developers_can_push = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_PUSH ? true : false - project.protected_branches.create({ name: project.default_branch, developers_can_push: developers_can_push }) - end - else - # Use the pushed commits that aren't reachable by the default branch - # as a heuristic. This may include more commits than are actually pushed, but - # that shouldn't matter because we check for existing cross-references later. - @push_commits = project.repository.commits_between(project.default_branch, newrev) - - # don't process commits for the initial push to the default branch - process_commit_messages(ref) + if push_remove_branch?(ref, newrev) + @push_commits = [] + elsif push_to_new_branch?(ref, oldrev) + # Re-find the pushed commits. + if is_default_branch?(ref) + # Initial push to the default branch. Take the full history of that branch as "newly pushed". + @push_commits = project.repository.commits(newrev) + + # Set protection on the default branch if configured + if (current_application_settings.default_branch_protection != PROTECTION_NONE) + developers_can_push = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_PUSH ? true : false + project.protected_branches.create({ name: project.default_branch, developers_can_push: developers_can_push }) end - elsif push_to_existing_branch?(ref, oldrev) - # Collect data for this git push - @push_commits = project.repository.commits_between(oldrev, newrev) - project.update_merge_requests(oldrev, newrev, ref, @user) + else + # Use the pushed commits that aren't reachable by the default branch + # as a heuristic. This may include more commits than are actually pushed, but + # that shouldn't matter because we check for existing cross-references later. + @push_commits = project.repository.commits_between(project.default_branch, newrev) + + # don't process commits for the initial push to the default branch process_commit_messages(ref) end + elsif push_to_existing_branch?(ref, oldrev) + # Collect data for this git push + @push_commits = project.repository.commits_between(oldrev, newrev) + project.update_merge_requests(oldrev, newrev, ref, @user) + process_commit_messages(ref) + end - @push_data = build_push_data(oldrev, newrev, ref) + @push_data = build_push_data(oldrev, newrev, ref) - EventCreateService.new.push(project, user, @push_data) - project.execute_hooks(@push_data.dup, :push_hooks) - project.execute_services(@push_data.dup, :push_hooks) - end + EventCreateService.new.push(project, user, @push_data) + project.execute_hooks(@push_data.dup, :push_hooks) + project.execute_services(@push_data.dup, :push_hooks) end protected diff --git a/app/services/git_tag_push_service.rb b/app/services/git_tag_push_service.rb index 0d8e6e85e47..bf203bbd692 100644 --- a/app/services/git_tag_push_service.rb +++ b/app/services/git_tag_push_service.rb @@ -3,7 +3,7 @@ class GitTagPushService def execute(project, user, oldrev, newrev, ref) @project, @user = project, user - + @push_data = build_push_data(oldrev, newrev, ref) EventCreateService.new.push(project, user, @push_data) @@ -18,6 +18,20 @@ class GitTagPushService private def build_push_data(oldrev, newrev, ref) - Gitlab::PushDataBuilder.build(project, user, oldrev, newrev, ref, []) + commits = [] + message = nil + + if !Gitlab::Git.blank_ref?(newrev) + tag_name = Gitlab::Git.ref_name(ref) + tag = project.repository.find_tag(tag_name) + if tag && tag.target == newrev + commit = project.repository.commit(tag.target) + commits = [commit].compact + message = tag.message + end + end + + Gitlab::PushDataBuilder. + build(project, user, oldrev, newrev, ref, commits, message) end end |